Purav Finish PR #2052 Centralize permission keys for hasPermission - #5431
Purav Finish PR #2052 Centralize permission keys for hasPermission#5431pixelpix13 wants to merge 8 commits into
Conversation
…le components for improved maintainability and consistency. Updated permission checks in BMHeader, BadgeDevelopmentTable, BadgeReport, JobFormBuilder, CPHeader, Header, EnhancedJobFormBuilder, and various Project components.
…stants Co-authored-by: Cursor <cursoragent@cursor.com>
…stants Co-authored-by: Cursor <cursoragent@cursor.com>
…nstants. Co-authored-by: Cursor <cursoragent@cursor.com>
✅ Deploy Preview for highestgoodnetwork-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…rmission vars, add sort comparator. Co-authored-by: Cursor <cursoragent@cursor.com>
Adit0717
left a comment
There was a problem hiding this comment.
Tested this locally on the "feature/Purav-takingover-permission-constants" branch. Verified the following routes using both Admin and Volunteer roles:
Admin role:
/projects - accessible
/usermanagement - accessible
/badgemanagement - accessible
/teams - accessible
/permissionsmanagement - accessible
/announcements - redirected to /dashboard
Volunteer role:
/projects, /usermanagement, /badgemanagement, /teams, /permissionsmanagement - all redirected to /dashboard
DeepighaJ
left a comment
There was a problem hiding this comment.
I see after toggle on/off the persmission management table is not updated, it is intended behavior?
Admin:
Toggle Permission



Assign badge is toggled off and assign badge is enabled and it allows to select badges and on clicking confirm it throws below error. The message should state no permission/permission toggled off something like that.

Create team is not available as its toggled off

JobAnalytic:





Volunteer:
nathanah
left a comment
There was a problem hiding this comment.
I think 'update:badges' is the wrong key.
I caught some redundant role checks for owner that we can clean up while we're at it.
Could reorganize the groups to be more useful, but this is fine.
Otherwise, looks good.
| const canUpdateBadges = hasPermission(permissions['update:badges']); | ||
| const canDeleteBadges = hasPermission(permissions['delete:badges']); |
There was a problem hiding this comment.
| const canUpdateBadges = hasPermission(permissions['update:badges']); | |
| const canDeleteBadges = hasPermission(permissions['delete:badges']); | |
| const canUpdateBadges = hasPermission(permissions.updateBadges); | |
| const canDeleteBadges = hasPermission(permissions.deleteBadges); |
Should it be this?
|
|
||
| const canDeleteQuestionSets = useMemo( | ||
| () => userRole === 'Owner' || dispatch(hasPermission('deleteFormQuestions')), | ||
| () => userRole === 'Owner' || dispatch(hasPermission(permissions.deleteFormQuestions)), |
There was a problem hiding this comment.
| () => userRole === 'Owner' || dispatch(hasPermission(permissions.deleteFormQuestions)), | |
| () => dispatch(hasPermission(permissions.deleteFormQuestions)), |
|
|
||
| const canEditQuestionSets = useMemo( | ||
| () => userRole === 'Owner' || dispatch(hasPermission('editFormQuestions')), | ||
| () => userRole === 'Owner' || dispatch(hasPermission(permissions.editFormQuestions)), |
There was a problem hiding this comment.
| () => userRole === 'Owner' || dispatch(hasPermission(permissions.editFormQuestions)), | |
| () => dispatch(hasPermission(permissions.editFormQuestions)), |
|
|
||
| const canCreateQuestionSets = useMemo( | ||
| () => userRole === 'Owner' || dispatch(hasPermission('createFormQuestions')), | ||
| () => userRole === 'Owner' || dispatch(hasPermission(permissions.createFormQuestions)), |
There was a problem hiding this comment.
| () => userRole === 'Owner' || dispatch(hasPermission(permissions.createFormQuestions)), | |
| () => dispatch(hasPermission(permissions.createFormQuestions)), |
|
|
||
| const canCreateQuestionSets = useMemo( | ||
| () => userRole === 'Owner' || dispatch(hasPermission('createFormQuestions')), | ||
| () => userRole === 'Owner' || dispatch(hasPermission(permissions.createFormQuestions)), |
There was a problem hiding this comment.
| () => userRole === 'Owner' || dispatch(hasPermission(permissions.createFormQuestions)), | |
| () => dispatch(hasPermission(permissions.createFormQuestions)), |
|
|
||
| const canManageForms = useMemo( | ||
| () => userRole === 'Owner' || dispatch(hasPermission('manageJobForms')), | ||
| () => userRole === 'Owner' || dispatch(hasPermission(permissions.manageJobForms)), |
There was a problem hiding this comment.
| () => userRole === 'Owner' || dispatch(hasPermission(permissions.manageJobForms)), | |
| () => dispatch(hasPermission(permissions.manageJobForms)), |
| props.hasPermission(RoutePermissions.permissionsManagement, !isAuthUser) || | ||
| props.hasPermission(RoutePermissions.userPermissionsManagement, !isAuthUser); |
There was a problem hiding this comment.
| props.hasPermission(RoutePermissions.permissionsManagement, !isAuthUser) || | |
| props.hasPermission(RoutePermissions.userPermissionsManagement, !isAuthUser); | |
| props.hasPermission(RoutePermissions.permissionsManagement, !isAuthUser); |
…checks, simplify Header permissionsManagement access. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@DeepighaJ can you tell me what role did you use to test? |
…on-only access pattern. Co-authored-by: Cursor <cursoragent@cursor.com>
|
linlin-husky
left a comment
There was a problem hiding this comment.
I tried to login with Volunteer and admin Role: for both roles, Route protection works as expected. Directly navigating to admin routes (/projects, /usermanagement, /badgemanagement, /teams, /permissionsmanagement) correctly redirects back to /dashboard. Also for admin role, Core management pages and header navigation load properly with the updated permission constants.
However, when I navigated to check Badge Management, when I clicked the Edit button in badge management, the page crashed.
Attaching the crash screenshot. Could you please take a look at the modal trigger and permission checks in BadgeDevelopmentTable.jsx?



Description
Implements permission-key constants so components no longer pass raw strings into

hasPermission()(PR #2052 / task: Finish PR2052 – Create constants for permission keys).This is a frontend refactor only (takeover of Anirudh’s WIP
Anirudh_permissionsMangement). There is no new UI feature. Runtime permission values are unchanged (permissions.postProject === 'postProject'), so behavior should matchdevelopmentwhen the same permissions are assigned.Motivation: Reused hardcoded strings across many components are typo-prone and hard to maintain. Centralizing keys in
permissionKeys.js(sourced fromPermissions.json+ legacy keys) and usingRoutePermissionsin Header improves consistency and maintainability going forward (per Jae/Diego notes on PR #2052).Fixes / Implements: PR #2052 (PRIORITY LOW – Finish constants for permission keys / WIP Purav #2052)
Related PRS (if any):
Anirudh_permissionsMangement(never merged); reimplemented on currentdevelopmentwith flatpermissions.*keys +RoutePermissions(instead of nested hand-written constants).Main changes explained:
src/utils/permissionKeys.js— builds frozenpermissionsmap fromPermissions.json+LEGACY_OR_EXTRA_KEYS; also exportspermissionCategories.src/utils/constants.js— re-exportspermissions/permissionCategories.src/utils/routePermissions.js— route/nav permission lists usepermissions.*constants.src/utils/permissions.js— supports array-style OR checks used byRoutePermissions.hasPermission(permissions.X)/RoutePermissions.*instead of string literals.viewWBSpermissionsRequired, routes Blue Square Email,frontPermissions.includes(...), etc.) to use the same constants.origin/development(Header / UserManagement conflicts resolved while keeping constants).hasPermission('postProject')hasPermission(permissions.postProject)hasPermission(RoutePermissions.userManagement)etc.permissionKeys.jsHow to test:
feature/Purav-takingover-permission-constantsnpm install(Node v20.19.4 recommended), then start locally:npm run start:local(app athttp://localhost:5173)Smoke (Admin / Volunteer)
Permission ON / OFF regression (Owner recommended)
Toggle permissions in Permissions Management → Save → hard refresh / re-login → confirm UI:
getJobReports), Weekly Summaries bio highlight filterPass criteria: ON → control available and works; OFF → hidden/disabled/blocked; no white screens.
Known note to verify
RoutePermissions.badgeManagement, which includesassignBadges(development Header OR-chain did not). Confirm whether users with only Assign Badges should see that nav item.Screenshots or videos of changes:
pr.5431_video.mp4
Note:
development, not look for new screens.postRole/putRole/deleteRole). Admin alone may not be able to add/edit/delete roles.