Skip to content

feat(BA-5077): apply RBAC Creator pattern to UserFairShare#10023

Draft
fregataa wants to merge 8 commits intomainfrom
BA-5077
Draft

feat(BA-5077): apply RBAC Creator pattern to UserFairShare#10023
fregataa wants to merge 8 commits intomainfrom
BA-5077

Conversation

@fregataa
Copy link
Member

Summary

  • Added USER_FAIR_SHARE to RBACElementType enum as a new element type
  • Registered USER_FAIR_SHARE under RESOURCE_GROUP in scope-entity combinations
  • Updated FairShareDBSource.create_user_fair_share() to use RBACEntityCreator and execute_rbac_entity_creator()
  • Updated FairShareRepository.create_user_fair_share() to accept RBACEntityCreator parameter

Test plan

  • pants fmt - no changes needed
  • pants fix - no changes needed
  • pants lint --changed-since=origin/main - all checks passed
  • Verified correct import paths for RBAC entity creator components

Resolves BA-5077

fregataa and others added 5 commits March 13, 2026 02:44
Add USER_FAIR_SHARE element type to the RBAC system as part of applying
the RBAC Creator pattern to UserFairShare auto sub-entity.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…binations

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Change `FairShareDBSource.create_user_fair_share()` parameter type from `Creator[UserFairShareRow]` to `RBACEntityCreator[UserFairShareRow]`
- Replace `execute_creator()` with `execute_rbac_entity_creator()`
- Add imports for `RBACEntityCreator`, `execute_rbac_entity_creator`, `RBACElementRef`, and `RBACElementType`

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updated FairShareRepository.create_user_fair_share() to accept
RBACEntityCreator[UserFairShareRow] instead of Creator[UserFairShareRow].
Added RBACEntityCreator import to repository module.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed import paths for RBACEntityCreator and execute_rbac_entity_creator
to use the correct module path:
ai.backend.manager.repositories.base.rbac.entity_creator

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 12, 2026 17:56
@github-actions github-actions bot added size:S 10~30 LoC comp:manager Related to Manager component comp:common Related to Common component labels Mar 12, 2026
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.

Pull request overview

Applies the RBAC “Creator” workflow to UserFairShare creation and wires the new entity type into the permissions model.

Changes:

  • Introduces USER_FAIR_SHARE as a new RBACElementType and registers it under RESOURCE_GROUP scope/entity combinations.
  • Migrates create_user_fair_share() in the DB source to use RBACEntityCreator + execute_rbac_entity_creator().
  • Updates FairShareRepository.create_user_fair_share() to accept an RBACEntityCreator-typed creator.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/ai/backend/manager/repositories/fair_share/repository.py Updates repository API type signature to accept RBACEntityCreator for user fair share creation.
src/ai/backend/manager/repositories/fair_share/db_source/db_source.py Switches execution path to execute_rbac_entity_creator() for user fair share creation.
src/ai/backend/common/data/permission/types.py Adds USER_FAIR_SHARE element type to RBAC enum.
src/ai/backend/common/data/permission/scope_entity_combinations.py Registers USER_FAIR_SHARE as an entity under RESOURCE_GROUP.
changes/10023.enhance.md Adds a changelog entry for the RBAC Creator migration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

async def create_user_fair_share(
self,
creator: Creator[UserFairShareRow],
creator: RBACEntityCreator[UserFairShareRow],
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

This changes the repository method’s public type signature from Creator[...] to RBACEntityCreator[...], which is a (type-level) breaking change for callers that still pass a Creator. If backward compatibility is desired, consider widening the accepted type (e.g., a shared Protocol / Union) or providing a small adapter so existing Creator instances can still be used where RBAC registration isn’t needed.

Copilot uses AI. Check for mistakes.
Comment on lines +514 to 515
result = await execute_rbac_entity_creator(db_sess, creator)
sg_row = await self._fetch_scaling_group_row(db_sess, result.row.resource_group)
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

After switching to execute_rbac_entity_creator(), this code still assumes the returned object has the same shape as execute_creator() (notably result.row). To make this contract explicit and prevent future refactors from silently breaking this call site, add an explicit type annotation for result (or otherwise assert the expected interface) so type-checking can enforce that .row is present.

Copilot uses AI. Check for mistakes.
…Creator

Add USER_FAIR_SHARE to RBACElementTypeGQL enum to stay in sync with
RBACElementType. Update test_scope_entity_combinations expected set and
migrate test Creator calls to RBACEntityCreator for user fair share.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added size:M 30~100 LoC and removed size:S 10~30 LoC labels Mar 12, 2026
Co-authored-by: octodog <mu001@lablup.com>
@github-actions github-actions bot added the area:docs Documentations label Mar 12, 2026
@fregataa fregataa marked this pull request as draft March 12, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Documentations comp:common Related to Common component comp:manager Related to Manager component size:M 30~100 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants