-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b526369
feat(permissions): permissions add
NSUWAL123 8a36f95
feat(permissions): role based permission for component access & hide/β¦
NSUWAL123 40c869b
feat(noAccessComponent): fallback component on user permission deny
NSUWAL123 54bf0be
refactor(permissions): update naming convention
NSUWAL123 ebc7f4f
Merge branch 'development' of github.com:hotosm/fmtm into feat/user-rβ¦
NSUWAL123 abfbfc2
feat(enums): project_roles add to enums
NSUWAL123 4d922c7
refactor(usePermissions): use access based permission instead of action
NSUWAL123 04bcfab
refactor(permissions): use access based permission
NSUWAL123 78df095
fix(merge): merge conflict resolve
NSUWAL123 057c822
feat(dialogTaskActions): allow project-manager, org-admin or super-adβ¦
NSUWAL123 9feea20
refactor(usePermission): remove console
NSUWAL123 78698b0
Merge branch 'development' of github.com:hotosm/fmtm into feat/user-rβ¦
NSUWAL123 03fc7fa
fix(organization): restrict organization creation if user already manβ¦
NSUWAL123 ff9f8af
refactor(projectDetailsForm): preselect organization dropdown if userβ¦
NSUWAL123 e15c1a5
fix(projectDetailsForm): list only organizations which the user is asβ¦
NSUWAL123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { user_roles } from '@/types/enums'; | ||
import CoreModules from '@/shared/CoreModules'; | ||
|
||
// ADMIN-ONLY | ||
export function useAdminAccess() { | ||
const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails); | ||
return !!authDetails && authDetails?.role === user_roles.ADMIN; | ||
} | ||
|
||
// PROJECT-LEVEL | ||
export function useCreateProjectAccess() { | ||
const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails); | ||
return authDetails?.role === user_roles.ADMIN || !!authDetails?.orgs_managed; | ||
} | ||
|
||
// ORGANIZATION-LEVEL | ||
export function useEditOrganizationAccess(id: number) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails); | ||
return ( | ||
authDetails?.role === user_roles.ADMIN || (authDetails?.orgs_managed && authDetails?.orgs_managed?.includes(id)) | ||
); | ||
} |
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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.