-
Notifications
You must be signed in to change notification settings - Fork 43
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
PIMS-2082 Backend Authorization Updates #2679
Conversation
Co-authored-by: dbarkowsky <[email protected]>
Code Climate has analyzed commit 99f3346 and detected 2 issues on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 95.4% (50% is the threshold). This pull request will bring the total coverage in the repository to 93.2%. View more on Code Climate. |
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.
Seems to work, after changing my role to general user, I'm only able to see properties under my agency and below, tested updating my user and I get a 403 error, and tested viewing another building and get a 403 and redirected to the map page.
Tested as an auditor as well, and the api is preventing me from making changes as expected.
🎯 Summary
PIMS-2082
Goal
Changes
activeUserCheck
middleware. Renamed it touserAuthCheck
. It now performs role checking functions as well. It also contains a function calledhasOneOfRoles
that you can use for role checking in other API locations. It then adds the user from the database plus this function to the request. It can be accessed likedreq.pimsUser
.userAuthCheck
is applied in the paths to the routes. It must be proceeded by theprotectedRoute
middleware or it will not have the user.preferred_username field to look up the database user. In cases where all the routes in an area (like agencies) were Admin protected, I added it to theexpress.ts
file, but if there were different permissions for each route in an area, I added it to the route files. Open to preference on this if we wanted it to be a little more repetitive in some cases but keep all these checks in the route files.Use Example
Testing
With your user already in the database:
🔰 Checklist