Skip to content

feat: add assignments array to GET /api/authz/v1/users/ endpoint - #451

Merged
rodmgwgu merged 3 commits into
openedx:mainfrom
WGU-Open-edX:carlos-marquez-wgu/issue-406-implement-per-user-aggregation-logic
Sep 18, 2026
Merged

rodmgwgu merged 3 commits into
openedx:mainfrom
WGU-Open-edX:carlos-marquez-wgu/issue-406-implement-per-user-aggregation-logic

Conversation

@carlos-marquez-wgu

@carlos-marquez-wgu carlos-marquez-wgu commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Description

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)

Manual testing

  1. Assign different roles to users if you don't have any
  2. Hit the following endpoint with an authenticated user:
/api/authz/v1/users/

Examples

GET /api/authz/v1/users/

Request

GET /api/authz/v1/users/

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

GET /api/authz/v1/users/?search=test.user.many_assignments&assignments_limit=50

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

GET /api/authz/v1/users/?search=test.user&assignments_limit=2&roles=library_author&orgs=CORG,REM&sort_by=email&order=desc

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:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

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

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 14, 2026
@openedx-webhooks

openedx-webhooks commented Sep 14, 2026

Copy link
Copy Markdown

Thanks for the pull request, @carlos-marquez-wgu!

This repository is currently maintained by @openedx/committers-openedx-authz.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 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)
@carlos-marquez-wgu
carlos-marquez-wgu force-pushed the carlos-marquez-wgu/issue-406-implement-per-user-aggregation-logic branch from dda0b39 to 594b992 Compare September 14, 2026 18:14
@carlos-marquez-wgu
carlos-marquez-wgu marked this pull request as ready for review September 14, 2026 18:27
@carlos-marquez-wgu

Copy link
Copy Markdown
Contributor Author

Hi @openedx/committers-openedx-authz, this PR is ready for review

@rodmgwgu rodmgwgu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good overall, added some comments and things that should be reviewed. Thanks!

Comment thread openedx_authz/rest_api/v1/serializers.py Outdated
Comment thread CHANGELOG.rst Outdated
Comment thread openedx_authz/rest_api/v1/views.py Outdated

@BryanttV BryanttV left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! I tested this on my local with some test data, and it works great. Just one comment from my side.

Comment thread openedx_authz/rest_api/v1/serializers.py
Comment thread openedx_authz/tests/rest_api/test_views.py
Comment thread CHANGELOG.rst Outdated
@carlos-marquez-wgu
carlos-marquez-wgu force-pushed the carlos-marquez-wgu/issue-406-implement-per-user-aggregation-logic branch from 254a6ed to 45eeab0 Compare September 15, 2026 23:36
- 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
@carlos-marquez-wgu
carlos-marquez-wgu force-pushed the carlos-marquez-wgu/issue-406-implement-per-user-aggregation-logic branch from 45eeab0 to 734131a Compare September 15, 2026 23:51

@BryanttV BryanttV left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks great! Just a couple of suggestions.

Comment thread openedx_authz/rest_api/v1/views.py Outdated
Comment thread openedx_authz/rest_api/v1/views.py Outdated
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Sep 17, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to In Eng Review in Contributions Sep 17, 2026

@BryanttV BryanttV left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing my comments! LGTM

@dcoa

dcoa commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

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 lib:*, if I apply the filter for an specific library lib:demo:test I am not in the list, but I have access to that library.

@BryanttV

Copy link
Copy Markdown
Contributor

Thanks for pointing that out, @dcoa! Yes, according to the designs, a specific scope (for example, course-v1:OpenedX+DemoX+DemoCourse) also applies to an organization-level scope (course-v1:OpenedX+*) and to the platform level (course-v1:*); therefore, they should be returned in the response.

I think we can merge this PR and work on this part in another issue. What do you think, @rodmgwgu?

@rodmgwgu

Copy link
Copy Markdown
Contributor

Thanks for pointing that out, @dcoa! Yes, according to the designs, a specific scope (for example, course-v1:OpenedX+DemoX+DemoCourse) also applies to an organization-level scope (course-v1:OpenedX+*) and to the platform level (course-v1:*); therefore, they should be returned in the response.

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 rodmgwgu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for solving my concerns, LGTM!

@BryanttV

Copy link
Copy Markdown
Contributor

Let's make sure we create the issue to keep track of that before merging please.

@rodmgwgu, here is the issue: #457

@rodmgwgu
rodmgwgu merged commit 85da7fd into openedx:main Sep 18, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from In Eng Review to Done in Contributions Sep 18, 2026
@rodmgwgu
rodmgwgu deleted the carlos-marquez-wgu/issue-406-implement-per-user-aggregation-logic branch September 18, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Backend: Implement per-user aggregation logic in the backend

6 participants