Skip to content

feat(BA-6254): add superadmin ensure-system-role repository/service/action#11891

Open
fregataa wants to merge 2 commits into
mainfrom
feat/BA-6254-ensure-system-role-repository-service
Open

feat(BA-6254): add superadmin ensure-system-role repository/service/action#11891
fregataa wants to merge 2 commits into
mainfrom
feat/BA-6254-ensure-system-role-repository-service

Conversation

@fregataa
Copy link
Copy Markdown
Member

@fregataa fregataa commented Jun 1, 2026

Summary

  • Add ensure_user_system_roles(specs) across repository → service → action → processor: an idempotent superadmin operation that guarantees each given user has a SYSTEM role and its user-role mapping.
  • Creates the role (with permissions) and mapping when missing; reuses the existing role and leaves the mapping untouched on repeat calls (no duplicate / unique-constraint violation). Accepts a batch of UserSystemRoleSpec and returns RoleMappingData per user.
  • Scope is USER (this issue covers repository/service/action only — GQL/adapter, REST/SDK/CLI, and the _get_user_role_id error change are sibling issues BA-6255/6256/6257).

Test plan

  • pants fmt / fix / lint / check pass on changed files
  • Repository tests (test_ensure_user_system_roles.py, real DB via with_tables): create-when-missing grants role + permissions + mapping; idempotent reuse on repeated calls; batch with mixed existing/missing users; empty input is a no-op
  • CI: full type check + test suite

Resolves BA-6254

…ction

Add an idempotent operation that ensures each given user has a SYSTEM role
and user-role mapping: it creates the role with its permissions and the
mapping when missing, and reuses existing ones on repeat calls. Wires the
repository, service, action, and processor layers (USER scope, batch input).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 1, 2026 16:39
@fregataa fregataa requested a review from a team as a code owner June 1, 2026 16:39
@github-actions github-actions Bot added size:L 100~500 LoC comp:manager Related to Manager component labels Jun 1, 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 idempotent “ensure SYSTEM role” operation to the permission controller stack (repository → service → action → processor) for superadmin use, plus repository-level DB-backed tests and a changelog entry.

Changes:

  • Introduce ensure_user_system_roles(specs) in the permission controller repository/DB source and wire it through a new EnsureSystemRoleAction and processor/service entrypoint.
  • Add RoleMappingData DTO to represent ensured user→role mappings.
  • Add unit tests (real DB via with_tables) covering create-when-missing, idempotency, mixed batches, and empty input.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/manager/repositories/permission_controller/test_ensure_user_system_roles.py Adds repository-level tests for ensuring SYSTEM roles and mappings.
src/ai/backend/manager/services/permission_contoller/service.py Adds service method to execute the new ensure action via repository.
src/ai/backend/manager/services/permission_contoller/processors.py Registers the new action processor and declares it supported.
src/ai/backend/manager/services/permission_contoller/actions/ensure_system_role.py Introduces EnsureSystemRoleAction and result type.
src/ai/backend/manager/services/permission_contoller/actions/init.py Exposes the new action/result from the actions package.
src/ai/backend/manager/repositories/permission_controller/repository.py Adds repository method delegating to DB source.
src/ai/backend/manager/repositories/permission_controller/db_source/db_source.py Implements DB logic to ensure user SYSTEM roles + mappings.
src/ai/backend/manager/data/permission/user_role.py Adds RoleMappingData DTO used by the new operation.
changes/11891.feature.md Adds changelog entry for the new superadmin operation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +167 to +172
"""Ensure the SYSTEM role(s) for the given scope exist.

Idempotent: roles already present in the scope (matched by name) are
reused; missing ones are created together with their permissions. For
the USER scope, the user-to-role mapping is ensured as well.
"""
Comment on lines +123 to +127
"""
Ensure the SYSTEM role(s) for the given scope exist (idempotent).

Returns the ensured roles.
"""
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:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants