feat(BA-4525): Unify ScopeType/EntityType to RBACElementType in permission controller#10335
Merged
jopemachine merged 6 commits intoMar 24, 2026
Merged
Conversation
fregataa
added a commit
that referenced
this pull request
Mar 19, 2026
Contributor
There was a problem hiding this comment.
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/EntityTypetoRBACElementTypefor 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.
fregataa
added a commit
that referenced
this pull request
Mar 23, 2026
c2ae10f to
8991fb7
Compare
jopemachine
previously approved these changes
Mar 24, 2026
seedspirit
previously approved these changes
Mar 24, 2026
Member
|
Please rebase the main branch, and resolve the conflict @fregataa |
…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>
72533e1 to
228c7a7
Compare
jopemachine
approved these changes
Mar 24, 2026
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>
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
ScopeTypeandEntityTypewith unifiedRBACElementTypeat interface boundaries in the permission controller repository, service, and their direct GQL/REST callersScopeIdcreation usingto_scope_type()/to_entity_type()methodsRBACElementTypehas no GLOBAL value)Test plan
pants lintpasses on changed filespants checkpasses (remaining errors are BA-4526 scope or pre-existing)pants testpasses for permission controller testsResolves BA-4525