Skip to content

feat(BA-4812): add my_roles GraphQL query#9554

Open
fregataa wants to merge 9 commits intomainfrom
BA-4812
Open

feat(BA-4812): add my_roles GraphQL query#9554
fregataa wants to merge 9 commits intomainfrom
BA-4812

Conversation

@fregataa
Copy link
Member

@fregataa fregataa commented Mar 1, 2026

Summary

  • Add my_roles GraphQL query that returns roles assigned to the current authenticated user
  • Implement RoleConditions.by_assigned_user_id to filter roles via user_roles table subquery
  • No RBAC check required — users can always see their own roles
  • Support pagination (cursor-based and offset-based), filtering, and ordering

Test plan

  • Unit tests for my_roles resolver (authenticated call, unauthenticated rejection, pagination params)
  • Unit test for RoleConditions.by_assigned_user_id condition
  • pants fmt, fix, lint pass
  • pants check (mypy) passes
  • pants test --changed-since=HEAD~1 passes

Resolves BA-4812


📚 Documentation preview 📚: https://sorna--9554.org.readthedocs.build/en/9554/


📚 Documentation preview 📚: https://sorna-ko--9554.org.readthedocs.build/ko/9554/

Add a `my_roles` query that returns the roles assigned to the
current authenticated user. The query reuses the existing
`fetch_roles` fetcher with a `by_assigned_user_id` base condition
to scope results to the requesting user's role assignments.

- Add `RoleConditions.by_assigned_user_id` using a subquery on `user_roles`
- Add `my_roles` resolver (no RBAC check — users always see own roles)
- Register `my_roles` in the GraphQL schema
- Add unit tests for the resolver and condition

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 1, 2026 05:37
@github-actions github-actions bot added size:L 100~500 LoC comp:manager Related to Manager component labels Mar 1, 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

Adds a new my_roles GraphQL query to list roles assigned to the currently authenticated user, backed by a new RoleConditions.by_assigned_user_id repository filter and wired into the GraphQL schema/export surface.

Changes:

  • Introduces my_roles Strawberry resolver that requires authentication and delegates to fetch_roles with a user-scoped base condition
  • Adds RoleConditions.by_assigned_user_id() to filter roles via a user_roles subquery
  • Adds unit tests + Pants BUILD target and a changelog entry

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit/manager/api/gql/rbac/test_my_roles_resolver.py Adds unit tests for my_roles and the new condition helper
tests/unit/manager/api/gql/rbac/BUILD Adds Pants python_tests target for the new tests
src/ai/backend/manager/repositories/permission_controller/options.py Adds RoleConditions.by_assigned_user_id() query condition
src/ai/backend/manager/api/gql/schema.py Exposes my_roles on the root Query
src/ai/backend/manager/api/gql/rbac/resolver/role.py Implements the my_roles resolver
src/ai/backend/manager/api/gql/rbac/resolver/init.py Re-exports my_roles resolver
src/ai/backend/manager/api/gql/rbac/init.py Re-exports my_roles at package level
changes/9554.feature.md Adds changelog entry for the new query

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

Co-authored-by: octodog <mu001@lablup.com>
@github-actions github-actions bot added the area:docs Documentations label Mar 1, 2026
@fregataa fregataa marked this pull request as draft March 1, 2026 05:52
fregataa and others added 5 commits March 1, 2026 15:28
Replace aiohttp.web.HTTPUnauthorized with the project-standard
InsufficientPrivilege error for unauthenticated access to my_roles.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: octodog <mu001@lablup.com>
Replace fetch_roles (RoleConnection) with fetch_role_assignments
(RoleAssignmentConnection) so that role assignment metadata (granted_at,
granted_by) is included in the response.

- Add AssignedUserConditions.by_user_id() for filtering by user
- Remove unused RoleConditions.by_assigned_user_id()
- Update my_roles resolver to use RoleAssignmentFilter

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use uuid4() instead of hardcoded UUID fixtures
- Remove TestRoleConditionsByAssignedUserId (tested condition was removed)
- Update mocks to match new resolver signature (fetch_role_assignments)
- Assert InsufficientPrivilege instead of HTTPUnauthorized

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: octodog <mu001@lablup.com>
@fregataa fregataa requested a review from a team March 1, 2026 08:51
@fregataa fregataa added this to the 26.3 milestone Mar 1, 2026
@fregataa fregataa marked this pull request as ready for review March 1, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Documentations comp:manager Related to Manager component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants