feat(BA-4877): add service/repository layer for bulk role assignment and revocation#9722
Merged
feat(BA-4877): add service/repository layer for bulk role assignment and revocation#9722
Conversation
…/revocation - Data types: BulkUserRoleAssignmentInput, BulkRoleAssignmentResultData, BulkUserRoleRevocationInput, BulkRoleRevocationResultData - BulkAssignRoleAction / BulkRevokeRoleAction with ActionResults - Service methods: bulk_assign_role, bulk_revoke_role - Repository: bulk_assign_role using BulkCreator, bulk_revoke_role with per-user savepoint - DB Source: execute_bulk_creator_partial for assign, savepoint loop for revoke - Processor wiring - Unit tests for service layer Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
99ec010 to
c06646d
Compare
2 tasks
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fregataa
commented
Mar 5, 2026
Comment on lines
+1002
to
+1039
| async def bulk_revoke_role( | ||
| self, data: BulkUserRoleRevocationInput | ||
| ) -> BulkRoleRevocationResultData: | ||
| successes: list[UserRoleRevocationData] = [] | ||
| failures: list[BulkRoleRevocationFailure] = [] | ||
|
|
||
| async with self._db.begin_session() as db_session: | ||
| for user_id in data.user_ids: | ||
| try: | ||
| async with db_session.begin_nested(): | ||
| stmt = ( | ||
| sa.select(UserRoleRow) | ||
| .where(UserRoleRow.user_id == user_id) | ||
| .where(UserRoleRow.role_id == data.role_id) | ||
| ) | ||
| user_role_row = await db_session.scalar(stmt) | ||
| if user_role_row is None: | ||
| raise RoleNotAssigned( | ||
| f"Role {data.role_id} is not assigned to user {user_id}." | ||
| ) | ||
| user_role_id = user_role_row.id | ||
| await db_session.delete(user_role_row) | ||
| await db_session.flush() | ||
| successes.append( | ||
| UserRoleRevocationData( | ||
| user_role_id=user_role_id, | ||
| user_id=user_id, | ||
| role_id=data.role_id, | ||
| ) | ||
| ) | ||
| except Exception as e: | ||
| log.warning( | ||
| "Failed to revoke role {} from user {}: {}", | ||
| data.role_id, | ||
| user_id, | ||
| str(e), | ||
| ) | ||
| failures.append(BulkRoleRevocationFailure(user_id=user_id, message=str(e))) |
Member
Author
There was a problem hiding this comment.
I planned to implement bulk purger partial function
jopemachine
reviewed
Mar 6, 2026
Comment on lines
+57
to
+58
| role_id = uuid.uuid4() | ||
| user_ids = [uuid.uuid4(), uuid.uuid4(), uuid.uuid4()] |
Member
There was a problem hiding this comment.
It would be better to extract user_ids, role_id into fixtures.
jopemachine
approved these changes
Mar 6, 2026
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
BulkAssignRoleActionwithBulkCreator[UserRoleRow]for partial-failure bulk insert via savepointsBulkRevokeRoleActionwith per-user savepoint revocation loopBulkRoleAssignmentResultData,BulkRoleRevocationResultDatawith per-user failure detailsTest plan
Resolves BA-4877 (service layer)
🤖 Generated with Claude Code