forked from hotosm/fmtm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): start user roles integration (hotosm#2207)
* feat(permissions): permissions add * feat(permissions): role based permission for component access & hide/unhide buttons * feat(noAccessComponent): fallback component on user permission deny * refactor(permissions): update naming convention * feat(enums): project_roles add to enums * refactor(usePermissions): use access based permission instead of action * refactor(permissions): use access based permission * feat(dialogTaskActions): allow project-manager, org-admin or super-admin to update the task state * refactor(usePermission): remove console * fix(organization): restrict organization creation if user already manages an organization * refactor(projectDetailsForm): preselect organization dropdown if user is org admin of only one organization * fix(projectDetailsForm): list only organizations which the user is associated with on organization list select
- Loading branch information
Showing
12 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { project_roles, user_roles } from '@/types/enums'; | ||
import CoreModules from '@/shared/CoreModules'; | ||
|
||
export function useIsAdmin() { | ||
const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails); | ||
return authDetails?.role === user_roles.ADMIN; | ||
} | ||
|
||
export function useHasManagedAnyOrganization() { | ||
const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails); | ||
const orgs_managed = authDetails?.orgs_managed || []; | ||
return authDetails?.role === user_roles.ADMIN || orgs_managed?.length > 0; | ||
} | ||
|
||
export function useIsOrganizationAdmin(id: number) { | ||
const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails); | ||
return ( | ||
authDetails?.role === user_roles.ADMIN || (authDetails?.orgs_managed && authDetails?.orgs_managed?.includes(id)) | ||
); | ||
} | ||
|
||
export function useIsProjectManager(id: string | number) { | ||
const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails); | ||
return authDetails?.role === user_roles.ADMIN || authDetails?.project_roles?.[id] === project_roles.PROJECT_MANAGER; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
|
||
const NoAccessComponent = () => { | ||
return <div>Access Denied</div>; | ||
}; | ||
|
||
export default NoAccessComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters