Skip to content

feat(BA-5906): bulk add/remove/replace role permissions repository#11422

Open
fregataa wants to merge 7 commits intomainfrom
fix/BA-5906-bulk-role-permissions
Open

feat(BA-5906): bulk add/remove/replace role permissions repository#11422
fregataa wants to merge 7 commits intomainfrom
fix/BA-5906-bulk-role-permissions

Conversation

@fregataa
Copy link
Copy Markdown
Member

@fregataa fregataa commented Apr 29, 2026

Summary

  • New repository / service / action triplet for managing role permissions in bulk, layered on top of the existing permission_controller domain.
  • Repository methods (bulk_add_role_permissions, bulk_remove_role_permissions, replace_role_permissions) delegate to execute_bulk_creator_partial / execute_bulk_purger_partial, exposing per-row success/failure breakdown via BulkCreatorResultWithFailures / BulkPurgerResultWithFailures.
  • Each Action carries a single bulk-helper field (creator: BulkCreator[PermissionRow] or purgers: list[Purger[PermissionRow]]) so the input shape mirrors the helper contract.

Test plan

  • DB-backed unit tests in tests/unit/manager/repositories/permission_controller/test_role_permissions_bulk.py — 11 tests cover:
    • bulk_add: missing role → failures recorded; happy-path inserts; duplicate inserts → ON CONFLICT-equivalent failures recorded with existing rows preserved; empty creator → no-op.
    • bulk_remove: unknown PK → no success; partial-target removal preserves siblings; empty list → no-op.
    • replace: full swap (wipe + insert); empty creator clears role; missing role → ObjectNotFound.
  • pants fmt fix lint check — all green.

Resolves BA-5906

…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>
Copilot AI review requested due to automatic review settings April 29, 2026 12:27
@github-actions github-actions Bot added size:XL 500~ LoC comp:manager Related to Manager component labels Apr 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 using execute_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.

@fregataa fregataa changed the title feat(BA-5906): bulk add/remove/replace role permissions (repo+service+action) feat(BA-5906): bulk add/remove/replace role permissions repository Apr 29, 2026
@fregataa fregataa marked this pull request as draft April 29, 2026 12:47
…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>
@fregataa fregataa added this to the 26.4 milestone Apr 29, 2026
@fregataa fregataa marked this pull request as ready for review April 29, 2026 13:29
@fregataa fregataa requested review from a team and removed request for a team April 29, 2026 13:54
@fregataa fregataa marked this pull request as draft April 29, 2026 13:57
fregataa and others added 2 commits April 29, 2026 23:39
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>
@fregataa fregataa marked this pull request as ready for review April 29, 2026 15:04
@fregataa fregataa requested a review from a team April 29, 2026 15:04
fregataa and others added 2 commits April 30, 2026 00:04
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants