Anirudh D - permissions management: Create constants for permission keys to replace passing strings directly into hasPermission() - #2052
Conversation
psharma1984
left a comment
There was a problem hiding this comment.
Hi @Pandani07 I tested the PR with listed steps. I tried login with owner and admin account but when i try to create a user using Create User in User Management it displays a blank page. Please see below video for details
screen-capture.webm
Hello, what user are you logged in as when you try to create a new user? |
SanketKaware
left a comment
There was a problem hiding this comment.
I did not encounter any issues and everything worked as expected.
Additionally, I was able to access the Create New User screen without any problems.
Here is my video review for reference.
Screen.Recording.2024-03-21.at.8.49.12.PM.mov
SushmithaPrathap
left a comment
There was a problem hiding this comment.
Hey!
I reviewed your PR and tested it following the steps provided. It works as expected.
I tested it with owner account and volunteer account.
Owner can create new users and volunteer cannot.
Here is a screen recording:
Screen.Recording.2024-04-04.at.8.26.23.PM.mov
|
I've checked out the PR, and everything's good to go. I've successfully created new users as well. Check out my video review here. PR2052.mp4 |
p-suram
left a comment
There was a problem hiding this comment.
Changes looks good. I have tested with Admin and Volunteer accounts. Good Work
2024-04-06.22-50-51.mp4
p-suram
left a comment
There was a problem hiding this comment.
Hey, following up with my previous review, I just checked, you missed below 2 files:
- src\components\PermissionsManagement\RolePermissions.jsx
const isEditableRole = props.role === 'Owner' ? props.hasPermission('addDeleteEditOwners') : props.auth.user.role !== props.role; const canEditRole = isEditableRole && props.hasPermission('putRole'); const canDeleteRole = isEditableRole && props.hasPermission('deleteRole'); - src\components\UserProfile\BlueSquareLayout.jsx
const canManageTimeOffRequests = dispatch(hasPermission('manageTimeOffRequests'));
There was a problem hiding this comment.
Hey Anirudh,
I have checked your PR and here's what I have test:
- Owner & Admin account can create users
- No other pages are affected my current change
- Volunteer must not be able to create new users
Owner Account Video:
Owner.mp4
Admin Account Video:
Admin.mp4
Volunteer Account Video:
Volunteer.mp4
For some reason my Volunteer has the permission to create new users which I am not able to remove for that account but the rest works pretty well.
Parth-tech
left a comment
There was a problem hiding this comment.
Could you help me understand why locally volunteer role has the permission to create new users? Furthermore, I not able to remove that permission either.
|
Hey pandani, would love to be able to get this merged asap as it looks like you've done a lot of great work here. Would it be possible for you to get the merge conflicts cleared up on this, and I'll wrangle some pull requesters to review it. Thank you! |
j-corp-25
left a comment
There was a problem hiding this comment.
Hi @Pandani07
I followed the instructions and created a user using Amin. No issues popped up. New user shows up when queried.
Video below:
CheckingPermissions.mp4
metaphor987
left a comment
There was a problem hiding this comment.
Hi Anirudh,
The description of the code changes is very clear. I've tested the changes using both admin and volunteer accounts, and the main functionalities work well.
There's only one issue with the "Get Time Zone" feature. After entering the "location" and clicking "Get Time Zone," I received an error message saying "API Key missing." This issue occurred when creating a new user using an admin account and when editing the location in user profiles using either an admin or volunteer account. I'm not completely sure whether this issue is related to the PR, but I think it would be great to check. Thank you!
Screen.Recording.2024-04-13.at.7.31.51.PM.mov
Screen.Recording.2024-04-13.at.8.24.44.PM.mov
aaryaneil
left a comment
There was a problem hiding this comment.
Tested the PR and the changes work as expected. Attached videos for reference.
Admin account:
Screen.Recording.2024-04-13.at.11.41.21.PM.mov
Volunteer account:
Screen.Recording.2024-04-13.at.11.46.13.PM.mov
Owner account:
Screen.Recording.2024-04-13.at.11.47.39.PM.mov
p-suram
left a comment
There was a problem hiding this comment.
Hey, following up with my previous review, I just checked, you missed below 2 files:
- src\components\PermissionsManagement\RolePermissions.jsx
const isEditableRole = props.role === 'Owner' ? props.hasPermission('addDeleteEditOwners') : props.auth.user.role !== props.role; const canEditRole = isEditableRole && props.hasPermission('putRole'); const canDeleteRole = isEditableRole && props.hasPermission('deleteRole'); - src\components\UserProfile\BlueSquareLayout.jsx
const canManageTimeOffRequests = dispatch(hasPermission('manageTimeOffRequests'));
ddacafc
I have resolved the merge conflicts now |
Will check |
Hello, working on it now. I was not working the last weeks. |
cgomezhub
left a comment
There was a problem hiding this comment.
Hi there,
I conducted a test using an admin user. I was successfully able to create a new user, assign them to a team, and add them to a project. However, when creating the new user, I encountered an issue where retrieving their time zone information failed.
Sandhya1236
left a comment
There was a problem hiding this comment.
I checked out the current branch on the frontend and the development branch on the backend. After running npm install and npm run start:local on the frontend and npm install, npm run build, and npm run start on the backend, I cleared the site data/cache. I logged in as various users to ensure there were no bugs and confirmed that each user functioned according to their assigned roles. All steps were followed successfully, verifying that changing hard-coded permission strings to constants did not introduce any issues.
|
Putting a pause on this for the reasons listed here: https://docs.google.com/document/d/1n5NIb3dbiSrIRuOG1ZCwt34pEP1poqddCv1guaQml88/edit#bookmark=id.ujw54u7uztbd |
Dnagabahiru
left a comment
There was a problem hiding this comment.
Priority: Low
I reviewed the changes for replacing hard-coded permission strings passed directly into hasPermission() with centralized permission constants.
The approach looks good and should help reduce the possibility of typos or inconsistencies when the same permission keys are reused across different components. Using constants such as permissions.projects.deleteWbs instead of hasPermission('deleteWbs') also makes the permission references easier to maintain going forward.
Since Permissions Management is now sufficiently developed, I think this is a good point to complete this implementation and verify the permissions end-to-end.
Suggested next steps:
Complete replacing the remaining hard-coded permission strings, including the areas currently excluded from the PR.
Confirm that RoutePermissions can be reused where appropriate, such as in the Header.
Test all Permissions Management functionality after the constants are implemented.
Verify that users continue to receive the correct permissions based on their assigned roles.
Pay particular attention to user creation and other areas where permission-related issues were previously observed.
Once the permission functionality has been fully tested and confirmed, this PR should provide a good foundation for consistently handling permission keys going forward.
Dnagabahiru
left a comment
There was a problem hiding this comment.
Priority: Low
I reviewed the changes for replacing hard-coded permission strings passed directly into hasPermission() with centralized permission constants.
The approach looks good and should help reduce the possibility of typos or inconsistencies when the same permission keys are reused across different components. Using constants such as permissions.projects.deleteWbs instead of hasPermission('deleteWbs') also makes the permission references easier to maintain going forward.
Since Permissions Management is now sufficiently developed, I think this is a good point to complete this implementation and verify the permissions end-to-end.
Suggested next steps:
Complete replacing the remaining hard-coded permission strings, including the areas currently excluded from the PR.
Confirm that RoutePermissions can be reused where appropriate, such as in the Header.
Test all Permissions Management functionality after the constants are implemented.
Verify that users continue to receive the correct permissions based on their assigned roles.
Pay particular attention to user creation and other areas where permission-related issues were previously observed.
Once the permission functionality has been fully tested and confirmed, this PR should provide a good foundation for consistently handling permission keys going forward.
nathanah
left a comment
There was a problem hiding this comment.
Priority High:
Looks like !targetIsDevAdminUneditable lost it's negation.
Priority Low:
This is definitely still an incomplete transition, but can complete that later.
Some cleaning out of redundancies.
| const canManageAdminLinks = props.hasPermission('manageAdminLinks'); | ||
|
|
||
| const canManageAdminLinks = props.hasPermission(permissions.userManagement.manageAdminLinks); | ||
| const canPutUserProfileImportantInfo = props.hasPermission(permissions.userManagement.putUserProfileImportantInfo); |
There was a problem hiding this comment.
| const canPutUserProfileImportantInfo = props.hasPermission(permissions.userManagement.putUserProfileImportantInfo); |
Extra?
There was a problem hiding this comment.
Imported permissions, but didn't replace permission string literals in this file.
| !isTeamSaved | ||
| } | ||
| canEditTeamCode={props.hasPermission('editTeamCode') || requestorRole == 'Owner' || !targetIsDevAdminUneditable} | ||
| canEditTeamCode={props.hasPermission(permissions.teams.editTeamCode) || requestorRole == 'Owner' || targetIsDevAdminUneditable} |
There was a problem hiding this comment.
| canEditTeamCode={props.hasPermission(permissions.teams.editTeamCode) || requestorRole == 'Owner' || targetIsDevAdminUneditable} | |
| canEditTeamCode={props.hasPermission(permissions.teams.editTeamCode) || !targetIsDevAdminUneditable} |
I don't think you meant to remove the negation.
| } | ||
| canEditTeamCode={ | ||
| props.hasPermission('editTeamCode') || requestorRole === 'Owner' ||requestorRole === 'Administrator' | ||
| props.hasPermission(permissions.teams.editTeamCode) || requestorRole === 'Owner' ||requestorRole === 'Administrator' |
There was a problem hiding this comment.
| props.hasPermission(permissions.teams.editTeamCode) || requestorRole === 'Owner' ||requestorRole === 'Administrator' | |
| props.hasPermission(permissions.teams.editTeamCode) |
These manual role checks are redundant, so we can clean them up while we're at it.
| // const canChangeUserStatus = props.hasPermission('changeUserStatus'); | ||
| // const canAddDeleteEditOwners = props.hasPermission('addDeleteEditOwners'); | ||
| // const canPutUserProfile = props.hasPermission('putUserProfile'); | ||
| // const canUpdatePassword = props.hasPermission('updatePassword'); | ||
| // const canGetProjectMembers = props.hasPermission('getProjectMembers'); | ||
| // const canChangeRehireableStatus = props.hasPermission('changeUserRehireableStatus'); | ||
| // const canManageAdminLinks = props.hasPermission('manageAdminLinks');; | ||
| // const canSeeQSC = props.hasPermission('seeQSC'); | ||
|
|
There was a problem hiding this comment.
| // const canChangeUserStatus = props.hasPermission('changeUserStatus'); | |
| // const canAddDeleteEditOwners = props.hasPermission('addDeleteEditOwners'); | |
| // const canPutUserProfile = props.hasPermission('putUserProfile'); | |
| // const canUpdatePassword = props.hasPermission('updatePassword'); | |
| // const canGetProjectMembers = props.hasPermission('getProjectMembers'); | |
| // const canChangeRehireableStatus = props.hasPermission('changeUserRehireableStatus'); | |
| // const canManageAdminLinks = props.hasPermission('manageAdminLinks');; | |
| // const canSeeQSC = props.hasPermission('seeQSC'); |
Cleaning things up.


























Description
Create constants for permission keys to replace passing strings directly into hasPermission()

The permissions were passed into
hasPermission()as a hard-coded string in the frontend. Eg -hasPermission('deleteWbs')To avoid manual error, I have created a separate constants file under

src/utils/constants.jsand I have created an object that has all the permissions being used. So the above example is changed to -hasPermission(permissions.projects.deleteWbs)andconstants.jshas the following entry -deleteWbs: 'deleteWbs'Related PRS (if any):
Use the latest backend
…
Main changes explained:
Changed hard-coded permission strings to constants except in
src/components/PermissionsManagement/RolePermissions.jsxHow to test:
npm installandnpm run start:localto run this PR locally and donpm install,npm run build && npm run starton the development backendScreenshots or videos of changes: