-
Notifications
You must be signed in to change notification settings - Fork 0
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
Create FetchUserRolesAndGroupsService
#392
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://eaflood.atlassian.net/browse/WATER-4085 We create a service to look up a user in the `idm` schema and return the roles assigned to them.
Our first pass at a solution is to make multiple calls to the db. This lets us know we're on the right track and can start refactoring and optimising the service
We overlooked adding the `idm` model folder to the `modelPaths` of our `LegacyBaseModel`. Fixing this means we are able to use the models correctly.
We want to replace our naive approach to retrieving the roles with something a little nicer. In order to do this, we need to add relations to the models so we can easily go from one to another. Note that for now we only add "forward" relations, eg. from user to user role to role. We don't yet add ones going the other way, eg. from role to user role to user. We also have not yet written unit tests for these.
We add a unit test case to ensure that if a role is added directly to the user, and the user also has that role via a group, then the role is only returned once from the service
Now that our models have relations going from one table to another, we can replace our multiple queries with a single query which fetches all roles and groups belonging to a user
We provide the service with the user id so there's no need for it to return it
We initially implemented only the minimum relations required to join the tables "forwards" so we can retrieve groups and roles from a user. We now go back and implement the relations going the other way.
We rename the service to reflect the fact it returns groups as well as roles
If the user id is not found then we ensure that we return empty arrays for `roles` and `groups`
StuAA78
changed the title
Create
Create Sep 4, 2023
GetUserRolesService
GetUserRolesAndGroupsService
We rename the service to `FetchUserRolesAndGroupsService` to better reflect our standard of "fetching" things from the db
We add an additional group and roles to the unit tests which we don't assign to the user, to confirm that they are not returned and therefore we are only returning the relevant groups and roles
Cruikshanks
requested changes
Sep 4, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just copy & paste typo. Other than that all gravy!
Co-authored-by: Alan Cruikshanks <[email protected]>
Cruikshanks
approved these changes
Sep 4, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StuAA78
changed the title
Create
Create Sep 4, 2023
GetUserRolesAndGroupsService
FetchUserRolesAndGroupsService
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://eaflood.atlassian.net/browse/WATER-4085
We create a service
FetchUserRolesAndGroupsService
to look up a user in theidm
schema and return the roles and groups assigned to them.Roles are assigned as follows:
user_roles
tableuser_groups
tablegroup_roles
tableWe want to collate all roles, no matter how they're assigned, and return the resulting list, along with the groups the user belongs to.