Skip to content

feat: validate permission dependencies when creating or editing a custom role - #675

Open
rodmgwgu wants to merge 1 commit into
mainfrom
feat/custom-role-dependency-validation
Open

rodmgwgu wants to merge 1 commit into
mainfrom
feat/custom-role-dependency-validation

Conversation

@rodmgwgu

@rodmgwgu rodmgwgu commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Closes #674

Problem

ADR 0036 section 7 requires the create and update custom role endpoints to reject a permission set that leaves out a dependency, but #647 and #649 shipped without the check because dependencies were not stored yet. Since #657 they are, so a client can still save a role that grants, for example, edit_library_content without view_library.

Approach

  • create_custom_role and update_custom_role check the set with the existing missing_dependencies helper and the stored dependency map, after the other permission checks and before any write. Both endpoints get the check from there.
  • A missing direct or indirect dependency raises the new MissingPermissionDependenciesError, a subclass of InvalidCustomRoleError. The server does not add dependencies.
  • POST /api/authz/v1/roles/ and PATCH /api/authz/v1/roles/<role_id>/ return 400 with message and missing_dependencies, which maps each permission to the sorted IDs it is missing, so the admin console can point at the permissions to add without parsing text.
  • On edit, hidden permissions the role keeps (feat: add the endpoint to edit custom roles #649) count as granted. Their own dependencies are not checked: the client cannot see them, so it could not fix the error, and their g2 rows still grant the dependencies.

Manual testing instructions

As a staff user in the LMS:

  1. POST /api/authz/v1/roles/ with {"display_name": "Library Cleaner", "scope_types": ["lib"], "permissions": ["content_libraries.delete_library"]}. It returns 400 with missing_dependencies listing content_libraries.edit_library_content and content_libraries.view_library, and no role is created.
  2. Repeat with "permissions": ["content_libraries.delete_library", "content_libraries.edit_library_content", "content_libraries.view_library"]. It returns 201.
  3. PATCH /api/authz/v1/roles/custom_library_cleaner/ with {"permissions": ["content_libraries.edit_library_content"]}. It returns 400 listing content_libraries.view_library, and the role keeps its three permissions.

Unit tests: pytest src/openedx_authz/tests/api/test_custom_roles.py src/openedx_authz/tests/rest_api/test_views.py -k "dependenc or hidden".

Rollback plan

Revert this PR. No migration and no stored data.

Retro compatibility

Create and update now reject permission sets they accepted before. Both endpoints are still unreleased, so no released client depends on the old behavior. Roles saved before this change without their dependencies are not changed; their next permissions edit must send a complete set.

AI Usage

🤖 This change was made with assistance from Kiro, with human guidance on the decisions and validation against ADR 0036.


Merge checklist:

  • Changelog record added
  • Documentation updated (not only docstrings) — not needed, ADR 0036 section 7 already describes this behavior
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets — based on main, not stacked.

…tom role

POST /api/authz/v1/roles/ and PATCH /api/authz/v1/roles/<role_id>/ now reject
a permission set that leaves out a direct or indirect dependency of another
permission in the set, with 400 and missing_dependencies (ADR 0036 section 7).
Hidden permissions an edit keeps count as granted, and their own dependencies
are not checked.

Closes #674
@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 Dec 2, 2026
@openedx-webhooks

openedx-webhooks commented Dec 2, 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 Dec 2, 2026
@rodmgwgu
rodmgwgu marked this pull request as ready for review December 2, 2026 21:25
@rodmgwgu
rodmgwgu requested review from BryanttV, diana-villalvazo-wgu, jacobo-dominguez-wgu, mariajgrimaldi and wgu-taylor-payne and a balanced review from Copilot and removed request for Copilot December 2, 2026 21:29
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Dec 2, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review 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: Ready for Review

Development

Successfully merging this pull request may close these issues.

Validate permission dependencies in the custom role create and update endpoints

3 participants