Skip to content

fix: include ancestor scopes when filtering assignments by scope - #483

Open
carlos-marquez-wgu wants to merge 1 commit into
openedx:mainfrom
WGU-Open-edX:carlos-marquez-wgu/issue-457-return-higher-scopes-when-querying-specifics-ones
Open

carlos-marquez-wgu wants to merge 1 commit into
openedx:mainfrom
WGU-Open-edX:carlos-marquez-wgu/issue-457-return-higher-scopes-when-querying-specifics-ones

Conversation

@carlos-marquez-wgu

@carlos-marquez-wgu carlos-marquez-wgu commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

The scope filter in _filter_candidate_assignments_by_params matched only exact scope keys, so querying a specific course or library did not return assignments granted at the org or platform level, this PR addresses this.

Changes

Add _expand_scopes_with_ancestors to derive org-glob and platform-glob parent keys for each queried scope using the existing ScopeMeta registries, and expand the match set before filtering.

Hierarchy: specific → org glob → platform glob

  • course-v1:Org+Course+Run → course-v1:Org+* → course-v1:*
  • lib:Org:Slug → lib:Org:* → lib:*

Manual testing

  1. Assign an org-wide or platform-wide scope permission (for a course or library) to a user, without adding the permission to the specific course / lib
  2. Query the assignments while filtering by the specific course / lib scope
  3. Response should return users which only has higher scope assignments and not only the very specific one

Example

Request

GET /api/authz/v1/users/?scope=course-v1:OpenedX+DemoX+DemoCourse,lib%3ACORG%3ALIB101

Response body (before)

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "username": "lord.admin",
      "full_name": "",
      "email": "admin@example.com",
      "assignment_count": 1,
      "assignments": [
        {
          "role": "library_admin",
          "org": "CORG",
          "scope": "lib:CORG:LIB101",
          "permission_count": 11,
          "scope_display_name": "MyLibrary"
        }
      ]
    }
  ]
}

Response body (after)

{
  "count": 2,
  "next": null,
  "previous": null,
  "results": [
    {
      "username": "lord.admin",
      "full_name": "",
      "email": "admin@example.com",
      "assignment_count": 2,
      "assignments": [
        {
          "role": "library_admin",
          "org": "CORG",
          "scope": "lib:CORG:LIB101",
          "permission_count": 11,
          "scope_display_name": "MyLibrary"
        },
        {
          "role": "course_editor",
          "org": "*",
          "scope": "course-v1:*",
          "permission_count": 22,
          "scope_display_name": ""
        }
      ]
    },
    {
      "username": "test.user.course_editor",
      "full_name": "",
      "email": "course_editor@example.com",
      "assignment_count": 2,
      "assignments": [
        {
          "role": "library_user",
          "org": "*",
          "scope": "lib:*",
          "permission_count": 3,
          "scope_display_name": ""
        },
        {
          "role": "course_staff",
          "org": "OpenedX",
          "scope": "course-v1:OpenedX+*",
          "permission_count": 31,
          "scope_display_name": ""
        }
      ]
    }
  ]
}

Screenshots

Note: using @dcoa work from PR openedx/frontend-app-admin-console#222

Before

image

After

image

Concerns

This change also affects the endpoint AssignmentsAPIView.get since it ultimately uses the same filtering function. Question, are we okay with this or should this path be isolated?

I didn't isolated this yet since this could be a desired effect due to the current Team Members figma design

image

(see is filtered by scope but it still shows higher scopes too)

Merge checklist:
Check off if complete or not applicable:

  • 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 #457

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

openedx-webhooks commented Sep 24, 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.

The scope filter in _filter_candidate_assignments_by_params matched
only exact scope keys, so querying a specific course or library did
not return assignments granted at the org or platform level.

Add _expand_scopes_with_ancestors to derive org-glob and platform-glob
parent keys for each queried scope using the existing ScopeMeta
registries, and expand the match set before filtering.

Hierarchy: specific → org glob → platform glob
  - course-v1:Org+Course+Run → course-v1:Org+* → course-v1:*
  - lib:Org:Slug → lib:Org:* → lib:*
@carlos-marquez-wgu
carlos-marquez-wgu force-pushed the carlos-marquez-wgu/issue-457-return-higher-scopes-when-querying-specifics-ones branch from 702426b to 18be5b2 Compare September 24, 2026 18:45
@carlos-marquez-wgu
carlos-marquez-wgu marked this pull request as ready for review September 24, 2026 21:34
@carlos-marquez-wgu

Copy link
Copy Markdown
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

Higher-level scopes are not returned when querying a more specific scope

2 participants