Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: using initial username as id and preventing later edits #1503

Merged
merged 3 commits into from
Oct 27, 2022

Conversation

TheSlimvReal
Copy link
Collaborator

When creating new user they currently get a UUID (like all other entities). The problem is we need the user's id to match the username of the Keycloak user. This is important in order to assign users to entities and then later match them with actually logged in users.

This approach initially overwrites the entity id when the first time a username is saved but afterwards does not allow to change the username anymore. This way we ensure that user entities can be matched with the usernames.

Visible/Frontend Changes

--

Architectural/Backend Changes

  • When creating a User entity, the name is used as entityId
  • When trying to change the name of a existing user, an error is thrown

@github-actions
Copy link

// Throwing error if trying to change existing username
const label = User.schema.get("name").label;
throw new Error(
$localize`:Error message when trying to change the username|e.g. username cannot be changed after initialization:${label} cannot be changed after initialization`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best practices would suggest to not mix logic (the Entity model here) with UI (translating an error message), I think. The clean but more complex approach would be to define error codes or classes and only put human-readable and translated error messages when displaying it to the user. But I have my doubts that complexity is a worthy trade off here. 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a good thought. At the moment we are missing a general display error approach where we could translate these errors to a user friendly name.

@@ -34,7 +34,23 @@ export class User extends Entity {
label: $localize`:Label of username:Username`,
validators: { required: true },
})
name: string;
set name(value: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's maybe change the property to username (or will this break dozens of things?). For some clients we introduced additional firstname and lastname properties to be used in the UI. "username" would make the purpose of this one more explicit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment it would break a dozens of things (all the current user entities) So lets get this out and if we ever want to migrate this, we can do this independently.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@TheSlimvReal TheSlimvReal merged commit df76bca into master Oct 27, 2022
@TheSlimvReal TheSlimvReal deleted the username_fix branch October 27, 2022 10:04
@aam-digital-ci
Copy link
Collaborator

🎉 This PR is included in version 3.13.2-master.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@aam-digital-ci
Copy link
Collaborator

🎉 This PR is included in version 3.13.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants