-
Notifications
You must be signed in to change notification settings - Fork 173
feat(BA-5906): bulk add/remove/replace role permissions repository #11422
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
Open
fregataa
wants to merge
7
commits into
main
Choose a base branch
from
fix/BA-5906-bulk-role-permissions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ea82621
feat(BA-5906): bulk add/remove/replace role permissions repository, s…
fregataa aaa316b
changelog: add news fragment for PR #11422
fregataa 59d14f3
refactor(BA-5906): use read-committed isolation for bulk role-permiss…
fregataa dbaf827
refactor(BA-5906): introduce BulkRolePermission Data/Failure types
fregataa aba8460
refactor(BA-5906): trim bulk role-permission docstrings and inline fa…
fregataa 500ada3
changelog: trim PR #11422 news fragment
fregataa e5bc33f
refactor(BA-5906): set bulk role-permission action entity_type to ROLE
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 bulk add/remove/replace operations for role permissions at the repository, service, and action layers. |
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
49 changes: 49 additions & 0 deletions
49
src/ai/backend/manager/services/permission_contoller/actions/bulk_add_role_permissions.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,49 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import override | ||
|
|
||
| from ai.backend.common.data.permission.types import EntityType | ||
| from ai.backend.manager.actions.action import BaseAction, BaseActionResult | ||
| from ai.backend.manager.actions.types import ActionOperationType | ||
| from ai.backend.manager.data.permission.role import BulkRolePermissionAddResultData | ||
| from ai.backend.manager.models.rbac_models.permission.permission import PermissionRow | ||
| from ai.backend.manager.repositories.base.creator import BulkCreator | ||
| from ai.backend.manager.repositories.permission_controller.creators import ( | ||
| PermissionCreatorSpec, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class BulkAddRolePermissionsAction(BaseAction): | ||
| creator: BulkCreator[PermissionRow] | ||
|
|
||
| @override | ||
| def entity_id(self) -> str | None: | ||
| for spec in self.creator.specs: | ||
| if isinstance(spec, PermissionCreatorSpec): | ||
| return str(spec.role_id) | ||
| return None | ||
|
|
||
| @override | ||
| @classmethod | ||
| def entity_type(cls) -> EntityType: | ||
| return EntityType.ROLE | ||
|
|
||
| @override | ||
| @classmethod | ||
| def operation_type(cls) -> ActionOperationType: | ||
| return ActionOperationType.UPDATE | ||
|
fregataa marked this conversation as resolved.
|
||
|
|
||
|
|
||
| @dataclass | ||
| class BulkAddRolePermissionsActionResult(BaseActionResult): | ||
| data: BulkRolePermissionAddResultData | ||
|
|
||
| @override | ||
| def entity_id(self) -> str | None: | ||
| for row in self.data.successes: | ||
| return str(row.role_id) | ||
| for failure in self.data.failures: | ||
| return str(failure.role_id) | ||
| return None | ||
|
fregataa marked this conversation as resolved.
|
||
41 changes: 41 additions & 0 deletions
41
src/ai/backend/manager/services/permission_contoller/actions/bulk_remove_role_permissions.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,41 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import override | ||
|
|
||
| from ai.backend.common.data.permission.types import EntityType | ||
| from ai.backend.manager.actions.action import BaseAction, BaseActionResult | ||
| from ai.backend.manager.actions.types import ActionOperationType | ||
| from ai.backend.manager.data.permission.role import BulkRolePermissionRemoveResultData | ||
| from ai.backend.manager.models.rbac_models.permission.permission import PermissionRow | ||
| from ai.backend.manager.repositories.base.purger import Purger | ||
|
|
||
|
|
||
| @dataclass | ||
| class BulkRemoveRolePermissionsAction(BaseAction): | ||
| purgers: list[Purger[PermissionRow]] | ||
|
|
||
| @override | ||
| def entity_id(self) -> str | None: | ||
| return None | ||
|
|
||
| @override | ||
| @classmethod | ||
| def entity_type(cls) -> EntityType: | ||
| return EntityType.ROLE | ||
|
|
||
| @override | ||
| @classmethod | ||
| def operation_type(cls) -> ActionOperationType: | ||
| return ActionOperationType.UPDATE | ||
|
fregataa marked this conversation as resolved.
|
||
|
|
||
|
|
||
| @dataclass | ||
| class BulkRemoveRolePermissionsActionResult(BaseActionResult): | ||
| data: BulkRolePermissionRemoveResultData | ||
|
|
||
| @override | ||
| def entity_id(self) -> str | None: | ||
| for row in self.data.successes: | ||
| return str(row.role_id) | ||
| return None | ||
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.