Skip to content

Purav Finish PR #2052 Centralize permission keys for hasPermission - #5431

Open
pixelpix13 wants to merge 8 commits into
developmentfrom
feature/Purav-takingover-permission-constants
Open

Purav Finish PR #2052 Centralize permission keys for hasPermission#5431
pixelpix13 wants to merge 8 commits into
developmentfrom
feature/Purav-takingover-permission-constants

Conversation

@pixelpix13

@pixelpix13 pixelpix13 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

Implements permission-key constants so components no longer pass raw strings into hasPermission() (PR #2052 / task: Finish PR2052 – Create constants for permission keys).
pr 5431 task

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 match development when 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 from Permissions.json + legacy keys) and using RoutePermissions in 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):

  • Frontend-only PR — no related backend PR.
  • Takeover / continuation of Anirudh’s earlier WIP branch Anirudh_permissionsMangement (never merged); reimplemented on current development with flat permissions.* keys + RoutePermissions (instead of nested hand-written constants).

Main changes explained:

  • Create src/utils/permissionKeys.js — builds frozen permissions map from Permissions.json + LEGACY_OR_EXTRA_KEYS; also exports permissionCategories.
  • Update src/utils/constants.js — re-exports permissions / permissionCategories.
  • Update src/utils/routePermissions.js — route/nav permission lists use permissions.* constants.
  • Update src/utils/permissions.js — supports array-style OR checks used by RoutePermissions.
  • Update Header and many feature areas (User Management, Projects/WBS, Teams, Timelog, Badges, Warnings, Permissions Management, BM/CP/KI headers, Weekly Summaries Report, Job Analytics, etc.) to call hasPermission(permissions.X) / RoutePermissions.* instead of string literals.
  • Update leftover access checks (viewWBSpermissionsRequired, routes Blue Square Email, frontPermissions.includes(...), etc.) to use the same constants.
  • Synced with latest origin/development (Header / UserManagement conflicts resolved while keeping constants).
Before After
hasPermission('postProject') hasPermission(permissions.postProject)
Long Header OR-chains of strings hasPermission(RoutePermissions.userManagement) etc.
Scattered magic strings Central map in permissionKeys.js

How to test:

  1. Check out this branch: feature/Purav-takingover-permission-constants
  2. Run npm install (Node v20.19.4 recommended), then start locally: npm run start:local (app at http://localhost:5173)
  3. Clear site data/cache for localhost if needed
  4. Log in as Admin (and also retest as Volunteer). For full role CRUD / permission toggles, use an Owner account (or ask Jae to upgrade a Dev account)

Smoke (Admin / Volunteer)

  • App loads with no console/runtime errors from permission checks
  • Header nav shows expected links for that role (Reports, User Management, Projects, Teams, Badges, Permissions Management, Send Emails, Schedule Meetings, etc.)
  • Permissions Management page opens
  • Dark mode still works normally (no UI redesign in this PR — confirm existing screens look correct in dark mode)

Permission ON / OFF regression (Owner recommended)

Toggle permissions in Permissions Management → Save → hard refresh / re-login → confirm UI:

  • Header / nav — Reports, Weekly Summaries, User Management, Badge Management, Projects, Teams, Permissions Management, Announcements/Send Emails, Schedule Meetings, PR Dashboard, Blue Square Email Management
  • User Management — list / create / delete user, status/pause, time-off, set final day
  • Projects / WBS / Tasks — project CRUD, members, WBS, tasks
  • Teams — create/edit/delete, assign members
  • Timelog / Weekly Summaries — edit/delete entries, edit summaries
  • Badges / Blue Squares / Warnings
  • Other — LeaderBoard, SummaryBar, Job Analytics (getJobReports), Weekly Summaries bio highlight filter

Pass criteria: ON → control available and works; OFF → hidden/disabled/blocked; no white screens.

Known note to verify

  • Header Badge Management uses RoutePermissions.badgeManagement, which includes assignBadges (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_1 pr 5431_2
pr.5431_video.mp4

Note:

  • No new UI/feature — reviewers should verify behavior parity with development, not look for new screens.
  • Full permission regression needs Owner (or postRole / putRole / deleteRole). Admin alone may not be able to add/edit/delete roles.
  • Dark mode: unchanged by design; still confirm no regressions on touched pages.
  • CSS: no new generic global class names introduced for this refactor.
  • Quality Gate / SonarCloud: passed on latest analysis after cleanup commits.

pixelpix13 and others added 4 commits August 3, 2026 21:24
…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>
@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploy Preview for highestgoodnetwork-dev ready!

Name Link
🔨 Latest commit 2999e59
🔍 Latest deploy log https://app.netlify.com/projects/highestgoodnetwork-dev/deploys/6a836cc51c7cf9000831117e
😎 Deploy Preview https://deploy-preview-5431--highestgoodnetwork-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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>
@pixelpix13 pixelpix13 changed the title Finish PR #2052: Centralize permission keys via permissionKeys constants Purarv-Takingover-PR #2052: Centralize permission keys via permissionKeys constants Aug 6, 2026
@pixelpix13 pixelpix13 changed the title Purarv-Takingover-PR #2052: Centralize permission keys via permissionKeys constants Purav-Takingover-PR #2052: Centralize permission keys via permissionKeys constants Aug 6, 2026
@pixelpix13 pixelpix13 changed the title Purav-Takingover-PR #2052: Centralize permission keys via permissionKeys constants Purav Finish PR #2052 Centralize permission keys for hasPermission Aug 9, 2026
@one-community one-community added the High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible label Aug 13, 2026

@Adit0717 Adit0717 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.

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 DeepighaJ 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 see after toggle on/off the persmission management table is not updated, it is intended behavior?
Admin:

Image Image Image Image Image Image Image

Toggle Permission
Image
Image
Image
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.
Image
Create team is not available as its toggled off
Image
JobAnalytic:
Image
Image
Image
Image
Image

Volunteer:

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.

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.

Comment on lines +30 to +31
const canUpdateBadges = hasPermission(permissions['update:badges']);
const canDeleteBadges = hasPermission(permissions['delete:badges']);

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

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
() => userRole === 'Owner' || dispatch(hasPermission(permissions.deleteFormQuestions)),
() => dispatch(hasPermission(permissions.deleteFormQuestions)),


const canEditQuestionSets = useMemo(
() => userRole === 'Owner' || dispatch(hasPermission('editFormQuestions')),
() => userRole === 'Owner' || dispatch(hasPermission(permissions.editFormQuestions)),

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
() => userRole === 'Owner' || dispatch(hasPermission(permissions.editFormQuestions)),
() => dispatch(hasPermission(permissions.editFormQuestions)),


const canCreateQuestionSets = useMemo(
() => userRole === 'Owner' || dispatch(hasPermission('createFormQuestions')),
() => userRole === 'Owner' || dispatch(hasPermission(permissions.createFormQuestions)),

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
() => userRole === 'Owner' || dispatch(hasPermission(permissions.createFormQuestions)),
() => dispatch(hasPermission(permissions.createFormQuestions)),


const canCreateQuestionSets = useMemo(
() => userRole === 'Owner' || dispatch(hasPermission('createFormQuestions')),
() => userRole === 'Owner' || dispatch(hasPermission(permissions.createFormQuestions)),

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
() => userRole === 'Owner' || dispatch(hasPermission(permissions.createFormQuestions)),
() => dispatch(hasPermission(permissions.createFormQuestions)),


const canManageForms = useMemo(
() => userRole === 'Owner' || dispatch(hasPermission('manageJobForms')),
() => userRole === 'Owner' || dispatch(hasPermission(permissions.manageJobForms)),

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
() => userRole === 'Owner' || dispatch(hasPermission(permissions.manageJobForms)),
() => dispatch(hasPermission(permissions.manageJobForms)),

Comment thread src/components/Header/Header.jsx Outdated
Comment on lines +214 to +215
props.hasPermission(RoutePermissions.permissionsManagement, !isAuthUser) ||
props.hasPermission(RoutePermissions.userPermissionsManagement, !isAuthUser);

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(RoutePermissions.permissionsManagement, !isAuthUser) ||
props.hasPermission(RoutePermissions.userPermissionsManagement, !isAuthUser);
props.hasPermission(RoutePermissions.permissionsManagement, !isAuthUser);

pixelpix13 and others added 2 commits August 17, 2026 15:07
…checks, simplify Header permissionsManagement access.

Co-authored-by: Cursor <cursoragent@cursor.com>
@pixelpix13

Copy link
Copy Markdown
Contributor Author

@DeepighaJ can you tell me what role did you use to test?

…on-only access pattern.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud

Copy link
Copy Markdown

@linlin-husky linlin-husky 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 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?

Image Image

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

Labels

High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants