Skip to content
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

Frontend user roles integration #2207

Merged
merged 15 commits into from
Feb 24, 2025
Merged

Frontend user roles integration #2207

merged 15 commits into from
Feb 24, 2025

Conversation

NSUWAL123
Copy link
Contributor

@NSUWAL123 NSUWAL123 commented Feb 18, 2025

What type of PR is this? (check all applicable)

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation
  • πŸ§‘β€πŸ’» Refactor
  • βœ… Test
  • πŸ€– Build or CI
  • ❓ Other (please specify)

Related Issue

Describe this PR

  • Hide/Unhide buttons, provide access to functionality and pages based on user roles

Screenshots

N/A

@github-actions github-actions bot added enhancement New feature or request frontend Related to frontend code labels Feb 18, 2025
}

// ORGANIZATION-LEVEL
export function useEditOrganizationAccess(id: number) {
Copy link
Member

@spwoodcock spwoodcock Feb 18, 2025

Choose a reason for hiding this comment

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

Instead of defining these based on the action type, could they be defined based on the access level?

We shouldn't need many in that scenario:

export function isOrgManager(id: number) {
  const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails);
  return (
    authDetails?.role === user_roles.ADMIN || (authDetails?.orgs_managed && authDetails?.orgs_managed?.includes(id))
  );
}

isProjectManager

isFieldManager

isAdmin

// PROJECT-LEVEL
export function useCreateProjectAccess() {
const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails);
return authDetails?.role === user_roles.ADMIN || !!authDetails?.orgs_managed;
Copy link
Member

Choose a reason for hiding this comment

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

This is good for orgs_managed: null πŸ‘

If for some reason the backend response changed to be orgs_managed: [] this would evaluate true, but the next check for the specific org id should still prevent access.

@NSUWAL123
Copy link
Contributor Author

@spwoodcock please have a look! Updated according to your suggestion.

Copy link
Member

@spwoodcock spwoodcock left a comment

Choose a reason for hiding this comment

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

@NSUWAL123 NSUWAL123 marked this pull request as ready for review February 21, 2025 12:26
@NSUWAL123 NSUWAL123 requested a review from spwoodcock February 21, 2025 12:26
@spwoodcock spwoodcock merged commit 34f7982 into development Feb 24, 2025
6 checks passed
@spwoodcock spwoodcock deleted the feat/user-roles branch February 24, 2025 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request frontend Related to frontend code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants