-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(permission): add AssignRole/AssignAdditionalPrivileges with conditions for Members, Identities, and Groups #5593
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
Open
victorvhs017
wants to merge
36
commits into
main
Choose a base branch
from
feature/privileges-conditions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,879
−566
Open
Changes from 14 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
ba7c4e3
refactor(permission): enhance privilege management by adding subject …
82334d2
refactor(permission): improve privilege checks with enhanced action a…
0605842
refactor(permission): enhance project member actions with new role an…
d4b87dc
refactor(permission): enhance error messaging and privilege handling …
f9fea52
refactor(permission): enhance privilege validation and UI interaction…
ceae491
refactor(permission): improve privilege validation and action handlin…
6cecf19
refactor(permission): update label for target email in member permiss…
ebdba65
refactor(permission): enhance action validation and condition extract…
3180fd3
refactor(permission): enhance action validation logic for project per…
d337b3c
refactor(permission): refine forbidden subject handling in condition …
09a1200
refactor(permission): introduce new identity actions and enhance priv…
3cc6ec2
refactor(permission): improve condition handling in privilege validation
a675996
refactor(permission): introduce AssignRole action and enhance group p…
747052b
refactor(permission): optimize legacy action handling in GeneralPermi…
2bf3930
refactor(permission): update role structure in permission service types
b768094
refactor(permission): enhance permission rules and condition extracti…
be40d4a
refactor(permission): streamline grant condition extraction and enhan…
7979f65
refactor(permission): introduce filter and modify functions for grant…
e7eaea2
refactor(permission): update project permission schema to include mem…
7836efa
refactor(permission): enhance privilege validation for project member…
04bc6b9
refactor(permission): extract and streamline subject-action condition…
b029513
refactor(permission): enhance project additional privileges validatio…
ca2dd61
refactor(permission): improve error handling in project membership id…
7644ba0
refactor(permission): rename and streamline grant privilege functions…
f10c6fb
refactor(permission): standardize permission fields and enhance valid…
f49fd00
fix(permission): improve role modification button logic and validation
e90d3c1
refactor(permission): remove unused import in IdentityRoleModify comp…
489719a
refactor(permission): streamline permission checks and enhance code r…
c8c857e
refactor(permission): enhance role modification logic and update cond…
5b8ab4c
refactor(permission): improve button disabled state logic in MemberRo…
db2c8ad
refactor(permission): enhance permission error messaging and update a…
51cfbbf
refactor(permission): simplify role selection logic in IdentityRoleMo…
d2e8bf8
refactor(permission): remove unused import in project additional priv…
9e547c8
refactor(permission): remove unused import in additional privilege se…
bda6aec
refactor(permission): remove unused import in route registration
27e2d78
refactor(permission): update action schema definitions for project pe…
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ import { ActorAuthMethod, AuthMethod } from "@app/services/auth/auth-type"; | |
| import { OrgPermissionSet } from "./org-permission"; | ||
| import { | ||
| ActionAllowedConditions, | ||
| ProjectPermissionGroupActions, | ||
| ProjectPermissionIdentityActions, | ||
victorvhs017 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ProjectPermissionMemberActions, | ||
| ProjectPermissionSecretActions, | ||
| ProjectPermissionSet, | ||
|
Member
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. |
||
| ProjectPermissionSub, | ||
|
|
@@ -102,6 +105,69 @@ export function checkForInvalidPermissionCombination(permissions: z.infer<typeof | |
| } | ||
| } | ||
|
|
||
| if (permission.subject === ProjectPermissionSub.Member) { | ||
| if (permission.action.includes(ProjectPermissionMemberActions.GrantPrivileges)) { | ||
| const hasAssignRole = permission.action.includes(ProjectPermissionMemberActions.AssignRole); | ||
| const hasAssignAdditionalPrivileges = permission.action.includes( | ||
| ProjectPermissionMemberActions.AssignAdditionalPrivileges | ||
| ); | ||
|
|
||
| if (hasAssignRole || hasAssignAdditionalPrivileges) { | ||
| const hasBothNewActions = hasAssignRole && hasAssignAdditionalPrivileges; | ||
|
|
||
| throw new BadRequestError({ | ||
| message: `You have selected Grant Privileges, and ${ | ||
| hasBothNewActions | ||
| ? "both Assign Role and Assign Additional Privileges" | ||
| : hasAssignRole | ||
| ? "Assign Role" | ||
| : hasAssignAdditionalPrivileges | ||
| ? "Assign Additional Privileges" | ||
| : "" | ||
| }. You cannot select Assign Role or Assign Additional Privileges if you have selected Grant Privileges. The Grant Privileges permission is a legacy action which has been replaced by Assign Role and Assign Additional Privileges.` | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (permission.subject === ProjectPermissionSub.Identity) { | ||
| if (permission.action.includes(ProjectPermissionIdentityActions.GrantPrivileges)) { | ||
| const hasAssignRole = permission.action.includes(ProjectPermissionIdentityActions.AssignRole); | ||
| const hasAssignAdditionalPrivileges = permission.action.includes( | ||
| ProjectPermissionIdentityActions.AssignAdditionalPrivileges | ||
| ); | ||
|
|
||
| if (hasAssignRole || hasAssignAdditionalPrivileges) { | ||
| const hasBothNewActions = hasAssignRole && hasAssignAdditionalPrivileges; | ||
|
|
||
| throw new BadRequestError({ | ||
| message: `You have selected Grant Privileges, and ${ | ||
| hasBothNewActions | ||
| ? "both Assign Role and Assign Additional Privileges" | ||
| : hasAssignRole | ||
| ? "Assign Role" | ||
| : hasAssignAdditionalPrivileges | ||
| ? "Assign Additional Privileges" | ||
| : "" | ||
| }. You cannot select Assign Role or Assign Additional Privileges if you have selected Grant Privileges. The Grant Privileges permission is a legacy action which has been replaced by Assign Role and Assign Additional Privileges.` | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (permission.subject === ProjectPermissionSub.Groups) { | ||
| if (permission.action.includes(ProjectPermissionGroupActions.GrantPrivileges)) { | ||
| const hasAssignRole = permission.action.includes(ProjectPermissionGroupActions.AssignRole); | ||
|
|
||
| if (hasAssignRole) { | ||
| throw new BadRequestError({ | ||
| message: | ||
| "You have selected Grant Privileges and Assign Role. You cannot select Assign Role if you have selected Grant Privileges. The Grant Privileges permission is a legacy action which has been replaced by Assign Role." | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const subjectConditions = ActionAllowedConditions[permission.subject as ProjectPermissionSub]; | ||
| const permissionConditions = "conditions" in permission ? permission.conditions : undefined; | ||
| if (permissionConditions && subjectConditions) { | ||
|
|
@@ -190,10 +256,13 @@ const validatePrivilegeChangeOperation = ( | |
| opAction: OrgPermissionSet[0] | ProjectPermissionSet[0], | ||
| opSubject: OrgPermissionSet[1] | ProjectPermissionSet[1], | ||
| actorPermission: MongoAbility, | ||
| managedPermission: MongoAbility | ||
| managedPermission: MongoAbility, | ||
| subjectFields?: Record<string, string | undefined> | ||
| ) => { | ||
| if (shouldUseNewPrivilegeSystem) { | ||
| if (actorPermission.can(opAction, opSubject)) { | ||
| const subjectToCheck = subjectFields ? subject(opSubject as string, subjectFields) : opSubject; | ||
|
|
||
| if (actorPermission.can(opAction, subjectToCheck)) { | ||
| return { | ||
| isValid: true, | ||
| missingPermissions: [] | ||
|
|
@@ -223,7 +292,7 @@ const constructPermissionErrorMessage = ( | |
| ) => { | ||
| return `${baseMessage}${ | ||
| shouldUseNewPrivilegeSystem | ||
| ? `. Actor is missing permission ${opAction as string} on ${opSubject as string}` | ||
| ? `. Actor is missing permission to perform ${opAction as string} on ${opSubject as string}` | ||
| : ". Actor privilege level is not high enough to perform this action" | ||
| }`; | ||
| }; | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Application testing feedback
I feel like the message could cause confusion. Because i had assign role and just was condition only on those one. It works correctly, just the UI
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.
I tried to make this more generic, including the conditions. What do you think?
Refactoring the error with a detailed message on which condition failed and why would be a big change.