Skip to content

[FC-0099] fix: load policy in role and permissions views#122

Merged
mariajgrimaldi merged 9 commits intoopenedx:mainfrom
eduNEXT:bav/load-filtered-policy-in-roles-and-perm-views
Oct 30, 2025
Merged

[FC-0099] fix: load policy in role and permissions views#122
mariajgrimaldi merged 9 commits intoopenedx:mainfrom
eduNEXT:bav/load-filtered-policy-in-roles-and-perm-views

Conversation

@BryanttV
Copy link
Copy Markdown
Contributor

@BryanttV BryanttV commented Oct 28, 2025

Description

This PR adds an initial policy load in the DynamicScopePermission class. This is necessary because this class validates whether the user has permissions using the is_user_allowed method, so it’s important to have the most up-to-date policies at the time of validation.

Related Issues

Testing Instructions

Using Tutor:

  1. Install this plugin with the changes in this PR.
  2. Run the migrations by running tutor dev exec lms python manage.py lms migrate
  3. Load the default policies by running tutor dev exec lms python manage.py lms load_policies
  4. Test all endpoints and check that the permissions are returned correctly according to the assignations.

Merge Checklist:

Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

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

openedx-webhooks commented Oct 28, 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 28, 2025
@BryanttV BryanttV changed the title fix: load policy in role and permissions views [FC-0099] fix: load policy in role and permissions views Oct 28, 2025
@mariajgrimaldi mariajgrimaldi moved this to In Progress in RBAC AuthZ Board Oct 28, 2025
@BryanttV BryanttV force-pushed the bav/load-filtered-policy-in-roles-and-perm-views branch 2 times, most recently from 55c4dbd to f15ab79 Compare October 28, 2025 19:21
@BryanttV
Copy link
Copy Markdown
Contributor Author

Regarding these changes, my only concern is with the permissions/validate/me endpoint, since loading the entire policy every time the request is made might not be the best option, considering it will be the most heavily used endpoint. For the other endpoints, I don’t think there’s a problem, as they won’t handle a large number of requests, but it's important to have the most up-to-date policies at the time.

What do you think? @mariajgrimaldi @bmtcril

@BryanttV BryanttV marked this pull request as ready for review October 29, 2025 00:51
@mariajgrimaldi
Copy link
Copy Markdown
Member

I don't think we should load the policies in the permissions/validate/me, what would be the consequences of waiting for the auto loader instead?

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.

LGTM

@mariajgrimaldi mariajgrimaldi moved this from In Progress to Ready for review in RBAC AuthZ Board Oct 29, 2025
@mariajgrimaldi mariajgrimaldi added the FC Relates to an Axim Funded Contribution project label Oct 29, 2025
@BryanttV BryanttV force-pushed the bav/load-filtered-policy-in-roles-and-perm-views branch from 8759e3e to 7c298c7 Compare October 29, 2025 14:06
@bmtcril
Copy link
Copy Markdown
Contributor

bmtcril commented Oct 29, 2025

Oops, I missed the discussion on /validate/me I agree that we shouldn't reload for that, otherwise there's no point in the caching. I think the only effect of this is what we already expect from the caching - it may take a few seconds for someone's permissions to be updated after a change, which is a fairly common situation on large systems.

@BryanttV BryanttV force-pushed the bav/load-filtered-policy-in-roles-and-perm-views branch from 1386ff7 to 91e9fb9 Compare October 29, 2025 17:57
@mphilbrick211 mphilbrick211 moved this from Needs Triage to In Eng Review in Contributions Oct 29, 2025
@rodmgwgu
Copy link
Copy Markdown
Contributor

I also agree that we shouldn't reload the policies in permissions/validate/me for performance reasons. Ideally this endpoint should have some kind of caching.

@BryanttV BryanttV force-pushed the bav/load-filtered-policy-in-roles-and-perm-views branch from ba0b8f9 to d2c70b7 Compare October 30, 2025 13:41
@BryanttV
Copy link
Copy Markdown
Contributor Author

Hi! According to my local tests, the validate/me endpoint has a strange behavior, as the policy loaded in memory by the enforcer appears to be cleared at times, resulting in incorrect permission validation, indicating that the user does not have permissions even though they are present in the DB.

The most immediate solution is to perform a hard load in the validate/me view before enforcement. This would be a temporary solution while we investigate in depth the reasons behind the issue and come up with a more efficient approach.

@mariajgrimaldi @bmtcril @rodmgwgu

@mariajgrimaldi mariajgrimaldi merged commit e374fbf into openedx:main Oct 30, 2025
14 checks passed
@github-project-automation github-project-automation Bot moved this from In Eng Review to Done in Contributions Oct 30, 2025
@github-project-automation github-project-automation Bot moved this from Ready for review to Done in RBAC AuthZ Board Oct 30, 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). 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.

6 participants