feat(permission): add AssignRole/AssignAdditionalPrivileges with conditions for Members, Identities, and Groups#5593
feat(permission): add AssignRole/AssignAdditionalPrivileges with conditions for Members, Identities, and Groups#5593victorvhs017 wants to merge 35 commits intomainfrom
Conversation
…fields and conditions for member actions - Updated `validatePrivilegeChangeOperation` to accept optional `subjectFields` for more granular permission checks. - Introduced `MemberSubjectFields` type to define fields relevant to member permissions. - Enhanced `ActionAllowedConditions` to include conditions for granting privileges to members. - Implemented new validation logic for grant privilege actions in `project-additional-privilege-factory`. - Updated frontend components to utilize new grant privilege conditions for filtering roles and actions based on permissions.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
…nd subject matching - Introduced helper functions for action and subject matching to streamline permission validation logic. - Updated handling of rule subjects to support both single and multiple subject scenarios. - Added a NotFoundError for better error handling when a target user is not found during project membership updates.
…d privilege assignments - Introduced `AssignRole` and `AssignAdditionalPrivileges` actions to improve role management for project members. - Updated permission validation logic to prevent conflicts between legacy and new privilege actions. - Enhanced documentation to reflect new actions and their conditions for better clarity in permission management.
…in project permissions - Updated error messages for permission-related actions to improve clarity. - Added role slug to permission service factory for better role management. - Refined privilege validation logic in project additional privilege factory to reflect accurate action descriptions. - Improved condition checks for granting privileges in frontend components to ensure proper role modifications.
…s for project roles - Introduced new condition checks for granting privileges in the project additional privilege factory. - Updated frontend components to utilize new privilege conditions, improving role management and user feedback. - Enhanced tooltip functionality to provide clearer permission-related messages in UI elements. - Refined privilege handling logic to ensure accurate validation and user experience across project member actions.
…g in project components - Updated privilege validation logic in MemberProjectAdditionalPrivilegeSection to ensure accurate email checks. - Enhanced GeneralPermissionPolicies to conditionally hide legacy actions based on permission rules. - Revised action descriptions in ProjectRoleModifySection.utils for clarity on legacy actions and their usage.
…ion conditions - Changed label from "Target Email" to "User Email" for clarity in the MemberPermissionConditions component. This improves the user interface by providing a more accurate description of the field's purpose.
…ion for project permissions - Introduced `validateAssignableActionFormat` function to validate action format and subject assignments in both backend and frontend components. - Updated `extractConditionValues` to streamline condition value extraction for permission checks. - Enhanced `MemberConditionSchema` and `ConditionSchema` to incorporate new validation logic, improving error handling and user feedback for action-related conditions.
…missions - Updated `validateAssignableActionFormat` to accept a configuration object for improved subject validation, including allowed, forbidden, and glob pattern checks. - Refactored condition extraction in `MemberConditionSchema` and `ConditionSchema` to utilize the new validation logic, enhancing error handling and user feedback. - Integrated `picomatch` for glob pattern matching in subject validation across both backend and frontend components.
…schema - Updated the handling of forbidden subjects in `ConditionSchema` to ensure that only trimmed values are considered, improving validation accuracy for permission conditions. - Enhanced the logic for `$NEQ` operator to correctly manage subject values, contributing to better error handling and user feedback in permission-related actions.
…ilege validation - Added `AssignRole` and `AssignAdditionalPrivileges` actions to the permission system for improved identity role management. - Updated validation logic to prevent conflicts between legacy and new actions, ensuring clearer permission handling. - Enhanced condition schemas and frontend components to utilize new grant privilege conditions, improving role filtering and user feedback. - Refined error handling and messaging for identity-related permission actions to enhance clarity and user experience.
- Updated condition extraction to safely handle undefined values in `MemberConditions` and `IdentityConditions`, ensuring robust permission checks. - Enhanced the logic for processing rules to prevent potential errors when conditions are not defined, improving overall validation accuracy.
…ermission handling - Added `AssignRole` action to the permission system, replacing the legacy `GrantPrivileges` action for group management. - Updated validation logic to prevent conflicts between legacy and new actions, ensuring clearer permission handling. - Enhanced condition schemas and frontend components to utilize new grant privilege conditions for groups, improving role filtering and user feedback. - Refined error handling and messaging for group-related permission actions to enhance clarity and user experience.
…ssionPolicies - Introduced a separate state management for legacy actions to prevent unnecessary re-renders in the ActionsMultiSelect component. - Updated the logic to conditionally hide legacy actions based on the new state, improving performance and clarity in permission handling. - Enhanced the useMemo hooks to streamline dependency management for better efficiency in rendering.
Greptile SummaryThis PR introduces granular privilege actions ( Key items worth addressing before merge:
Confidence Score: 3/5
Important Files Changed
|
- Modified the role structure in `permission-service-types.ts` to make `id`, `createdAt`, and `updatedAt` optional, enhancing flexibility in role definitions. - Updated the `permission-service.ts` to include the `name` property in the role object, improving clarity and consistency in role handling.
…on for roles - Added `AssignRole` and `AssignAdditionalPrivileges` actions to the admin permission rules, improving role management capabilities. - Introduced `extractNegatedConditionValues` function to streamline the extraction of forbidden values from conditions, enhancing validation accuracy. - Updated frontend components to utilize new grant privilege conditions, improving role filtering and user feedback in group management.
…ce role validation - Refactored the grant condition extraction logic to utilize a more flexible configuration-based approach, improving maintainability and clarity. - Introduced a new `ConditionMapping` type to enhance the handling of condition keys and their corresponding results. - Updated the `isGrantPrivilegesMemberRule` function to improve readability and maintainability. - Enhanced the GroupsTab component to ensure proper handling of inverted permission rules, improving role validation accuracy.
|
@greptileai re-review and update the summary |
… conditions - Added `filterByGrantConditions` and `canModifyByGrantConditions` functions to streamline the handling of permission checks based on grant conditions. - Updated various components to utilize the new functions for improved role filtering and permission validation, enhancing code clarity and maintainability. - Refactored existing logic in components such as `GroupsTab`, `AddMemberModal`, and `IdentityProjectAdditionalPrivilegeSection` to leverage the new utility functions, improving overall permission handling.
|
@greptileai re-review and update the summary |
backend/src/services/membership-user/project/project-membership-user-factory.ts
Show resolved
Hide resolved
backend/src/services/additional-privilege/project/project-additional-privilege-factory.ts
Show resolved
Hide resolved
…ber actions - Added a new schema for member actions in the project permission structure, enhancing the flexibility of permission definitions. - Removed the previous member action schema to streamline the overall permission handling, ensuring clarity and maintainability. - Updated descriptions for better understanding of the new member permission conditions and actions.
…ship actions - Introduced unconditional checks for privilege validation in project membership group, identity, and user factories to streamline permission handling. - Updated validation logic to ensure that legacy actions are only invoked when necessary, improving clarity and maintainability. - Enhanced error handling for permission boundary checks, providing clearer feedback on missing permissions during project membership creation and updates.
… validation - Introduced a new `refineSubjectActionConditions` function to encapsulate the logic for validating subject and action conditions, improving code reusability and clarity. - Updated the `MemberConditionSchema` and `IdentityManagementConditionSchema` to utilize the new function, reducing redundancy in validation logic. - Enhanced error handling for action validation, ensuring clearer feedback on issues related to subject conditions.
|
@greptileai re-review and update summary |
backend/src/services/additional-privilege/project/project-additional-privilege-factory.ts
Outdated
Show resolved
Hide resolved
backend/src/services/additional-privilege/project/project-additional-privilege-factory.ts
Show resolved
Hide resolved
…n and introduce new guard logic - Updated the `newProjectAdditionalPrivilegesFactory` to improve permission validation by ensuring that unconditional allow rules take precedence over other conditions. - Introduced a new `$validateAdditionalPrivilegesGuard` function to encapsulate detailed privilege validation logic, enhancing clarity and maintainability. - Streamlined the handling of legacy actions and improved error handling for permission boundary checks, providing clearer feedback on missing permissions. - Refactored the `onCreateAdditionalPrivilegesGuard` to utilize the new guard logic, ensuring consistent permission checks across different actor types.
|
@greptileai re-review and update the summary |
…entity creation - Refactored the error handling logic in the `newProjectMembershipIdentityFactory` to enhance clarity and maintainability. - Streamlined the construction of permission error messages, ensuring consistent feedback on missing permissions during identity project membership creation.
|
@greptileai re-review and update summary |
backend/src/services/membership-group/project/project-membership-group-factory.ts
Outdated
Show resolved
Hide resolved
… for member management - Replaced `getGrantPrivilegeConditions` with `getMemberGrantPrivilegeConditions` across various components to improve clarity and specificity in member-related permission handling. - Updated related imports and usages in `AddMemberModal`, `MemberProjectAdditionalPrivilegeSection`, and `MemberRoleDetailsSection` to reflect the new function naming, enhancing code maintainability and readability.
akhilmhdh
left a comment
There was a problem hiding this comment.
Pending application testing
backend/src/services/additional-privilege/project/project-additional-privilege-factory.ts
Show resolved
Hide resolved
backend/src/services/membership-group/project/project-membership-group-factory.ts
Outdated
Show resolved
Hide resolved
backend/src/services/membership-identity/project/project-membership-identity-factory.ts
Outdated
Show resolved
Hide resolved
backend/src/services/membership-user/project/project-membership-user-factory.ts
Outdated
Show resolved
Hide resolved
| allowed: grantPrivilegeConditions.groupNames, | ||
| forbidden: grantPrivilegeConditions.forbiddenGroupNames | ||
| }); | ||
| }, [permission, grantPrivilegeConditions, groupName]); |
There was a problem hiding this comment.
Instead of memoing permission each time - why not a single memo for the whole thing and return a object contains all the properties
| subject(ProjectPermissionSub.Identity, { identityId }) | ||
| ); | ||
|
|
||
| const grantPrivilegeConditions = useMemo( |
There was a problem hiding this comment.
Same comment - instead of memoing permission each time, one single memo with various props as keys
| ProjectPermissionSub.Member | ||
| ); | ||
|
|
||
| const grantPrivilegeConditions = useMemo( |
There was a problem hiding this comment.
Like wise everywhere we are doing memo
…ation logic - Updated permission-related schemas and validation functions to replace legacy field names with more descriptive ones, such as changing `email` to `userEmail` and `role` to `assignableRole`. - Enhanced the `validatePrivilegeChangeOperation` function to accept multiple actions, improving flexibility in permission checks. - Streamlined error handling in project membership factories to provide clearer feedback on permission issues, ensuring consistent validation across member, identity, and group actions. - Updated documentation to reflect the new permission field names and conditions, improving clarity for developers.
- Updated the button's disabled state in `IdentityRoleModify` to include a check for empty filtered roles, ensuring that users cannot attempt to modify roles when none are available. - Simplified the edit disabled condition in `MemberProjectAdditionalPrivilegeSection` by removing the check for ownership, enhancing clarity in permission handling.
…onent - Removed the unused import of `ProjectMembershipRole` in the `IdentityRoleModify` component to enhance code cleanliness and maintainability.
…eadability - Removed unused imports and simplified permission checks in the `newProjectAdditionalPrivilegesFactory` to improve clarity. - Reformatted condition mappings in `permission.ts` for better readability. - Updated action allowed conditions in `ProjectRoleModifySection.utils.tsx` to enhance consistency and maintainability.
…ition checks - Updated the `MemberRoleModify` component to include additional checks for role modification permissions, ensuring that buttons are only enabled when appropriate. - Refactored condition mappings in `ProjectRoleModifySection.utils.tsx` to replace legacy field names with more descriptive ones, improving clarity and maintainability.
…leModify component - Enhanced the readability of the disabled state condition for the role modification button in the `MemberRoleModify` component by formatting the logic across multiple lines. - This change improves clarity in understanding the conditions under which the button is enabled or disabled, aligning with recent refactoring efforts in permission handling.
akhilmhdh
left a comment
There was a problem hiding this comment.
Just some minor ux issues in application testing. Rest looks good @victorvhs017
One main one is error message for assign role. The additional privilege one has spot on error message. The assign role is a bit misleading
| import { OrgPermissionSet } from "./org-permission"; | ||
| import { | ||
| ActionAllowedConditions, | ||
| ProjectPermissionGroupActions, |
| ProjectPermissionIdentityActions, | ||
| ProjectPermissionMemberActions, | ||
| ProjectPermissionSecretActions, | ||
| ProjectPermissionSet, |
…ction descriptions - Improved the clarity of permission error messages in the `constructPermissionErrorMessage` function to provide more detailed feedback on permission denials. - Updated action descriptions in `IdentityManagementPermissionConditions` and `MemberPermissionConditions` components to reflect more specific examples, enhancing user understanding of assignable actions. - Removed unused imports in the `ConditionsFields` component to streamline the code and improve maintainability.
…dify and MemberRoleModify components - Updated the role selection logic in both `IdentityRoleModify` and `MemberRoleModify` components to utilize a new helper function for determining assignable roles, improving code clarity and maintainability. - Enhanced the rendering of role options to include permission checks, providing users with clearer feedback on assignable roles. - Streamlined the handling of role assignment conditions in the `ConditionsFields` component to improve user experience and messaging.
…ilege factory - Eliminated the unused import of `TIdentityDALFactory` in the `newProjectAdditionalPrivilegesFactory` to enhance code cleanliness and maintainability.
…rvice - Eliminated the unused import of `TIdentityDALFactory` in the `additionalPrivilegeServiceFactory` to enhance code cleanliness and maintainability.
- Eliminated the unused import of `identityDAL` in the route registration function to enhance code cleanliness and maintainability.





Context
This PR refactors project RBAC by introducing granular privilege actions and condition-based permission rules for Members, Identities, and Groups.
Before: Only
GrantPrivilegesexisted, with no conditions or subject/action scoping.After:
AssignRole(role assignment) andAssignAdditionalPrivileges(subject:action scoping)GrantPrivilegesis deprecated; it cannot be combined withAssignRoleorAssignAdditionalPrivileges{subject}:{action}), forbidden subjects, and assignable subject allow-listsScreenshots
In the video below, I show all the new Actions set in a role called "test". Then I switch to another browser where I have a user with this test role. Check how the conditions set for him change what he can and cannot do regarding roles and additional privileges of Users, Machine Identities, and Groups.
Screenshare.-.2026-03-05.8_23_54.PM.mp4
Steps to verify the change
UI – allow/forbid:
Legacy actions:
GrantPrivilegesonly.GrantPrivilegesstill work.API – user:
AssignRoleandAssignAdditionalPrivileges.API – machine identity:
AssignRoleandAssignAdditionalPrivileges.Type
Checklist
type(scope): short description(scope is optional, e.g.,fix: prevent crash on syncorfix(api): handle null response).