Repository navigation
fix: return 403 instead of redirecting from the courseware API for catalog-hidden courses - #39412
AhtishamShahid wants to merge 1 commit into
Conversation
…talog-hidden courses With COURSE_ABOUT_VISIBILITY_PERMISSION = 'see_about_page', a course with catalog_visibility 'none' makes the about-page access check raise CourseAccessRedirect for non-staff users. In the courseware metadata API this escaped as a 302 to the dashboard, which the learning MFE follows cross-origin and fails on. Convert the redirect raised while building CoursewareMeta into a 403 carrying the access error message, matching the course home metadata API. When staff masquerade as a learner, show_courseware_link now returns False instead of redirecting.
|
Thanks for the pull request, @AhtishamShahid! This repository is currently maintained by 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 approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo 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:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Update the status of your PRYour PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate. 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Description
With
COURSE_ABOUT_VISIBILITY_PERMISSION = "see_about_page", a course withcatalog_visibility: nonemakes the about-page access check raiseCourseAccessRedirectfor non-staff users (CatalogVisibilityError, from #38121). #38121 turned this into a 403 in the course home metadata API, butGET /api/courseware/course/<id>still answers with a 302 to/dashboard. The learning MFE follows that redirect, which fails (cross-origin on some deployments), and shows "There was an error loading this course." instead of the restricted-access message.The redirect escapes in two places:
CoursewareMeta.__init__→course_detail(): enrolled learners and anonymous users.CoursewareMeta.show_courseware_link: staff using "View this course as" Learner.course_detailpasses as the real staff user, but this check runs as the masqueraded learner.Changes:
CoursewareInformation.get_objectconverts the redirect into a 403 with the access error's message, the same response as the course home metadata API.show_courseware_linkreturnsFalsewhen the user can't see the about page, instead of redirecting.Roles affected: Learner, Course staff (masquerade).
Testing instructions
COURSE_ABOUT_VISIBILITY_PERMISSION = "see_about_page"in LMS settings.nonefor a course.GET /api/courseware/course/<course_id>.302 → /dashboard.403 {"detail": "This course is not currently accessible. ..."}, the same as/api/course_home/course_metadata/<course_id>.show_courseware_link: false.Tested locally on a Tutor dev stack, with the HTTP calls above and real logins. New unit tests in
CourseApiCatalogVisibilityNoneTestsfail without the fix (302) and pass with it. Thecourseware_apitest suite passes.Screenshots
Course staff, View this course as → Audit, opening a unit in a
catalog_visibility: nonecourse (local Tutor dev stack,COURSE_ABOUT_VISIBILITY_PERMISSION = "see_about_page")./api/courseware/course/→ 302 /dashboard)For an enrolled non-staff learner the page looks the same before and after: the MFE already shows the restricted-access message from the course home metadata 403. Only the courseware API response changes, from 302 to 403.