feat: add assignments array to GET /api/authz/v1/users/ endpoint - #451
Conversation
|
Thanks for the pull request, @carlos-marquez-wgu! 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. |
Extend TeamMembersAPIView to return a nested assignments array per user, implementing ADR 0024 (API Contract for User-Grouped Role Assignments). Changes: - Add assignments_limit query parameter (default 3, max 10) to control the number of inline assignments per user - Add assignments array to the response with role, org, scope, scope_display_name, and permission_count per entry - Resolve scope_display_name from ContentLibrary.learning_package.title and CourseOverview.display_name via batched lookups - Rename assignation_count to assignment_count for consistency with the rest of the codebase - Add roles query parameter passthrough to the underlying API call - Add get_scope_display_name_map batch helper to api/utils.py - Add TeamMemberAssignmentInlineSerializer extending TeamMemberAssignmentSerializer with scope_display_name and without is_superadmin - Add tests for response shape, assignments_limit behavior, scope_display_name resolution (libraries, courses, missing resources, glob scopes)
dda0b39 to
594b992
Compare
|
Hi @openedx/committers-openedx-authz, this PR is ready for review |
rodmgwgu
left a comment
There was a problem hiding this comment.
Looking good overall, added some comments and things that should be reviewed. Thanks!
BryanttV
left a comment
There was a problem hiding this comment.
Thanks! I tested this on my local with some test data, and it works great. Just one comment from my side.
254a6ed to
45eeab0
Compare
- Change roles field to CommaSeparatedListField in ListTeamMembersSerializer - Use UserProfile.name instead of get_full_name() in TeamMemberSerializer and TeamMemberUserAssignmentSerializer for consistency - Resolve scope display names post-pagination to avoid unnecessary DB lookups - Fix RST formatting in CHANGELOG.rst (double backticks for inline code) - Add role assignment and assertGreater guard to course DB error test
45eeab0 to
734131a
Compare
BryanttV
left a comment
There was a problem hiding this comment.
Code looks great! Just a couple of suggestions.
BryanttV
left a comment
There was a problem hiding this comment.
Thanks for addressing my comments! LGTM
|
I just have one question if I filter by scope or organization a user with a glob permission should be returned, no? For example, I have Library User role for All libraries in the platform |
|
Thanks for pointing that out, @dcoa! Yes, according to the designs, a specific scope (for example, I think we can merge this PR and work on this part in another issue. What do you think, @rodmgwgu? |
Let's make sure we create the issue to keep track of that before merging please. |
rodmgwgu
left a comment
There was a problem hiding this comment.
Thanks for solving my concerns, LGTM!
Description
Extend TeamMembersAPIView to return a nested assignments array per user, implementing ADR 0024 (API Contract for User-Grouped Role Assignments).
Changes
Manual testing
Examples
GET /api/authz/v1/users/
Request
Response body
{ "count": 6, "next": null, "previous": null, "results": [ { "username": "carlos.marquez", "full_name": "", "email": "carlos.marquez@wgu.edu", "assignment_count": 8, "assignments": [ { "role": "library_admin", "org": "test", "scope": "lib:test:LIB101", "permission_count": 11, "scope_display_name": "Carlos Testing Library" }, { "role": "course_admin", "org": "test", "scope": "course-v1:test+CARLOS102+2026_2", "permission_count": 33, "scope_display_name": "Carlos Testing Course 2" }, { "role": "course_staff", "org": "test", "scope": "course-v1:test+CARLOS102+2026_2", "permission_count": 31, "scope_display_name": "Carlos Testing Course 2" } ] }, { "username": "test.user.course_editor", "full_name": "", "email": "course_editor@example.com", "assignment_count": 1, "assignments": [ { "role": "course_editor", "org": "CORG", "scope": "course-v1:CORG+CARLOS301+2026_2", "permission_count": 22, "scope_display_name": "Carlos Testing Course 3" } ] }, { "username": "test.user.courses.manage_library_updates", "full_name": "", "email": "courses.manage_library_updates@example.com", "assignment_count": 2, "assignments": [ { "role": "course_staff", "org": "test", "scope": "course-v1:test+CARLOS101+2026_2", "permission_count": 31, "scope_display_name": "Carlos Testing Course" }, { "role": "course_staff", "org": "CORG", "scope": "course-v1:CORG+CARLOS301+2026_2", "permission_count": 31, "scope_display_name": "Carlos Testing Course 3" } ] }, { "username": "test.user.many_assignments", "full_name": "", "email": "many_assignments@example.com", "assignment_count": 14, "assignments": [ { "role": "library_author", "org": "*", "scope": "lib:*", "permission_count": 9, "scope_display_name": "" }, { "role": "library_author", "org": "CORG", "scope": "lib:CORG:*", "permission_count": 9, "scope_display_name": "" }, { "role": "library_author", "org": "EORG", "scope": "lib:EORG:*", "permission_count": 9, "scope_display_name": "" } ] }, { "username": "test.user.master_editor", "full_name": "", "email": "master_editor@example.com", "assignment_count": 6, "assignments": [ { "role": "library_admin", "org": "*", "scope": "lib:*", "permission_count": 11, "scope_display_name": "" }, { "role": "library_admin", "org": "CORG", "scope": "lib:CORG:*", "permission_count": 11, "scope_display_name": "" }, { "role": "library_admin", "org": "EORG", "scope": "lib:EORG:*", "permission_count": 11, "scope_display_name": "" } ] }, { "username": "test.user.regular_editor", "full_name": "", "email": "regular_editor@example.com", "assignment_count": 1, "assignments": [ { "role": "library_user", "org": "test", "scope": "lib:test:LIB101", "permission_count": 3, "scope_display_name": "Carlos Testing Library" } ] } ] }GET /api/authz/v1/users/?search=test.user.many_assignments&assignments_limit=50
Request
Response body
{ "count": 1, "next": null, "previous": null, "results": [ { "username": "test.user.many_assignments", "full_name": "", "email": "many_assignments@example.com", "assignment_count": 14, "assignments": [ { "role": "library_author", "org": "*", "scope": "lib:*", "permission_count": 9, "scope_display_name": "" }, { "role": "library_author", "org": "CORG", "scope": "lib:CORG:*", "permission_count": 9, "scope_display_name": "" }, { "role": "library_author", "org": "EORG", "scope": "lib:EORG:*", "permission_count": 9, "scope_display_name": "" }, { "role": "library_author", "org": "REM", "scope": "lib:REM:*", "permission_count": 9, "scope_display_name": "" }, { "role": "library_author", "org": "test", "scope": "lib:test:*", "permission_count": 9, "scope_display_name": "" }, { "role": "library_author", "org": "test", "scope": "lib:test:LIB101", "permission_count": 9, "scope_display_name": "Carlos Testing Library" }, { "role": "course_staff", "org": "*", "scope": "course-v1:*", "permission_count": 31, "scope_display_name": "" }, { "role": "course_staff", "org": "CORG", "scope": "course-v1:CORG+*", "permission_count": 31, "scope_display_name": "" }, { "role": "course_staff", "org": "CORG", "scope": "course-v1:CORG+CARLOS301+2026_2", "permission_count": 31, "scope_display_name": "Carlos Testing Course 3" }, { "role": "course_staff", "org": "EORG", "scope": "course-v1:EORG+*", "permission_count": 31, "scope_display_name": "" } ] } ] }GET /api/authz/v1/users/?search=test.user&assignments_limit=2&roles=library_author&orgs=CORG,REM&sort_by=email&order=desc
Request
Response body
{ "count": 1, "next": null, "previous": null, "results": [ { "username": "test.user.many_assignments", "full_name": "", "email": "many_assignments@example.com", "assignment_count": 2, "assignments": [ { "role": "library_author", "org": "CORG", "scope": "lib:CORG:*", "permission_count": 9, "scope_display_name": "" }, { "role": "library_author", "org": "REM", "scope": "lib:REM:*", "permission_count": 9, "scope_display_name": "" } ] } ] }Merge checklist:
AI Usage
Kiro + Claude were used to assist with the creation of the tests and code implementations while throughly and carefully guided, everything was reviewed and corrected manually by an actual person and ensured the changes were up to standard and met the closing issue requirements.
Closes #406