Skip to content

Conversation

@MaferMazu
Copy link
Contributor

@MaferMazu MaferMazu commented Oct 17, 2025

Description

This PR:

  • Introduces openedx-authz in two api methods user_can_create_library
    and require_permission_for_library_key.
  • Modify the collections and publish enforcement to use the new permissions and also check the old one.
  • Add tests based on test_library_permission but using the new authz system.

Implementation:
We implement user_has_permission_across_lib_authz_systems to handle the verification of permissions in both system (the one in content_libraries/permissions.py and the new one implemented in openedx-authz).

Consequences:
By adding openedx-authz enforcement in require_permission_for_library_key, we are extending the verification in those places: https://github.com/search?q=repo%3Aopenedx%2Fedx-platform%20require_permission_for_library_key&type=code

Important note:
With this change we are adding checks over explicit permissions in the openedx-authz system. So we rely on bridgekeeper for the moment to make attribute checking (specific cases: course_creator imply library_creator, and the library having the allow_public_read attribute imply view_library true).

Supporting information

openedx/openedx-authz#88
https://openedx-authz.readthedocs.io/en/latest/concepts/core_roles_and_permissions/content_library_roles.html#roles-and-permissions-summary-table

Testing instructions

Using python test

  • I didn't modify the current test, so the tested behavior won't change with this addition.
  • I added test that verify the rest api calls when he data uses the new openedx-authz system.

In stage

Stage information: https://openedx.atlassian.net/wiki/spaces/OEPM/pages/5279023110/AuthZ+Stage+Information

Preparation of the env:

  • Have an library user, a contributor, an author and an admin.
image

Credentials: https://openedx.atlassian.net/wiki/spaces/OEPM/pages/5279023110/AuthZ+Stage+Information

You can create your own library, or use one created. For this I'll use lib:OpenedX:LIBTESTDELETE/ as example.

Test:
Library User

Library Contributor

Library Author
The same + publish content.

Library Admin
It should have access to get, edit the content and collections and delete (soft delete a library)

Deadline

Ulmo cut.

Other information

Related to: https://openedx.atlassian.net/wiki/spaces/OEPM/pages/4724490259/PRD+Roles+Permissions

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 17, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Oct 17, 2025

Thanks for the pull request, @MaferMazu!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

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.

@MaferMazu MaferMazu force-pushed the mfmz/authz-base branch 2 times, most recently from 2bd07e4 to d916e7b Compare October 21, 2025 23:38
@MaferMazu MaferMazu marked this pull request as ready for review October 21, 2025 23:46
@feanil feanil requested a review from bmtcril October 22, 2025 17:36
@MaferMazu MaferMazu moved this to In Progress in RBAC AuthZ Board Oct 22, 2025
@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Oct 22, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Triage to In Eng Review in Contributions Oct 22, 2025
Copy link
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

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

I know this is still a work in progress, but I think we should add unit tests for the cases in
https://github.com/openedx/edx-platform/blob/8fad71724e6b87e4c3f2c95f69b21c7e7507a5da/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py#L565-L745
to make sure we're still covering the same scenarios we're modifying here, assuming these are the ones affected.

@MaferMazu
Copy link
Contributor Author

MaferMazu commented Oct 24, 2025

@BryanttV @mariajgrimaldi, following the recommendation to add our enforcement in require_permission_for_library_key, we are already adding the enforcement in some of the places I identified.

This PR currently covers the parts marked in here: openedx/openedx-authz#88 (tested)

Right now, I am working on the collection permissions (I know I have some tests failing, but I'll work on that tomorrow morning) to try to have all the enforcement in this PR, since we're far from having all the enforcement points updated.

I added require_authz_lib_permission to handle the permissions that weren't in the old system.

Things this PR needs:

  • Fix collection tests
  • Update the remaining enforcement points
  • Create a test_content_library_permission using data from the new system

Copy link
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

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

Here's another round of review. My main concern is transparency and readability. It's a bit confusing to have multiple functions checking permissions, so we might need to rethink how to centralize all checks in one place. That way, we avoid maintaining different versions and make it easier for others to follow the authorization logic.

I want to prioritize parity functionality instead of quality and nits, so we can find a good place in between.

@MaferMazu MaferMazu force-pushed the mfmz/authz-base branch 3 times, most recently from bc99706 to bb9a1bb Compare October 27, 2025 03:10
@MaferMazu MaferMazu changed the title [FC-0099] feat: add openedx-authz as a requirement and add some enforcerment checks [FC-0099] feat: add openedx-authz to library apis user_can_create_library and require_permission_for_library_key Oct 27, 2025
@mariajgrimaldi
Copy link
Member

@MaferMazu: can we report this in the openedx-authz repo?

Expected result: No see the publish button. - This is something we should modify in the front as part of release testing (for now we can view the button but in backend the contributor can not publish that is the expected behavior)

Copy link
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

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

LGTM!

Thank you so much for the hard work. I left a few nits for you to consider, but everything else looks good to go. Everything I tested also looked good! Thanks :)

@MaferMazu
Copy link
Contributor Author

I am having problems with the test using the last openedx-authz. I'm working on it.

@mariajgrimaldi
Copy link
Member

mariajgrimaldi commented Nov 12, 2025

@MaferMazu could you check these changes to see if they help with the unit tests? 3cd4176

A few notes:

  1. The atomic blocks aren’t needed since the API we call already handles atomic consistency.
  2. There was an issue when inheriting from classes that both define the same methods (like setUp, setUpClass, etc.) and share the same parent (Django test class), which caused unexpected behavior.
  3. I split the test into smaller, clearer blocks to make debugging and review easier.

Let me know what you think of the changes. Thanks!

@mariajgrimaldi mariajgrimaldi self-requested a review November 12, 2025 13:58
Copy link
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.

I've tested this locally and it looks good to me once @mariajgrimaldi 's comments are sorted!

@MaferMazu
Copy link
Contributor Author

@mariajgrimaldi, thanks a lot for the help with the test. I applied your changes, and they work. Thanks again.

The last change I did was to upgrade the openedx-authz package.

@mariajgrimaldi, can you help me review this?

Copy link
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you :)

@MaferMazu MaferMazu enabled auto-merge (squash) November 13, 2025 15:20
@MaferMazu MaferMazu disabled auto-merge November 13, 2025 15:22
feat: add the authz publish check in rest_api blocks and containers

feat: add the authz checks in libraries and refactor

feat: add collections checks

feat: update enforcement in serializer file

refactor: refactor the permission check functions

fix: fix value error

fix: calling the queries twice
refactor: refactor the tests and apply feedback

fix: apply feedback

Revert "refactor: refactor the tests and apply feedback"

This reverts commit aa0bd52.

refactor: use constants and avoid mapping

test: fix the test to have them in order

docs: about we rely on bridgekeeper and the old check for two cases

docs: update openedx/core/djangoapps/content_libraries/api/libraries.py

Co-authored-by: Maria Grimaldi (Majo) <maria.grimaldi@edunext.co>

refactor: use global scope wildcard instead of *

refactor: allow receiving PermissionData objects

refactor: do not inherit from BaseRolesTestCase to favor CL setup methods

If both BaseRolesTestCase and ContentLibrariesRestApiTest define a method
with the same name (e.g., setUp()), Python will use the one found first
in the MRO, which is the one in BaseRolesTestCase because it is
listed first in the class definition leading to unexpected behavior.

refactor: remove unnecessary imports and indent
@MaferMazu MaferMazu merged commit f4f14a6 into openedx:master Nov 13, 2025
84 of 95 checks passed
@github-project-automation github-project-automation bot moved this from Ready for review to Done in RBAC AuthZ Board Nov 13, 2025
@github-project-automation github-project-automation bot moved this from In Eng Review to Done in Contributions Nov 13, 2025
@github-project-automation github-project-automation bot moved this from In progress to Done in Build-Test-Release Working Group Nov 13, 2025
MaferMazu added a commit to eduNEXT/edx-platform that referenced this pull request Nov 13, 2025
…rary and require_permission_for_library_key (openedx#37501)

* feat: add the authz check to the library api function

feat: add the authz publish check in rest_api blocks and containers

feat: add the authz checks in libraries and refactor

feat: add collections checks

feat: update enforcement in serializer file

refactor: refactor the permission check functions

fix: fix value error

fix: calling the queries twice

* test: add structure for test and apply feedback

refactor: refactor the tests and apply feedback

fix: apply feedback

Revert "refactor: refactor the tests and apply feedback"

This reverts commit aa0bd52.

refactor: use constants and avoid mapping

test: fix the test to have them in order

docs: about we rely on bridgekeeper and the old check for two cases

docs: update openedx/core/djangoapps/content_libraries/api/libraries.py

Co-authored-by: Maria Grimaldi (Majo) <maria.grimaldi@edunext.co>

refactor: use global scope wildcard instead of *

refactor: allow receiving PermissionData objects

refactor: do not inherit from BaseRolesTestCase to favor CL setup methods

If both BaseRolesTestCase and ContentLibrariesRestApiTest define a method
with the same name (e.g., setUp()), Python will use the one found first
in the MRO, which is the one in BaseRolesTestCase because it is
listed first in the class definition leading to unexpected behavior.

refactor: remove unnecessary imports and indent

* chore: bump openedx-authz version

(cherry picked from commit f4f14a6)
MaferMazu added a commit to eduNEXT/edx-platform that referenced this pull request Nov 14, 2025
…sion_for_library_key (openedx#37501)

* feat: add the authz check to the library api function

feat: add the authz publish check in rest_api blocks and containers

feat: add the authz checks in libraries and refactor

feat: add collections checks

feat: update enforcement in serializer file

refactor: refactor the permission check functions

fix: fix value error

fix: calling the queries twice

* test: add structure for test and apply feedback

refactor: refactor the tests and apply feedback

fix: apply feedback

Revert "refactor: refactor the tests and apply feedback"

This reverts commit aa0bd52.

refactor: use constants and avoid mapping

test: fix the test to have them in order

docs: about we rely on bridgekeeper and the old check for two cases

docs: update openedx/core/djangoapps/content_libraries/api/libraries.py

Co-authored-by: Maria Grimaldi (Majo) <maria.grimaldi@edunext.co>

refactor: use global scope wildcard instead of *

refactor: allow receiving PermissionData objects

refactor: do not inherit from BaseRolesTestCase to favor CL setup methods

If both BaseRolesTestCase and ContentLibrariesRestApiTest define a method
with the same name (e.g., setUp()), Python will use the one found first
in the MRO, which is the one in BaseRolesTestCase because it is
listed first in the class definition leading to unexpected behavior.

refactor: remove unnecessary imports and indent

* chore: bump openedx-authz version

(cherry picked from commit f4f14a6)
mariajgrimaldi pushed a commit to eduNEXT/edx-platform that referenced this pull request Nov 18, 2025
…rary and require_permission_for_library_key (openedx#37501)

* feat: add the authz check to the library api function

feat: add the authz publish check in rest_api blocks and containers

feat: add the authz checks in libraries and refactor

feat: add collections checks

feat: update enforcement in serializer file

refactor: refactor the permission check functions

fix: fix value error

fix: calling the queries twice

* test: add structure for test and apply feedback

refactor: refactor the tests and apply feedback

fix: apply feedback

Revert "refactor: refactor the tests and apply feedback"

This reverts commit aa0bd52.

refactor: use constants and avoid mapping

test: fix the test to have them in order

docs: about we rely on bridgekeeper and the old check for two cases

docs: update openedx/core/djangoapps/content_libraries/api/libraries.py

Co-authored-by: Maria Grimaldi (Majo) <maria.grimaldi@edunext.co>

refactor: use global scope wildcard instead of *

refactor: allow receiving PermissionData objects

refactor: do not inherit from BaseRolesTestCase to favor CL setup methods

If both BaseRolesTestCase and ContentLibrariesRestApiTest define a method
with the same name (e.g., setUp()), Python will use the one found first
in the MRO, which is the one in BaseRolesTestCase because it is
listed first in the class definition leading to unexpected behavior.

refactor: remove unnecessary imports and indent

* chore: bump openedx-authz version
mariajgrimaldi pushed a commit to eduNEXT/edx-platform that referenced this pull request Nov 18, 2025
…rary and require_permission_for_library_key (openedx#37501)

* feat: add the authz check to the library api function

feat: add the authz publish check in rest_api blocks and containers

feat: add the authz checks in libraries and refactor

feat: add collections checks

feat: update enforcement in serializer file

refactor: refactor the permission check functions

fix: fix value error

fix: calling the queries twice

* test: add structure for test and apply feedback

refactor: refactor the tests and apply feedback

fix: apply feedback

Revert "refactor: refactor the tests and apply feedback"

This reverts commit aa0bd52.

refactor: use constants and avoid mapping

test: fix the test to have them in order

docs: about we rely on bridgekeeper and the old check for two cases

docs: update openedx/core/djangoapps/content_libraries/api/libraries.py

Co-authored-by: Maria Grimaldi (Majo) <maria.grimaldi@edunext.co>

refactor: use global scope wildcard instead of *

refactor: allow receiving PermissionData objects

refactor: do not inherit from BaseRolesTestCase to favor CL setup methods

If both BaseRolesTestCase and ContentLibrariesRestApiTest define a method
with the same name (e.g., setUp()), Python will use the one found first
in the MRO, which is the one in BaseRolesTestCase because it is
listed first in the class definition leading to unexpected behavior.

refactor: remove unnecessary imports and indent

* chore: bump openedx-authz version
MaferMazu added a commit to eduNEXT/edx-platform that referenced this pull request Nov 19, 2025
…sion_for_library_key (openedx#37501)

* feat: add the authz check to the library api function

feat: add the authz publish check in rest_api blocks and containers

feat: add the authz checks in libraries and refactor

feat: add collections checks

feat: update enforcement in serializer file

refactor: refactor the permission check functions

fix: fix value error

fix: calling the queries twice

* test: add structure for test and apply feedback

refactor: refactor the tests and apply feedback

fix: apply feedback

Revert "refactor: refactor the tests and apply feedback"

This reverts commit aa0bd52.

refactor: use constants and avoid mapping

test: fix the test to have them in order

docs: about we rely on bridgekeeper and the old check for two cases

docs: update openedx/core/djangoapps/content_libraries/api/libraries.py

Co-authored-by: Maria Grimaldi (Majo) <maria.grimaldi@edunext.co>

refactor: use global scope wildcard instead of *

refactor: allow receiving PermissionData objects

refactor: do not inherit from BaseRolesTestCase to favor CL setup methods

If both BaseRolesTestCase and ContentLibrariesRestApiTest define a method
with the same name (e.g., setUp()), Python will use the one found first
in the MRO, which is the one in BaseRolesTestCase because it is
listed first in the class definition leading to unexpected behavior.

refactor: remove unnecessary imports and indent

* chore: bump openedx-authz version

(cherry picked from commit f4f14a6)
mariajgrimaldi added a commit that referenced this pull request Nov 20, 2025
…cement points (#37633)

* feat: filter libraries based on user-role scopes (#37564)

(cherry picked from commit 6c6fc5d)

* feat: add openedx-authz to user_can_create_library and require_permission_for_library_key (#37501)

* feat: add the authz check to the library api function

feat: add the authz publish check in rest_api blocks and containers

feat: add the authz checks in libraries and refactor

feat: add collections checks

feat: update enforcement in serializer file

refactor: refactor the permission check functions

fix: fix value error

fix: calling the queries twice

* test: add structure for test and apply feedback

refactor: refactor the tests and apply feedback

fix: apply feedback

Revert "refactor: refactor the tests and apply feedback"

This reverts commit aa0bd52.

refactor: use constants and avoid mapping

test: fix the test to have them in order

docs: about we rely on bridgekeeper and the old check for two cases

docs: update openedx/core/djangoapps/content_libraries/api/libraries.py

Co-authored-by: Maria Grimaldi (Majo) <maria.grimaldi@edunext.co>

refactor: use global scope wildcard instead of *

refactor: allow receiving PermissionData objects

refactor: do not inherit from BaseRolesTestCase to favor CL setup methods

If both BaseRolesTestCase and ContentLibrariesRestApiTest define a method
with the same name (e.g., setUp()), Python will use the one found first
in the MRO, which is the one in BaseRolesTestCase because it is
listed first in the class definition leading to unexpected behavior.

refactor: remove unnecessary imports and indent

* chore: bump openedx-authz version

(cherry picked from commit f4f14a6)

* feat: Upgrade Python dependency openedx-authz (#37652)

* feat: Upgrade Python dependency openedx-authz

handle cache invalidation

Commit generated by workflow `openedx/edx-platform/.github/workflows/upgrade-one-python-dependency.yml@refs/heads/master`

* fix: update the num of queries in tests

---------

Co-authored-by: MaferMazu <35668326+MaferMazu@users.noreply.github.com>
Co-authored-by: Maria Fernanda Magallanes Zubillaga <maria.magallanes@edunext.co>
(cherry picked from commit 122b4e0)

* chore: update requirements to fix the inconsistency

---------

Co-authored-by: Maria Grimaldi (Majo) <maria.grimaldi@edunext.co>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project
Status: Done

Development

Successfully merging this pull request may close these issues.

Bug: 403 when opening library dashboard as "guillermotest" team member Enforcement Updates

8 participants