Skip to content

Anirudh D - permissions management: Create constants for permission keys to replace passing strings directly into hasPermission() - #2052

Closed
Pandani07 wants to merge 11 commits into
developmentfrom
Anirudh_permissionsMangement
Closed

Anirudh D - permissions management: Create constants for permission keys to replace passing strings directly into hasPermission()#2052
Pandani07 wants to merge 11 commits into
developmentfrom
Anirudh_permissionsMangement

Conversation

@Pandani07

@Pandani07 Pandani07 commented Mar 13, 2024

Copy link
Copy Markdown
Contributor

Description

Create constants for permission keys to replace passing strings directly into hasPermission()
Screenshot 2024-03-12 at 5 05 08 PM
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.js and I have created an object that has all the permissions being used. So the above example is changed to - hasPermission(permissions.projects.deleteWbs) and constants.js has the following entry - deleteWbs: 'deleteWbs'
Screenshot 2024-03-12 at 5 10 22 PM

Related PRS (if any):

Use the latest backend

Main changes explained:

Changed hard-coded permission strings to constants except in src/components/PermissionsManagement/RolePermissions.jsx

How to test:

  1. check into the current branch on the front end and the development branch on the backend
  2. do npm install and npm run start:local to run this PR locally and do npm install, npm run build && npm run start on the development backend
  3. Clear site data/cache
  4. log in as any user and check if you encounter any bugs. Every user should function as the role it's assigned

Screenshots or videos of changes:

Screenshot 2024-03-12 at 5 15 10 PM
Screenshot 2024-03-12 at 5 15 02 PM

Abi-Liu
Abi-Liu previously approved these changes Mar 13, 2024

@Abi-Liu Abi-Liu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Everything looks good!

@psharma1984 psharma1984 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@Pandani07

Copy link
Copy Markdown
Contributor Author

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
SanketKaware previously approved these changes Mar 22, 2024

@SanketKaware SanketKaware left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@MQChen211

Copy link
Copy Markdown

Hi I tested your PR with a volunteer account and an owner account. It works well.

Volunteer account:
截屏2024-04-03 19 39 08
截屏2024-04-03 19 38 34
截屏2024-04-03 19 38 25

Owner Account:

截屏2024-04-03 19 40 32 截屏2024-04-03 19 40 14

@Gayathr-2012

Copy link
Copy Markdown
Contributor

Hi
I do not have any problem. I could create a new user. I tested your PR it works as well.

image

image

image

image

@SushmithaPrathap SushmithaPrathap left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@hiralsonip

Copy link
Copy Markdown
Contributor

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 p-suram left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Changes looks good. I have tested with Admin and Volunteer accounts. Good Work

2024-04-06.22-50-51.mp4

@p-suram p-suram left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey, following up with my previous review, I just checked, you missed below 2 files:

  1. 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');
  2. src\components\UserProfile\BlueSquareLayout.jsx
    const canManageTimeOffRequests = dispatch(hasPermission('manageTimeOffRequests'));

Parth-tech
Parth-tech previously approved these changes Apr 10, 2024

@Parth-tech Parth-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 Parth-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

jennZhang93
jennZhang93 previously approved these changes Apr 12, 2024

@jennZhang93 jennZhang93 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've checked with an owner account. I can visit user management page, add new user, other features like report page are also functioning. The code changes are very detailed which should've covered all hardcoded strings. Good job!

Screenshot 2024-04-12 at 3 58 40 PM Screenshot 2024-04-12 at 3 58 45 PM Screenshot 2024-04-12 at 4 00 05 PM

@anandsesha

Copy link
Copy Markdown
Contributor

Hi, I have tested your changes using owner and admin users and it works as expected. I am able to create a user from user management for both users and view the dashboard and timelog sections. For volunteer users that option is not available as expected.

Owner:
Screenshot (807)
Screenshot (808)
Screenshot (809)
volunteer
Screenshot (816)

@KurtisIvey

Copy link
Copy Markdown
Contributor

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
j-corp-25 previously approved these changes Apr 13, 2024

@j-corp-25 j-corp-25 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 metaphor987 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@Tiantian-C Tiantian-C left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi, I have reviewed this PR and logged in as different users, no errors.

Screenshot 2024-04-13 at 5 53 52 PM Screenshot 2024-04-13 at 5 54 13 PM

aaryaneil
aaryaneil previously approved these changes Apr 14, 2024

@aaryaneil aaryaneil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@one-community one-community changed the title Anirudh permissions mangement Anirudh permissions management: Create constants for permission keys to replace passing strings directly into hasPermission() Apr 15, 2024
@one-community one-community changed the title Anirudh permissions management: Create constants for permission keys to replace passing strings directly into hasPermission() Anirudh D - permissions management: Create constants for permission keys to replace passing strings directly into hasPermission() Apr 15, 2024

@p-suram p-suram left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey, following up with my previous review, I just checked, you missed below 2 files:

  1. 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');
  2. src\components\UserProfile\BlueSquareLayout.jsx
    const canManageTimeOffRequests = dispatch(hasPermission('manageTimeOffRequests'));

@Pandani07

Copy link
Copy Markdown
Contributor Author

This PR will likely have a LOT of merge conflicts. Many of them probably breaking things of not merged correctly.

I have resolved the merge conflicts now

@Pandani07

Copy link
Copy Markdown
Contributor Author

Hey, following up with my previous review, I just checked, you missed below 2 files:

  1. 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');
  2. src\components\UserProfile\BlueSquareLayout.jsx
    const canManageTimeOffRequests = dispatch(hasPermission('manageTimeOffRequests'));

Will check

@Pandani07

Copy link
Copy Markdown
Contributor Author

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!

Hello, working on it now. I was not working the last weeks.

@Chuehleo Chuehleo added High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible and removed High Priority - Please Review First labels May 1, 2024

@cgomezhub cgomezhub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Please see the attached images for reference.
Screenshot 2024-05-07 094911
Screenshot 2024-05-07 095950
Screenshot 2024-05-07 100024

@nishithaShetty

Copy link
Copy Markdown

Hi Anirudh, Nice work! it works as expected.
PR#2052_1
PR#2052_2
PR#2052_3
PR#2052_4

Sandhya1236
Sandhya1236 previously approved these changes May 26, 2024

@Sandhya1236 Sandhya1236 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

image

@one-community one-community added do not review Do not review or look at code without full context and removed High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible labels May 30, 2024
@one-community

Copy link
Copy Markdown
Member

@one-community one-community added the Saved for Later Implementation This is an important fix but it needs to wait for other fixes first label Aug 11, 2024

@Dnagabahiru Dnagabahiru left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Image Image Image Image Image

@Dnagabahiru Dnagabahiru left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Image Image Image Image Image

@nathanah nathanah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const canPutUserProfileImportantInfo = props.hasPermission(permissions.userManagement.putUserProfileImportantInfo);

Extra?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines +708 to +716
// 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');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not review Do not review or look at code without full context Saved for Later Implementation This is an important fix but it needs to wait for other fixes first

Projects

None yet

Development

Successfully merging this pull request may close these issues.