Conversation
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>
Contributor
There was a problem hiding this comment.
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_rolesStrawberry resolver that requires authentication and delegates tofetch_roleswith a user-scoped base condition - Adds
RoleConditions.by_assigned_user_id()to filter roles via auser_rolessubquery - 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.
src/ai/backend/manager/repositories/permission_controller/options.py
Outdated
Show resolved
Hide resolved
Co-authored-by: octodog <mu001@lablup.com>
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>
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
my_rolesGraphQL query that returns roles assigned to the current authenticated userRoleConditions.by_assigned_user_idto filter roles viauser_rolestable subqueryTest plan
my_rolesresolver (authenticated call, unauthenticated rejection, pagination params)RoleConditions.by_assigned_user_idconditionpants fmt,fix,lintpasspants check(mypy) passespants test --changed-since=HEAD~1passesResolves BA-4812
📚 Documentation preview 📚: https://sorna--9554.org.readthedocs.build/en/9554/
📚 Documentation preview 📚: https://sorna-ko--9554.org.readthedocs.build/ko/9554/