Skip to content

feat: add the endpoint to edit custom roles - #649

Merged
rodmgwgu merged 1 commit into
mainfrom
feat/custom-role-update
Dec 2, 2026
Merged

rodmgwgu merged 1 commit into
mainfrom
feat/custom-role-update

Conversation

@rodmgwgu

@rodmgwgu rodmgwgu commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #590

Problem

The Administrative Console can't edit custom roles. api.update_custom_role from #644 has no REST endpoint.

Approach

  • Added PATCH /api/authz/v1/roles/<role_id>/ in a new RoleDetailView, as ADR 0036 defines it. The request takes description, permissions, or both, and calls api.update_custom_role. permissions replaces the full list.
  • Only staff and superusers can edit, through PrivilegedWritePermission.
  • UpdateCustomRoleSerializer keeps only the fields that were sent and rejects display_name and scope_types, which can't change after creation. The other rules stay in the API. Editing a static role returns 400, and a role that doesn't exist or was removed returns 404.
  • The response is the role in the format of a role list item, with the user_count the caller can view. get_role_entry builds it, and the create endpoint now uses it too, so both write paths respond the same way.
  • Moved the shared setup of the create and edit view tests into CustomRoleViewTestMixin.
  • Permission dependencies are not checked yet. The check needs dependencies stored in the schema (Implementation: Permission dependencies mapping via Yaml extensibility #560) and will go into the API, so this endpoint gets it without changes.
  • 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 that grants content_libraries.view_library:

  1. PATCH /api/authz/v1/roles/custom_designer/ with {"description": "Edits libraries"}. It returns 200 with the new description and a later updated_at.
  2. PATCH with {"permissions": ["content_libraries.edit_library_content"]}. It returns 200, and a user with the role in a library can now edit content but no longer has view_library.
  3. PATCH with {"display_name": "Other"}. It returns 400.
  4. PATCH /api/authz/v1/roles/library_author/ with {"description": "x"}. It returns 400.
  5. As a library admin who isn't staff, repeat step 1. It returns 403.

Unit tests: pytest src/openedx_authz/tests/rest_api/test_views.py -k TestRoleDetailViewUpdate.

Rollback plan

Revert this PR. No migration. Edits made through the endpoint stay.

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

openedx-webhooks commented Nov 23, 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 23, 2026
@rodmgwgu
rodmgwgu added this pull request to stack #646 November 23, 2026 20:46
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-update branch from 4848314 to 65661f4 Compare November 23, 2026 21:07
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-update branch from 65661f4 to 21df998 Compare November 23, 2026 22:51
@rodmgwgu
rodmgwgu marked this pull request as ready for review November 23, 2026 22:57
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-update branch from 21df998 to b3f6bdd Compare November 24, 2026 15:46
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Nov 24, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Nov 24, 2026
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-update branch from b3f6bdd to 2525d5e Compare November 25, 2026 17:44
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-update branch from 2525d5e to e2ace28 Compare November 25, 2026 20:52
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-update branch from e2ace28 to 157dc9e 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 the PR! I just have one comment

Comment thread src/openedx_authz/rest_api/v1/views.py Resolved
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-update branch from 157dc9e to 22dc34a Compare November 30, 2026 15:20
Base automatically changed from feat/custom-role-create to main November 30, 2026 16:22
@rodmgwgu
rodmgwgu force-pushed the feat/custom-role-update branch 2 times, most recently from 256d31b to aed6933 Compare November 30, 2026 23:13
@rodmgwgu
rodmgwgu requested a review from BryanttV December 1, 2026 22:17
PATCH /api/authz/v1/roles/<role_id>/ changes the description or the
permissions of a custom role (ADR 0036). Only staff and superusers can
edit roles. The name and resource type cannot change, so sending them
returns 400, as does editing a static role. A role that does not exist
or was removed returns 404.

Permission dependency checks wait for dependencies to be stored in the schema (#560).

Co-authored-by: Kiro <noreply@kiro.dev>

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

@rodmgwgu
rodmgwgu merged commit e88f1a6 into main Dec 2, 2026
8 checks passed
@rodmgwgu
rodmgwgu deleted the feat/custom-role-update branch December 2, 2026 16:55
@github-project-automation github-project-automation Bot moved this from Ready for Review 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). 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: update custom role (metadata + permissions) endpoints

4 participants