Skip to content

feat(BA-4525): Unify ScopeType/EntityType to RBACElementType in permission controller#10335

Merged
jopemachine merged 6 commits into
mainfrom
feat/BA-4525-rbac-permission-controller-unified-enum
Mar 24, 2026
Merged

feat(BA-4525): Unify ScopeType/EntityType to RBACElementType in permission controller#10335
jopemachine merged 6 commits into
mainfrom
feat/BA-4525-rbac-permission-controller-unified-enum

Conversation

@fregataa
Copy link
Copy Markdown
Member

@fregataa fregataa commented Mar 19, 2026

Summary

  • Replace ScopeType and EntityType with unified RBACElementType at interface boundaries in the permission controller repository, service, and their direct GQL/REST callers
  • Legacy types are bridged at DB row construction and ScopeId creation using to_scope_type() / to_entity_type() methods
  • Move GLOBAL scope handling from repository to REST handler as an early-return (since RBACElementType has no GLOBAL value)

Test plan

  • pants lint passes on changed files
  • pants check passes (remaining errors are BA-4526 scope or pre-existing)
  • pants test passes for permission controller tests

Resolves BA-4525

Copilot AI review requested due to automatic review settings March 19, 2026 17:01
@github-actions github-actions Bot added size:L 100~500 LoC comp:manager Related to Manager component labels Mar 19, 2026
fregataa added a commit that referenced this pull request Mar 19, 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

This PR aims to standardize RBAC “type” handling by replacing legacy ScopeType/EntityType at permission-controller boundaries with a unified RBACElementType, while bridging back to legacy enums at DB row construction and ID creation.

Changes:

  • Switch permission-controller service/actions/repository APIs from ScopeType/EntityType to RBACElementType for scope/entity selection.
  • Add bridging conversions (to_scope_type() / to_entity_type()) in creators/updaters/options and update GQL/REST adapters accordingly.
  • Move GLOBAL scope search behavior out of repository and into the REST handler via an early return.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
src/ai/backend/manager/services/permission_contoller/service.py Returns unified RBACElementType lists and passes element types to repository.
src/ai/backend/manager/services/permission_contoller/actions/search_scopes.py Renames action input from scope_type to element_type.
src/ai/backend/manager/services/permission_contoller/actions/get_scope_types.py Changes action result payload to element_types: list[RBACElementType].
src/ai/backend/manager/services/permission_contoller/actions/get_entity_types.py Changes action result payload to element_types: list[RBACElementType].
src/ai/backend/manager/repositories/permission_controller/updaters.py Maps RBACElementType back to legacy enums when updating DB rows.
src/ai/backend/manager/repositories/permission_controller/role_manager.py Updates system-role permission creation flow to use RBACElementType keys.
src/ai/backend/manager/repositories/permission_controller/repository.py Updates search_scopes() to match on RBACElementType and removes GLOBAL handling from it.
src/ai/backend/manager/repositories/permission_controller/options.py Converts query conditions to accept RBACElementType and bridge to legacy enums for DB filtering.
src/ai/backend/manager/repositories/permission_controller/db_source/db_source.py Bridges role-permission updates by converting incoming legacy types to RBACElementType.
src/ai/backend/manager/repositories/permission_controller/creators.py Changes creator specs to accept RBACElementType and bridge to legacy enums when building ORM rows.
src/ai/backend/manager/repositories/base/rbac/revoker.py Changes revoker scope-type field to RBACElementType and converts to legacy for DB delete.
src/ai/backend/manager/repositories/base/rbac/granter.py Changes granter scope-type field to RBACElementType and converts to legacy for DB insert.
src/ai/backend/manager/api/rest/rbac/permission_adapter.py Converts REST request legacy enums to RBACElementType for create-permission actions.
src/ai/backend/manager/api/rest/rbac/object_permission_adapter.py Converts REST request legacy EntityType to RBACElementType for object-permission actions.
src/ai/backend/manager/api/rest/rbac/handler.py Adds GLOBAL early-return for scope search and converts element-types back to legacy DTO enums.
src/ai/backend/manager/api/rest/rbac/entity_adapter.py Switches entity search querier builder to RBACElementType.
src/ai/backend/manager/api/gql/rbac/types/permission.py Uses element types in conditions/creator/updater wiring.
src/ai/backend/manager/api/gql/rbac/types/entity.py Uses element types in entity-scope filtering.
Comments suppressed due to low confidence (1)

src/ai/backend/manager/repositories/permission_controller/repository.py:310

  • PermissionControllerRepository.get_global_scope() appears unused now (verified no call sites after GLOBAL handling moved to the REST handler). Consider removing it to avoid dead code, or routing the handler’s static GLOBAL response through this helper to avoid duplication.
    def get_global_scope(self) -> ScopeListResult:
        """Get the global scope as a static result."""
        return ScopeListResult(
            items=[
                ScopeData(

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

Comment thread src/ai/backend/manager/api/rest/rbac/handler.py
Comment thread src/ai/backend/manager/api/rest/rbac/handler.py Outdated
Comment thread src/ai/backend/manager/repositories/base/rbac/granter.py
Comment thread src/ai/backend/manager/repositories/base/rbac/revoker.py
Comment thread src/ai/backend/manager/api/rest/rbac/handler.py
Comment thread src/ai/backend/manager/api/rest/rbac/permission_adapter.py
Comment thread src/ai/backend/manager/api/rest/rbac/object_permission_adapter.py
Comment thread src/ai/backend/manager/api/rest/rbac/handler.py Outdated
Comment thread src/ai/backend/manager/api/rest/rbac/handler.py Outdated
@fregataa fregataa added this to the 26.4 milestone Mar 19, 2026
@fregataa fregataa requested review from a team and removed request for a team March 19, 2026 17:14
@fregataa fregataa marked this pull request as draft March 19, 2026 17:15
fregataa added a commit that referenced this pull request Mar 23, 2026
@fregataa fregataa force-pushed the feat/BA-4525-rbac-permission-controller-unified-enum branch from c2ae10f to 8991fb7 Compare March 23, 2026 17:24
@fregataa fregataa marked this pull request as ready for review March 23, 2026 17:35
@fregataa fregataa requested a review from a team March 23, 2026 17:38
@fregataa fregataa marked this pull request as draft March 23, 2026 17:54
@fregataa fregataa removed the request for review from a team March 23, 2026 17:54
@fregataa fregataa marked this pull request as ready for review March 23, 2026 18:44
@fregataa fregataa requested a review from a team March 23, 2026 18:44
jopemachine
jopemachine previously approved these changes Mar 24, 2026
seedspirit
seedspirit previously approved these changes Mar 24, 2026
@jopemachine
Copy link
Copy Markdown
Member

jopemachine commented Mar 24, 2026

Please rebase the main branch, and resolve the conflict @fregataa

fregataa and others added 6 commits March 24, 2026 12:38
…ssion controller

Replace ScopeType and EntityType with RBACElementType at interface boundaries
in the permission controller repository, service, and their direct GQL/REST
callers. Legacy types are bridged at DB row construction and ScopeId creation.

Repository layer:
- creators.py, updaters.py, options.py: Accept RBACElementType, bridge internally
- repository.py: search_scopes() takes RBACElementType, GLOBAL moved to handler
- db_source.py, role_manager.py: Bridge at PermissionCreatorSpec call sites
- granter.py, revoker.py: Accept RBACElementType for scope type fields

Service layer:
- get_scope_types/get_entity_types: Return list[RBACElementType]
- search_scopes: Accept RBACElementType instead of ScopeType

GQL/REST layers:
- Simplify double-conversion (.to_element().to_scope_type()) to .to_element()
- Add GLOBAL scope early-return in REST handler

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ndler

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace ScopeType/EntityType with RBACElementType at all call sites
where permission controller interfaces now expect the unified enum.
Update test files to use RBACElementType for scope and entity type
parameters, and remove unused GLOBAL scope references from tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rch_scopes

Remove GLOBAL scope early-return from handler (scope_type.to_element()
now raises RBACTypeConversionError naturally), remove GLOBAL branch from
ScopeAdapter, remove get_global_scope() from repository, and delete the
corresponding test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Change GLOBAL scope adapter test to verify NotImplementedError is raised
- Fix search_scopes handler test to assert on element_type instead of scope_type

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fregataa fregataa dismissed stale reviews from seedspirit and jopemachine via 228c7a7 March 24, 2026 03:40
@fregataa fregataa force-pushed the feat/BA-4525-rbac-permission-controller-unified-enum branch from 72533e1 to 228c7a7 Compare March 24, 2026 03:40
@jopemachine jopemachine merged commit 1d1121c into main Mar 24, 2026
33 checks passed
@jopemachine jopemachine deleted the feat/BA-4525-rbac-permission-controller-unified-enum branch March 24, 2026 04:03
jopemachine pushed a commit that referenced this pull request Mar 24, 2026
…ssion controller (#10335)

Co-authored-by: Claude Opus 4.6 <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:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants