Skip to content

feat: add the endpoints to read and remove custom roles - #656

Merged
rodmgwgu merged 2 commits into
mainfrom
feat/custom-role-read-remove
Dec 2, 2026
Merged

rodmgwgu merged 2 commits into
mainfrom
feat/custom-role-read-remove

Conversation

@rodmgwgu

Copy link
Copy Markdown
Contributor

Closes #581

Problem

The Administrative Console can't open a role's detail view or remove a custom role. api.remove_custom_role from #644 has no REST endpoint, and there is no endpoint that returns one role.

Approach

  • Added GET and DELETE to RoleDetailView at /api/authz/v1/roles/<role_id>/, as ADR 0036 defines them.
  • GET returns the role, static or custom, in the format of a role list item, through get_role_entry. A non-staff caller needs the permission ADR 0028 requires to list roles of one of the role's resource types (courses.view_course_team or content_libraries.view_library_team). The new RoleScopeTypePermission checks this against the role in the URL. An unknown role is left to the view, so it returns 404 for every caller.
  • DELETE is limited to staff and superusers through PrivilegedWritePermission and calls api.remove_custom_role. A role with assignments needs assignments=revoke, or the request returns 409 and removes nothing. Any other value returns 400, an empty value counts as not sent. Static roles return 400, and unknown or removed roles return 404.
  • The audit trail (Implementation: Custom roles audit trail #588) will follow separately.

Manual testing instructions

As a staff user in the LMS, with a custom library role custom_designer assigned to one user in a library:

  1. GET /api/authz/v1/roles/custom_designer/. It returns 200 with user_count 1.
  2. As a course staff member who isn't staff and has no library role, repeat step 1. It returns 403.
  3. DELETE /api/authz/v1/roles/custom_designer/. It returns 409 and the role is still listed.
  4. DELETE /api/authz/v1/roles/custom_designer/?assignments=revoke. It returns 204, the user loses the role's access, and GET returns 404.
  5. DELETE /api/authz/v1/roles/library_author/. It returns 400.

Unit tests: pytest src/openedx_authz/tests/rest_api/test_views.py -k "TestRoleDetailViewRead or TestRoleDetailViewRemove".

Rollback plan

Revert this PR. No migration. Roles removed through the endpoint stay removed.

Retro compatibility

No existing endpoint changes.

AI Usage

Kiro assisted with the implementation and review, with human guidance on the decisions and validation against ADR 0036.


Merge checklist:

@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 Nov 25, 2026
@openedx-webhooks

openedx-webhooks commented Nov 25, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @rodmgwgu!

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.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Nov 25, 2026
@rodmgwgu
rodmgwgu added this pull request to stack #646 November 25, 2026 18:26
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-read-remove branch 3 times, most recently from fef600f to e5f125e Compare November 25, 2026 21:21
@rodmgwgu
rodmgwgu marked this pull request as ready for review November 25, 2026 21:21
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-read-remove branch from e5f125e to f1d9fbc Compare November 27, 2026 21: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.

Hi @rodmgwgu, thanks for this! I ran some automated tests on my local, and this is what the AI agent reported:

Comment thread src/openedx_authz/rest_api/v1/views.py Resolved
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-read-remove branch 2 times, most recently from 2785c0c to 6e0f0d6 Compare November 30, 2026 15:49
@rodmgwgu
rodmgwgu requested a review from BryanttV November 30, 2026 15:49
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-read-remove branch 2 times, most recently from 845a6f2 to b2a13a2 Compare November 30, 2026 23:13

@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.

LGTM, thanks!

@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-read-remove branch from b2a13a2 to 5e43abf Compare December 2, 2026 15:57
Base automatically changed from feat/custom-role-update to main December 2, 2026 16:55
GET /api/authz/v1/roles/<role_id>/ returns one role, static or custom, in
the format of the role list (ADR 0036). The caller needs the permission to
list roles of one of the role's resource types; staff and superusers always
pass.

DELETE /api/authz/v1/roles/<role_id>/ removes a custom role and is limited
to staff and superusers. A role with assignments needs assignments=revoke,
otherwise it returns 409 and removes nothing. Static roles return 400, and
unknown or removed roles return 404 on both endpoints.

Closes #581

Co-authored-by: Kiro <noreply@kiro.dev>
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-read-remove branch from 5e43abf to fbff17a Compare December 2, 2026 16:55
@rodmgwgu
rodmgwgu merged commit 217653d into main Dec 2, 2026
8 checks passed
@rodmgwgu
rodmgwgu deleted the feat/custom-role-read-remove branch December 2, 2026 18:21
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in Contributions Dec 2, 2026
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: Done

Development

Successfully merging this pull request may close these issues.

Backend: read and remove custom role endpoints

3 participants