Skip to content

feat: serve the role and permission catalog by scope type - #510

Open
BryanttV wants to merge 7 commits into
rod/authz-schema-icons-validationfrom
bav/roles-catalog-api
Open

BryanttV wants to merge 7 commits into
rod/authz-schema-icons-validationfrom
bav/roles-catalog-api

Conversation

@BryanttV

@BryanttV BryanttV commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Implements ADR 0028. GET /api/authz/v1/roles/ is now queried by scope types (course and/or library) instead of a concrete scope. It returns the paginated roles together with the full categories and permissions catalogs, so the Admin Console can build its roles and permissions matrix from a single request.

The catalog is read from the authz schema models (the same data the Casbin policy is rendered from), not from the Casbin policy itself.

Warning

Breaking Change

Before After
Query param scope=lib:OpenedX:CSPROB scope_types=course, scope_types=library or a comma-separated list (scope_types=course,library)
user_count Users assigned in that single scope Distinct users assigned in any scope of the requested scope types (specific scopes plus org/platform globs)
Permission manage_library_team / view permission on the given scope courses.view_course_team (course) and/or content_libraries.view_library_team (library), held in any scope. The user needs the permission of each requested scope type
Response Paginated list of {role, permissions, user_count} Paginated envelope with scopes, categories, permissions and results

Changes

API layer (openedx_authz/api)

  • New catalog.py with get_permission_catalog, get_category_catalog and get_role_catalog. They use a constant number of queries and read only from the schema models.
    • Permissions qualify when any of the requested namespaces is in their supported scopes.
    • Roles are included only if they have at least one grant in the requested namespaces and are not hidden. A role without a stored definition is not listed
    • Categories are the distinct categories used by the returned permissions.
  • roles.py: adds get_user_counts_per_role_in_namespaces, which counts distinct users per role across all scopes of the given namespaces. A user assigned to a role in several namespaces is counted once.
  • data.py: adds the DefinitionKind enum (static / user_defined). Only static is used today; user_defined is reserved for later.

REST API (openedx_authz/rest_api)

  • ScopeTypePermission: a new permission class that maps each scope_type to the permission it needs.
    • Superusers and staff always pass.
    • A missing or unsupported scope_types is not rejected here. The view serializer answers 400.
  • Serializers: ListRolesWithScopeSerializer and ListRolesWithSeplaced by ListRolesQuerySerializerand theRoleCatalog*`serializers.
  • RoleListView: now uses the new permission class and serialization documented separately from 401.
  • data.py: adds SCOPE_TYPE_NAMESPACES (course → course-v1, library → lib).

Example

GET /api/authz/v1/roles/?scope_types=course&page=1&page_size=10
{
  "count": 4,
  "next": null,
  "previous": null,
  "scopes": [
    "course-v1"
  ],
  "categories": [
    {
      "id": "course_team_group",
      "display_name": "Course team & groups",
      "description": "Permissions for viewing and managing the course team, learner groups, and group configurations.",
      "icon": "Group"
    }
  ],
  "permissions": [
    {
      "id": "courses.view_course_team",
      "namespace": "courses",
      "name": "view_course_team",
      "display_name": "View course team",
      "description": "See the list of users with a role assigned to this course.",
      "icon": "RemoveRedEye",
      "category_id": "course_team_group",
      "scopes": [
        "course-v1"
      ]
    }
  ],
  "results": [
    {
      "role": "course_admin",
      "display_name": "Course Admin",
      "description": "Can manage the course team and all course settings.",
      "icon": null,
      "definition_kind": "static",
      "permissions": [
        "courses.view_course_team"
      ],
      "user_count": 5
    }
  ]
}

categories and permissions are complete on every page. Only results are paginated.

Testing Instructions

  1. The catalog is read from the schema models, so they must be loaded: tutor dev run lms ./manage.py lms load_authz_schema. If the tables don't exist, apply migrations first. The new migration is 0011_authz_schema_definitions: tutor dev run lms ./manage.py lms migrate openedx_authz
  2. Log in to the LMS as admin (superuser) and open http://local.openedx.io:8000/api/authz/v1/roles/?scope_types=course in the browser. Expect a 200 response with scope_types, categories, permissions, and a paginated results list of roles.
    • Then try ?scope_types=library, ?scope_types=course,library and ?scope_types=course&page=1&page_size=1. The roles are paginated, but categories and permissions stay complete on every page.
    • A missing or invalid scope_types, or the old scope param, returns 400.
  3. Log out and log in as a regular user (non-staff, with no authz roles). Open http://local.openedx.io:8000/api/authz/v1/roles/?scope_types=course. Expect a 403 response. Repeat with ?scope_types=library and expect 403 as well.

Merge checklist

Check off if complete or not applicable:

  • 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

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Oct 1, 2026
@openedx-webhooks

openedx-webhooks commented Oct 1, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @BryanttV!

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.

@BryanttV
BryanttV force-pushed the bav/roles-catalog-api branch 2 times, most recently from e19eacd to 3d1fd3b Compare October 1, 2026 17:18
@BryanttV BryanttV linked an issue Oct 1, 2026 that may be closed by this pull request
@BryanttV
BryanttV force-pushed the bav/roles-catalog-api branch from 3d1fd3b to 5453f7a Compare October 1, 2026 17:47
@BryanttV
BryanttV marked this pull request as ready for review October 1, 2026 20:51
@BryanttV
BryanttV force-pushed the bav/roles-catalog-api branch 2 times, most recently from 71a6623 to 447e245 Compare October 5, 2026 17:34
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-icons-validation branch from fd932d0 to 768b626 Compare October 5, 2026 22:50
BryanttV and others added 5 commits October 6, 2026 12:51
Implement ADR 0028: GET /api/authz/v1/roles/ is queried by scope_type and
returns paginated roles with the categories and permissions catalogs read
from the authz schema models, with per-scope-type authorization and
user_count calculated by scope type.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Update the roles endpoint to the revised ADR 0028: GET /api/authz/v1/roles/
is queried by a comma-separated scope_types list. Permissions and roles are
the union across the requested scope types, the user must hold the view-team
permission of each one, and user_count counts distinct users across them.
Roles without a stored definition are not listed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Each permission listed by GET /api/authz/v1/roles/ now exposes its scopes,
the scope namespaces where it can be granted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Replace the scope_types field of the response with scopes, using the
backend namespaces (course-v1, lib), as defined in ADR 0028.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… catalog

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@BryanttV
BryanttV force-pushed the bav/roles-catalog-api branch from 447e245 to d29c9a8 Compare October 6, 2026 17:54
The changelog is no longer maintained by hand since the move to
python-semantic-release.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Match the field name used by the authz schema.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). 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.

Role and permission metadata (Catalog API)

3 participants