Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bypass access checks when populating course blocks cache #35655

Merged

Conversation

asadali145
Copy link
Contributor

@asadali145 asadali145 commented Oct 16, 2024

Description

This PR fixes an issue with the course blocks cache when cache is invalid/does not exist for a course.

The details can be found in this discussion post. Here is the summary:

Let's assume that there are 2 types of Enrollment Track Groups: Audit and Verified.

  • Some of the Units are only accessible to the Verified Learners.
  • Course block cache is empty and an Audit learner accesses the course.
  • when populating the cache, we check for user access.
  • Audit learners do not have access to content in a specific unit. Such content blocks i.e. problem blocks won't be returned in this case. Resulting in an inconsistent cache for the verified learners.
  • When a Verified learner accesses the course when the cache is populated using the Audit access, it will result in an inconsistent outline, progress page, and instr

Useful information to include:

  • This change impacts Learners and Instructors

Screenshots

  • Outline for Audit Learner:
    outline_audit

  • Outline for Verified Learner Before (Inconsistent Course Blocks Cache):
    outline_verified_before

  • Outline for Verified Learner After (Cache is consistent):
    outline_verified_after

  • Old Progress Page before (With Inconsistent Cache):
    old_progress_before

  • Old Progress Page After (With Consistent Cache):
    old_progress_after

  • New Progress Page before (With Inconsistent Cache):
    new_progress_before

  • New Progress Page After (With Consistent Cache):
    new_progress_after

Supporting information

https://discuss.openedx.org/t/course-block-cache-resulting-in-inconsistent-course-outline-progress-page-and-instructor-reports/13379
https://discuss.openedx.org/t/debugging-persistent-grade-issues/11155

Testing instructions

NOTE: Originally, these steps were performed in Devstack. These involve restarting the cache instances. If you can restart the cache instances with Tutor and Live environment then these should be good enough to reproduce/test. At some point, these steps mention that if you are using Tutor or a Live Environment, then you will need a different configuration to avoid restarting the cache.

  • Create a new Course
    • Go to the Open edX Studio
    • Create a new course
      • Name: Test Course Blocks Cache
      • Fill in other details like Organization, Course Number, and Run.
    • Go to Django Admin /admin/course_modes/coursemode/ and Create Course modes
      • Create Audit Mode
        • Select the newly created course
          • Select Audit mode
          • Title: Audit
      • Create Verified Mode
        • Select the newly created course
          • Select Verified mode
          • Title: Verified
          • Price: 1
    • Open the Course in the Open edX Studio
      • From the tools dropdown menu, select import
      • Use this linked file to import the course content.
      • Download and Select the above file and start the import.
      • You should see an updated Course Outline with 2 Sections Homework, and Proctored Exam
      • NOTE: Access to the Proctored Exam is limited to the Verified track only.
  • For TUTOR and Any other Live environment where we cannot restart/clear the cache:
    • The Default Course Blocks Cache Timeout is 1 Day, for testing, we will set it to 1 minute.
      • Go to /admin/block_structure/blockstructureconfiguration/
      • Add a new entry with these Values
        • Enabled: True
        • Num versions to keep: 1
        • Cache timeout in seconds: 60
      • You can verify the timeout in the shell. Run the below snippet:
from openedx.core.djangoapps.content.block_structure.config.models import BlockStructureConfiguration
from openedx.core.djangoapps.content.block_structure import config
BlockStructureConfiguration.current()
config.cache_timeout_in_seconds()
- OUTPUT Should be 60 for the last 2 lines.
  • It would be better to restart the Cache instances at this point.
    • This is recommended due to the multi-level caching of blocks and block cache configurations.
  • Create 2 new Users.
    • Enroll the first User in the Audit Mode.
    • Enroll the second User in the Verified Mode.
    • You can enroll the User and change the enrollment status in Django Admin.
      • Enable student.courseenrollment_admin at /admin/waffle/switch/
    • Now you can access enrollments at /admin/student/courseenrollment/
    • Open the second User enrollment and change the Mode to verified
  • If you are using TUTOR or a Live environment:
    • Now wait for about 2minutes to let the cache expire
  • If you are using Devstack then restart the Memcache instance.
  • Open 2 windows and login with both users in separate windows.
  • Visit the course outline with the Audit User.
  • The Outline will be like:
    outline_audit
  • Now visit the Outline with the verified. If TUTOR or Live Env, Try to do this quickly as the Cache might expire before you visit with the Verified Learner.
    • If the course blocks cache is used, you should see the same outline for the Verified User:
      outline_verified_before
  • If Tutor or Live Env, Now wait for 2 minutes, and reload the outline for the Verified Learner
  • The Outline should be; You will see the number of questions.
    outline_verified_after

PS: These steps are also documented in https://docs.google.com/document/d/15UBgv8likenypTU2WmEx3uQlJlj4kLwFU_4ZhiFO-yI/edit?usp=sharing.

Deadline

ASAP

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

Thanks for the pull request, @asadali145!

What's next?

Please work through the following steps to get your changes 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.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/wg-maintenance-edx-platform. Tag them in a comment and let them know that your changes are ready for review.

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.

Copy link
Contributor

@ziafazal ziafazal left a comment

Choose a reason for hiding this comment

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

@asadali145 thanks for making these changes. Could you please add some unit tests to support these?

@@ -99,7 +106,15 @@ def get_collected(self):
BlockStructureTransformers.verify_versions(block_structure)

except (BlockStructureNotFound, TransformerDataIncompatible):
block_structure = self._update_collected()
if user:
Copy link
Contributor

@ziafazal ziafazal Oct 17, 2024

Choose a reason for hiding this comment

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

I think we check if user has known attribute and its value is True

Suggested change
if user:
if user and getattr(user, 'known', True):

@mphilbrick211 mphilbrick211 added the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Oct 21, 2024
@asadali145 asadali145 force-pushed the asad/bypass-access-checks-when-populating-cache branch from b7cd161 to ea33dba Compare October 23, 2024 09:59
@asadali145 asadali145 requested a review from ziafazal October 23, 2024 10:10
@asadali145 asadali145 force-pushed the asad/bypass-access-checks-when-populating-cache branch from 0413c34 to 9ed41b0 Compare October 31, 2024 18:22
Copy link
Contributor

@ziafazal ziafazal left a comment

Choose a reason for hiding this comment

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

LGTM :

@pdpinch
Copy link
Contributor

pdpinch commented Nov 1, 2024

Thanks for the review @ziafazal. Is there anyone else that you think should review or test this? Do you want to merge it, or shall I (not on a Friday, in either case).

@ziafazal
Copy link
Contributor

ziafazal commented Nov 4, 2024

Thanks for the review @ziafazal. Is there anyone else that you think should review or test this? Do you want to merge it, or shall I (not on a Friday, in either case)

I don't think we have some one with the context to review it. If you think you can find some one it would be great otherwise we are good to merge.

@pdpinch pdpinch merged commit 5d1566c into openedx:master Nov 6, 2024
49 checks passed
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reviewer assigned PR needs to be (re-)assigned a new reviewer 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