feat(BA-5906): bulk add/remove/replace role permissions repository#11422
Open
feat(BA-5906): bulk add/remove/replace role permissions repository#11422
Conversation
…ervice, action Add a new repository / service / action triplet for managing role permissions in bulk, layered on top of the existing permission_controller domain. - Repository: bulk_add_role_permissions(creator), bulk_remove_role_permissions(purgers), replace_role_permissions( role_id, creator). Each method delegates to execute_bulk_creator_partial / execute_bulk_purger_partial so callers get per-row success/failure breakdown. - Action: BulkAddRolePermissionsAction(creator), BulkRemoveRolePermissionsAction(purgers), ReplaceRolePermissionsAction(role_id, creator). Each action carries a single bulk-helper field so the input shape mirrors the helper contract. - Service: thin pass-through that wires the actions to the repository and surfaces the BulkCreatorResultWithFailures / BulkPurgerResultWithFailures payloads. Repository layer is deliberately rule-free: the caller (CLI/SDK) is responsible for assembling the desired CreatorSpec/Purger inputs. This keeps the BEP-1012 admin/member operation set as a client-side concern, to be addressed by BA-5909. Tests cover: missing role behavior, empty input no-op, idempotent / duplicate-handling for bulk add (failures recorded), partial-target remove, and replace's wipe-then-insert semantics. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new bulk role-permission management API (repository + service + actions) on top of the existing permission_controller data layer, with partial-success reporting for per-row failures.
Changes:
- Add
PermissionDBSource/repository methods for bulk add, bulk remove, and replace of role permission rows usingexecute_bulk_creator_partial/execute_bulk_purger_partial. - Introduce new permission-controller actions + service/processors wiring for these bulk operations.
- Add DB-backed unit tests covering happy paths, missing-role behavior, duplicates, and no-op inputs.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/manager/repositories/permission_controller/test_role_permissions_bulk.py | New unit tests validating bulk add/remove/replace semantics and partial failure reporting. |
| src/ai/backend/manager/services/permission_contoller/service.py | Exposes new bulk add/remove/replace service methods delegating to the repository. |
| src/ai/backend/manager/services/permission_contoller/processors.py | Registers new actions/processors and advertises them in supported_actions(). |
| src/ai/backend/manager/services/permission_contoller/actions/bulk_add_role_permissions.py | Adds action/result types for bulk insertion of permission rows. |
| src/ai/backend/manager/services/permission_contoller/actions/bulk_remove_role_permissions.py | Adds action/result types for bulk deletion of permission rows. |
| src/ai/backend/manager/services/permission_contoller/actions/replace_role_permissions.py | Adds action/result types for full replacement of a role’s permission set. |
| src/ai/backend/manager/services/permission_contoller/actions/init.py | Re-exports the newly added actions/results. |
| src/ai/backend/manager/repositories/permission_controller/repository.py | Adds repository methods returning Bulk*ResultWithFailures types. |
| src/ai/backend/manager/repositories/permission_controller/db_source/db_source.py | Implements bulk add/remove/replace DB operations with savepoint-isolated partial execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ion ops - Switch bulk_add_role_permissions, bulk_remove_role_permissions, and replace_role_permissions to begin_session_read_committed() so the bulk INSERT / DELETE statements run under read-committed isolation. - Document replace_role_permissions: role existence is verified first (raises ObjectNotFound on missing role), and creator specs are assumed to carry the same role_id as the argument. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Mirror the BulkRoleAssignmentResultData / BulkRoleAssignmentFailure pattern for the new bulk role-permission operations so the manager-side boundary type is a domain dataclass rather than the generic BulkCreatorResultWithFailures helper. data/permission/role.py adds: - BulkRolePermissionAddFailure (role_id + scope + entity + operation + message) - BulkRolePermissionRemoveFailure (permission_id + message) - BulkRolePermissionAddResultData / BulkRolePermissionRemoveResultData / BulkRolePermissionReplaceResultData wrapping list[PermissionData] successes and the matching failure list. Repository layer: - bulk_add / bulk_remove / replace methods now return the new Data types, converting from BulkCreator/Purger results in repository.py. - _add_failure_from_creator_error helper isolates the spec-to-failure translation. Action results: - BulkAddRolePermissionsActionResult / BulkRemoveRolePermissionsActionResult / ReplaceRolePermissionsActionResult now hold the new Data types via a uniform `data` field (matches BulkAssignRoleActionResult.data shape). - entity_id() resolves from the Data type's role_id / successes / failures. Service methods are pass-throughs and tests still drive the DB source directly, so existing test coverage stays valid. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ilure mapping - db_source.bulk_add/remove_role_permissions docstrings collapsed to one line each — matching the brevity of the surrounding methods. - Drop the _add_failure_from_creator_error helper. The conversion now follows the bulk_assign_role pattern: the spec is cast inline (with a walrus binding for the multi-field case) inside the failures list comprehension in the repository. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The bulk add / remove / replace role-permission actions operate on the parent role, so their entity_type() now returns EntityType.ROLE instead of EntityType.ROLE_PERMISSION. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
permission_controllerdomain.bulk_add_role_permissions,bulk_remove_role_permissions,replace_role_permissions) delegate toexecute_bulk_creator_partial/execute_bulk_purger_partial, exposing per-row success/failure breakdown viaBulkCreatorResultWithFailures/BulkPurgerResultWithFailures.creator: BulkCreator[PermissionRow]orpurgers: list[Purger[PermissionRow]]) so the input shape mirrors the helper contract.Test plan
tests/unit/manager/repositories/permission_controller/test_role_permissions_bulk.py— 11 tests cover:ObjectNotFound.pants fmt fix lint check— all green.Resolves BA-5906