feat: split read vs write authz checks for library updates - #39009
feat: split read vs write authz checks for library updates#39009wgu-taylor-payne wants to merge 1 commit into
Conversation
|
Thanks for the pull request, @wgu-taylor-payne! 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. DetailsWhere 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. |
0ffca0e to
bc06509
Compare
bc06509 to
ddc8f71
Compare
ddc8f71 to
f1dac98
Compare
Use COURSES_VIEW_LIBRARY_UPDATES for read access (list/summary endpoints) and COURSES_MANAGE_LIBRARY_UPDATES for write access (sync/decline). Course Auditors can now view library update status in read-only mode while only Editors+ can sync or decline updates. Updates DownstreamListView, DownstreamSummaryView, and _load_accessible_block to use authz permissions with legacy fallback. ENG45-712
f1dac98 to
2d48695
Compare
| if not user_has_course_permission( | ||
| request.user, | ||
| COURSES_VIEW_COURSE.identifier, | ||
| COURSES_VIEW_LIBRARY_UPDATES.identifier, |
There was a problem hiding this comment.
Out of curiosity. Why is this part of the changes?
There was a problem hiding this comment.
My understanding is that previously, we always allowed anyone with view course permissions to see the available library updates, now we want to restrict it to only people with the view library updates permission, so this would be correct to include in these changes.
68b9dea to
2d48695
Compare
| if not has_studio_read_access(user, usage_key.context_key): | ||
|
|
||
| context_key = usage_key.context_key | ||
| if not isinstance(context_key, CourseKey): |
There was a problem hiding this comment.
Are you sure this function will always be used for course keys? Given the description, it seems this is used for loading XBlocks, so this would break that functionality.
Perhaps we should conditionally test for different permissions depending if it's a course or something else, or understand if this will ever used to check for courses or not.
BryanttV
left a comment
There was a problem hiding this comment.
Thanks for the PR! @wgu-taylor-payne
I've been testing the GET endpoints, and they are working correctly for the different roles (Course Auditor/Course Editor).
However, for the functionality to work completely, we still need to work on:
- The GET endpoint (http://meilisearch.local.openedx.io:7700/multi-search) currently doesn't validate RBAC permissions. This will be addressed in the issue you reported: openedx/openedx-authz#417
- The POST endpoint
/api/contentstore/v2/downstreams/{usage_key}/sync: Although this PR updates the XBlock loading step to use RBAC, it subsequently validates whether the user has permissions for the library being synced. It shouldn't work this way. Users with the Course Admin/Staff/Editor role should be able to sync library changes within their assigned courses simply by validating thecourses.manage_library_updatespermission. This will be addressed in this issue: openedx/openedx-authz#419
I think we can merge this PR and open additional ones related to the other tasks. What do you think, @rodmgwgu?
I would like to wait for @wgu-taylor-payne to confirm if validating for course keys only in _load_accessible_block is correct, as otherwise it could break other code. |
Description
Updates the downstream sync v2 endpoints to use
courses.view_library_updatesfor read access (list/summary) andcourses.manage_library_updatesfor write access (sync/decline).Previously, the list endpoint used
has_studio_read_access(legacy only, no authz integration), and the sync/decline endpoints usedhas_studio_write_access. This meant Course Auditors were blocked from even viewing library update status. Per the design in openedx/openedx-authz#283, auditors should see the library updates page in read-only mode.User roles impacted: Course Auditor — can now view (but not sync/decline) library updates when authz is enabled.
Changes:
cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py:DownstreamListView.get: UseCOURSES_VIEW_LIBRARY_UPDATESfor course-filtered requestsDownstreamSummaryView.get: UseCOURSES_VIEW_LIBRARY_UPDATESinstead ofCOURSES_VIEW_COURSE_load_accessible_block: UseCOURSES_MANAGE_LIBRARY_UPDATESfor write,COURSES_VIEW_LIBRARY_UPDATESfor readhas_studio_read_access/has_studio_write_accessimportsRollback: Gated behind
AUTHZ_COURSE_AUTHORING_FLAG— disabling the flag triggers legacy fallback viauser_has_course_permission.Supporting information
courses.view_library_updatesenforcement in openedx-platform openedx-authz#398Testing instructions
AUTHZ_COURSE_AUTHORING_FLAGfor a course with library-linked componentscourse_auditorroleGET /api/contentstore/v2/downstreams/?course_id={course_id}→ 200GET /api/contentstore/v2/downstreams/{course_id}/summary→ 200POST /api/contentstore/v2/downstreams/{usage_key}/sync→ 404 (permission denied)course_editor→ sync should succeed (200 or 400 depending on upstream state)Deadline
None
AI Usage
Kiro was used as a development partner throughout this PR. I directed the implementation approach, defined scope, reviewed generated code, and made design decisions — Kiro researched the codebase, wrote the implementation and tests, ran lint/type checks, and iterated on fixes. I verified the changes manually against a local Tutor dev environment and reviewed the final diffs before submitting.