Skip to content

[FC-0099] feat: add rest api for roles and permissions#84

Merged
mariajgrimaldi merged 26 commits intoopenedx:mainfrom
eduNEXT:bav/rest-api
Oct 14, 2025
Merged

[FC-0099] feat: add rest api for roles and permissions#84
mariajgrimaldi merged 26 commits intoopenedx:mainfrom
eduNEXT:bav/rest-api

Conversation

@BryanttV
Copy link
Copy Markdown
Contributor

@BryanttV BryanttV commented Oct 1, 2025

Description

This PR introduces the REST API for Open edX AuthZ.

How To Test

We create the following endpoints:

  • Validate Permissions (POST)
  • List Users in Role (GET)
  • Add Users to Role (PUT)
  • Delete User from Role (DELETE)
  • List Roles by Scope (GET)

You can download this open-edx-authz.postman_collection.json or go to {lms_domain}/api-docs/#/authz to test all endpoints.

@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, 2025
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented Oct 1, 2025

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.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Oct 1, 2025
@BryanttV BryanttV force-pushed the bav/rest-api branch 2 times, most recently from fe5cd43 to 6ed26f6 Compare October 2, 2025 02:17
Comment thread openedx_authz/rest_api/v1/views.py Outdated
Comment thread openedx_authz/api/roles.py
Comment thread openedx_authz/rest_api/v1/views.py Outdated
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Oct 2, 2025
Comment thread openedx_authz/rest_api/v1/views.py Outdated
Comment thread openedx_authz/api/users.py Outdated
@BryanttV BryanttV force-pushed the bav/rest-api branch 2 times, most recently from 623b6b1 to 9b924f8 Compare October 6, 2025 18:12
Comment thread openedx_authz/rest_api/v1/urls.py Outdated
@BryanttV BryanttV changed the title feat: add rest api for roles and permissions [FC-0099] feat: add rest api for roles and permissions Oct 7, 2025
@BryanttV BryanttV marked this pull request as ready for review October 7, 2025 04:06
Comment thread openedx_authz/rest_api/v1/views.py Outdated
Comment thread openedx_authz/rest_api/v1/views.py Outdated
Comment thread openedx_authz/rest_api/v1/serializers.py Outdated
Comment thread openedx_authz/rest_api/v1/views.py Outdated
Comment thread openedx_authz/rest_api/utils.py
Copy link
Copy Markdown
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great, I think there are 1-2 more thorny issues to work out but it's close.

Comment thread openedx_authz/rest_api/v1/serializers.py Outdated
Comment thread openedx_authz/rest_api/v1/serializers.py Outdated
Comment thread openedx_authz/rest_api/v1/serializers.py Outdated
Comment thread openedx_authz/rest_api/v1/views.py Outdated
Comment thread openedx_authz/rest_api/v1/views.py Outdated
serializer = AddUserToRoleWithScopeSerializer(data=request.data)
serializer.is_valid(raise_exception=True)

# TODO: Should we validate that the role or scope exists?
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.

I think we have to if the api doesn't error on it. Otherwise it may be a vector for credential stuffing attacks? Similarly we should make sure that the scope matches whatever we're authenticating for in permission class (ex: we're checking library permissions in the permission class now, but not checking that the scope they're modifying here is a library scope).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with you. I added a validation method in the serializer that checks whether the scope exists. For example, if my scope is a Library ID (lib:OpenedX:CSPROB), it will validate using the exists() method to ensure that this library actually exists in the database. After that, it validates that the role exists within the roles defined in the general scope (namespace). If any of these validations fail, it will return an error. What do you think?


user_identifiers = serializer.validated_data["users"]
role_name = serializer.validated_data["role"]
scope = serializer.validated_data["scope"]
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.

Similar comment to above, we should make sure that the scope we're deleting matches the permissions we're checking in the permission class.

Comment thread openedx_authz/rest_api/v1/views.py Outdated
- user_count: Number of users currently assigned to this role

**Authentication and Permissions**
Requires authenticated user.
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.

Can any authenticated user make this call for any scope?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, I'm just not sure which permission we should validate in this case, considering that it's a general endpoint for all scopes.

cc @mariajgrimaldi

Copy link
Copy Markdown
Member

@mariajgrimaldi mariajgrimaldi Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's this one: https://openedx.atlassian.net/wiki/spaces/OEPM/pages/4840095745/Library+Roles+and+Permissions#Manage-Library-Team (which also considers view). This ties back to our earlier discussion about HasLibraryPermission as well. For now, it's limited to that specific library perm, but once we add support for other scopes, it would apply to the course admin, and so on.

Tagging @MaferMazu since she has been working on the final authz.policy.

Comment thread openedx_authz/rest_api/enums.py Outdated
Copy link
Copy Markdown
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good, I appreciate the changes to add BaseScopePermission! 👍

@BryanttV
Copy link
Copy Markdown
Contributor Author

@bmtcril @mariajgrimaldi

I just bumped to version 0.3.0.

For now, the endpoint to get roles and permissions by namespace has been added so that only an admin user can use it. It should be usable by any user with the manage_library_team permission, but since only the namespace is sent, it's challenging to do the evaluation with the enforcer correctly.

If you agree, we can merge the PR, and I will work on a way to fix it in another PR.

@mariajgrimaldi
Copy link
Copy Markdown
Member

@BryanttV: I'll merge this with that note in mind, we can address it in a different PR. Thank you all for all the work!

@mariajgrimaldi mariajgrimaldi merged commit 8e55e59 into openedx:main Oct 14, 2025
14 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting on Author to Done in Contributions Oct 14, 2025
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

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants