feat: Implemented team member assignments endpoint#248
feat: Implemented team member assignments endpoint#248rodmgwgu merged 11 commits intoopenedx:mainfrom
Conversation
|
Thanks for the pull request, @rodmgwgu! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
ef2d318 to
4b2b47c
Compare
There was a problem hiding this comment.
Pull request overview
Implements a new REST endpoint to list role assignments for a specific user (including a special-case “superadmin” entry) for use in the Admin Console.
Changes:
- Added
/api/authz/v1/users/<username>/assignmentsAPI view, serializers, ordering filter, and sorting utility. - Introduced
SuperAdminAssignmentDataand API helpers to surface Django staff/superuser status as an assignment entry. - Added unit tests for the new endpoint and
sort_assignments, and bumped version/changelog.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| openedx_authz/rest_api/v1/views.py | Adds TeamMemberAssignmentsAPIView that aggregates superadmin + visible role assignments, then sorts/paginates. |
| openedx_authz/rest_api/v1/urls.py | Registers the new user assignments route. |
| openedx_authz/rest_api/v1/serializers.py | Adds query-param serializer + response serializer for assignment entries. |
| openedx_authz/rest_api/v1/filters.py | Adds ordering backend for assignments. |
| openedx_authz/rest_api/utils.py | Adds sort_assignments helper. |
| openedx_authz/rest_api/data.py | Adds AssignmentSortField enum. |
| openedx_authz/api/users.py | Adds APIs to fetch visible assignments for a specific user + superadmin assignment generation. |
| openedx_authz/api/data.py | Adds SuperAdminAssignmentData data class. |
| openedx_authz/tests/rest_api/test_views.py | Adds endpoint-level test suite for user assignments endpoint. |
| openedx_authz/tests/rest_api/test_utils.py | Adds unit tests for sort_assignments invalid parameter handling. |
| openedx_authz/init.py | Version bump to 1.6.0. |
| CHANGELOG.rst | Changelog entry for the new endpoint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cf18189 to
f13a62a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Retrieve superadmin assignments (django staff or superuser users), as they always have access to everything | ||
| user_role_assignments += get_superadmin_assignments(user_external_keys=[username]) | ||
|
|
||
| user_role_assignments += get_visible_user_role_assignments_filtered_by_current_user( |
There was a problem hiding this comment.
Since get_superadmin_assignments filters by is_active=True, should we apply the same filter for non-staff/non-superusers?
There was a problem hiding this comment.
Good catch, fixed!, I also added a test for this.
mariajgrimaldi
left a comment
There was a problem hiding this comment.
LGTM after addressing Daniel's comment. Thanks a lot!
Description
Closes: #230
Implement the
/api/authz/v1/users/<username>/assignmentsendpoint to get a list of role assignations for a user, to be used in the admin console.Special case: superadmin users (Django staff or superuser) automatically have access to everything, so if we query for a superadmin user, we'll get an extra entry indicating the superadmin status.
Deadline: Verawood
How to test
Using a local dev tutor installation, call the following endpoint with required credentials:
http://local.openedx.io:8000/api/authz/v1/users/<username>/assignmentsThe user you use to test this should have permission to at least view one course or library.
You should see a response similar to this:
{ "count": 6, "next": null, "previous": null, "results": [ { "is_superadmin": false, "role": "course_admin", "org": "WGU", "scope": "course-v1:WGU+TC101+2026_01", "permission_count": 29 }, { "is_superadmin": false, "role": "course_staff", "org": "WGU", "scope": "course-v1:WGU+TC101+2026_01", "permission_count": 27 }, { "is_superadmin": true, "role": "django.superuser", "org": "*", "scope": "*", "permission_count": null }, { "is_superadmin": false, "role": "library_admin", "org": "WGU", "scope": "lib:WGU:CSPROB", "permission_count": 11 } ] }You can also test with params, for example:
http://local.openedx.io:8000/api/authz/v1/users/contributor/assignments?orgs=OpenedX,WGU&roles=library_contributor&sort_by=org&order=descMerge checklist:
Merge checklist:
Check off if complete or not applicable: