-
Notifications
You must be signed in to change notification settings - Fork 176
feat(BA-6177): role preset repository, service, and processor layers #11846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HyeockJinKim
merged 11 commits into
main
from
feat/BA-6177-role-preset-repository-service
Jun 2, 2026
+1,438
−0
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a7e1148
feat(BA-6177): add role preset repository, service, and processor layers
fregataa 5825083
changelog: add news fragment for PR #11846
fregataa 6ce78c6
fix(BA-6177): use snake_case for RolePresetNotFound.object_name
fregataa d9f7f4c
refactor(BA-6177): id-based get/purge, wrap results, partial bulk purge
fregataa 75e20a6
refactor(BA-6177): return counts from bulk update/remove operations
fregataa b473dec
test(BA-6177): add role preset repository tests; use bare creator_spec
fregataa 6a42873
refactor(BA-6177): bulk soft-delete/restore via partial updater; batc…
fregataa c482553
refactor(BA-6177): unify bulk operation returns to records + failures
fregataa 6128925
refactor(BA-6177): pass-through bulk_purge result; spec-driven soft d…
fregataa cda9245
refactor(BA-6177): make CreateRolePresetAction a scope action
fregataa f51fb35
refactor(BA-6177): separate role permission preset action hierarchy
fregataa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add role preset repository, service, and processor layers covering CRUD, soft-delete with restore, purge, and bulk add/remove of `role_permission_preset` entries. |
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass, field | ||
| from datetime import datetime | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from ai.backend.common.data.permission.types import ( | ||
| EntityType, | ||
| OperationType, | ||
| RBACElementType, | ||
| ) | ||
| from ai.backend.common.identifier.role_permission_preset import RolePermissionPresetID | ||
| from ai.backend.common.identifier.role_preset import RolePresetID | ||
| from ai.backend.manager.repositories.base.creator import BulkCreatorError | ||
| from ai.backend.manager.repositories.base.purger import BulkPurgerError | ||
| from ai.backend.manager.repositories.base.updater import BulkUpdaterError | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ai.backend.manager.models.rbac_models.role_permission_preset.row import ( | ||
| RolePermissionPresetRow, | ||
| ) | ||
| from ai.backend.manager.models.rbac_models.role_preset.row import RolePresetRow | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class RolePermissionPresetData: | ||
| id: RolePermissionPresetID | ||
| role_preset_id: RolePresetID | ||
| entity_type: EntityType | ||
| operation: OperationType | ||
| created_at: datetime | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class RolePresetData: | ||
| id: RolePresetID | ||
| name: str | ||
| scope_type: RBACElementType | ||
| auto_assign: bool | ||
| deleted: bool | ||
| created_at: datetime | ||
| updated_at: datetime | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class RolePresetSearchResult: | ||
| items: list[RolePresetData] | ||
| total_count: int | ||
| has_next_page: bool | ||
| has_previous_page: bool | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class RolePresetBulkPurgeResult: | ||
| successes: list[RolePresetData] = field(default_factory=list) | ||
| failures: list[BulkPurgerError[RolePresetRow]] = field(default_factory=list) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class RolePresetBulkUpdateResult: | ||
| successes: list[RolePresetData] = field(default_factory=list) | ||
| failures: list[BulkUpdaterError[RolePresetRow]] = field(default_factory=list) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class RolePermissionPresetBulkAddResult: | ||
| successes: list[RolePermissionPresetData] = field(default_factory=list) | ||
| failures: list[BulkCreatorError[RolePermissionPresetRow]] = field(default_factory=list) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class RolePermissionPresetBulkRemoveResult: | ||
| successes: list[RolePermissionPresetData] = field(default_factory=list) | ||
| failures: list[BulkPurgerError[RolePermissionPresetRow]] = field(default_factory=list) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """Role preset domain exceptions.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from aiohttp import web | ||
|
|
||
| from ai.backend.common.exception import ( | ||
| BackendAIError, | ||
| ErrorCode, | ||
| ErrorDetail, | ||
| ErrorDomain, | ||
| ErrorOperation, | ||
| ) | ||
|
|
||
| from .common import ObjectNotFound | ||
|
|
||
|
|
||
| class RolePresetNotFound(ObjectNotFound): | ||
| object_name = "role_preset" | ||
|
|
||
| def error_code(self) -> ErrorCode: | ||
| return ErrorCode( | ||
| domain=ErrorDomain.ROLE, | ||
| operation=ErrorOperation.READ, | ||
| error_detail=ErrorDetail.NOT_FOUND, | ||
| ) | ||
|
|
||
|
|
||
| class RolePermissionPresetConflict(BackendAIError, web.HTTPConflict): | ||
| error_type = "https://api.backend.ai/probs/duplicate-role-permission-preset" | ||
| error_title = "Duplicate role permission preset entry." | ||
|
|
||
| def error_code(self) -> ErrorCode: | ||
| return ErrorCode( | ||
| domain=ErrorDomain.ROLE, | ||
| operation=ErrorOperation.CREATE, | ||
| error_detail=ErrorDetail.CONFLICT, | ||
| ) |
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
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
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
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
Empty file.
93 changes: 93 additions & 0 deletions
93
src/ai/backend/manager/repositories/role_preset/creators.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Sequence | ||
| from dataclasses import dataclass | ||
| from typing import override | ||
|
|
||
| from ai.backend.common.data.permission.types import ( | ||
| EntityType, | ||
| OperationType, | ||
| ScopeType, | ||
| ) | ||
| from ai.backend.common.identifier.role_preset import RolePresetID | ||
| from ai.backend.manager.errors.repository import UniqueConstraintViolationError | ||
| from ai.backend.manager.errors.role_preset import RolePermissionPresetConflict | ||
| from ai.backend.manager.models.rbac_models.role_permission_preset.row import ( | ||
| RolePermissionPresetRow, | ||
| ) | ||
| from ai.backend.manager.models.rbac_models.role_preset.row import RolePresetRow | ||
| from ai.backend.manager.repositories.base.creator import ( | ||
| CreatorSpec, | ||
| DependentCreatorSpec, | ||
| ) | ||
| from ai.backend.manager.repositories.base.types import IntegrityErrorCheck | ||
|
|
||
|
|
||
| @dataclass | ||
| class RolePresetCreatorSpec(CreatorSpec[RolePresetRow]): | ||
| name: str | ||
| scope_type: ScopeType | ||
| auto_assign: bool = False | ||
|
|
||
| @override | ||
| def build_row(self) -> RolePresetRow: | ||
| return RolePresetRow( | ||
| name=self.name, | ||
| scope_type=self.scope_type, | ||
| auto_assign=self.auto_assign, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class RolePermissionPresetDependentCreatorSpec( | ||
|
fregataa marked this conversation as resolved.
|
||
| DependentCreatorSpec[RolePresetID, RolePermissionPresetRow] | ||
| ): | ||
| entity_type: EntityType | ||
| operation: OperationType | ||
|
|
||
| @override | ||
| def build_row(self, dependency: RolePresetID) -> RolePermissionPresetRow: | ||
| return RolePermissionPresetRow( | ||
| role_preset_id=dependency, | ||
| entity_type=self.entity_type, | ||
| operation=self.operation, | ||
| ) | ||
|
|
||
| @property | ||
| @override | ||
| def integrity_error_checks(self) -> Sequence[IntegrityErrorCheck]: | ||
| return ( | ||
| IntegrityErrorCheck( | ||
| violation_type=UniqueConstraintViolationError, | ||
| error=RolePermissionPresetConflict( | ||
| f"Duplicate permission entry ({self.entity_type}, {self.operation})." | ||
| ), | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class RolePermissionPresetCreatorSpec(CreatorSpec[RolePermissionPresetRow]): | ||
| role_preset_id: RolePresetID | ||
| entity_type: EntityType | ||
| operation: OperationType | ||
|
|
||
| @override | ||
| def build_row(self) -> RolePermissionPresetRow: | ||
| return RolePermissionPresetRow( | ||
| role_preset_id=self.role_preset_id, | ||
| entity_type=self.entity_type, | ||
| operation=self.operation, | ||
| ) | ||
|
|
||
| @property | ||
| @override | ||
| def integrity_error_checks(self) -> Sequence[IntegrityErrorCheck]: | ||
| return ( | ||
| IntegrityErrorCheck( | ||
| violation_type=UniqueConstraintViolationError, | ||
| error=RolePermissionPresetConflict( | ||
| f"Duplicate permission entry ({self.entity_type}, {self.operation})." | ||
| ), | ||
| ), | ||
| ) | ||
Empty file.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.