Skip to content

feat(BA-4877): add service/repository layer for bulk role assignment and revocation#9722

Merged
fregataa merged 2 commits intomainfrom
feat/BA-4877-bulk-role-assignment
Mar 6, 2026
Merged

feat(BA-4877): add service/repository layer for bulk role assignment and revocation#9722
fregataa merged 2 commits intomainfrom
feat/BA-4877-bulk-role-assignment

Conversation

@fregataa
Copy link
Member

@fregataa fregataa commented Mar 5, 2026

Summary

  • Add BulkAssignRoleAction with BulkCreator[UserRoleRow] for partial-failure bulk insert via savepoints
  • Add BulkRevokeRoleAction with per-user savepoint revocation loop
  • Add data types: BulkRoleAssignmentResultData, BulkRoleRevocationResultData with per-user failure details
  • Wire service methods, action processors, repository, and db_source layers

Test plan

  • Service-level unit tests for both bulk assign and revoke (all succeed, partial failure, all fail, empty list)
  • pants check/test

Resolves BA-4877 (service layer)

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 5, 2026 17:02
@fregataa fregataa self-assigned this Mar 5, 2026
@fregataa fregataa added this to the 26.3 milestone Mar 5, 2026
@fregataa fregataa marked this pull request as draft March 5, 2026 17:04
Copy link
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

…/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>
@fregataa fregataa force-pushed the feat/BA-4877-bulk-role-assignment branch from 99ec010 to c06646d Compare March 5, 2026 17:28
@fregataa fregataa requested a review from a team March 5, 2026 17:40
@github-actions github-actions bot added size:XL 500~ LoC comp:manager Related to Manager component labels Mar 5, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fregataa fregataa marked this pull request as ready for review March 5, 2026 18:00
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)))
Copy link
Member Author

@fregataa fregataa Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I planned to implement bulk purger partial function

@fregataa fregataa changed the title feat(BA-4877): add bulk role assignment and revocation mutations feat(BA-4877): add service/repository layer for bulk role assignment and revocation Mar 5, 2026
Comment on lines +57 to +58
role_id = uuid.uuid4()
user_ids = [uuid.uuid4(), uuid.uuid4(), uuid.uuid4()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to extract user_ids, role_id into fixtures.

@fregataa fregataa merged commit 5987602 into main Mar 6, 2026
24 checks passed
@fregataa fregataa deleted the feat/BA-4877-bulk-role-assignment branch March 6, 2026 04:09
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:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants