Repository navigation
Conversation
component_handler decided whether to save a handler's changes with the legacy has_course_author_access check. Course Editors have no legacy role, so for them update_item was skipped and the handler still returned 200: edits to blocks like Drag and Drop or Survey looked saved but were lost. The save now uses user_has_course_permission with courses.edit_course_content (legacy WRITE fallback, which is the same check as before when the AuthZ flag is off). Users without that permission can still call read-only handlers, but if the handler changed any content, settings or children field on the block or its asides, the request now fails with 403 instead of reporting a success that was never saved. Fixes openedx/openedx-authz#598
|
Thanks for the pull request, @efortish! 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. |
Description
When a Course Editor saves an XBlock through a studio handler (Drag and Drop, Poll, Survey, etc.), the handler returns 200 and the UI shows a success message, but nothing is saved. Reloading the editor shows the old values.
component_handler(cms/djangoapps/contentstore/views/component.py) decided whether to callupdate_itemwith the legacyhas_course_author_accesscheck. Editors are AuthZ-only (they have no entry inLEGACY_COURSE_ROLE_EQUIVALENCES), so for them the save was skipped, a warning was logged, and the handler's 200 was still returned.This PR changes two things:
Persist with the AuthZ permission. The save now uses
user_has_course_permission(user, COURSES_EDIT_COURSE_CONTENT, course_key, LegacyAuthoringPermission.WRITE). Whenauthz.enable_course_authoringis off for the course, this falls back tohas_studio_write_access, which is exactly whathas_course_author_accesscalled, so legacy users with write access see no change.No more silent success. For users without edit permission, the view snapshots the block's (and its asides') explicitly set
content,settingsandchildrenfields before the handler runs, and compares after:expand_static_url): keep the current behavior, 200 plus the existing warning log.The snapshot is only taken when the user lacks permission, so the common path is unaffected.
Roles impacted: Course Author. Course Editors can now save XBlocks that use studio handlers. Users without edit permission who send a modifying request get an explicit 403 instead of a fake success.
Behavior change on the legacy path: with the flag off, a user without studio write access whose handler call modifies fields now gets 403 instead of a 200 that saved nothing. This is intentional (it's the same silent data loss) but worth calling out.
Supporting information
openedx-authz.Testing instructions
Automated
New
TestComponentHandlerAuthzincms/djangoapps/contentstore/views/tests/test_block.py, using a small test XBlock with one handler that writes a field and one that only reads:Without the fix, the Editor case and both 403 cases fail.
test_block.pyandtest_container_page.pypass in full (197 tests).Manual (verified on a local Tutor devstack)
Ran against the running LMS and Studio over HTTP (LMS login, then SSO into Studio, then
POST /xblock/<usage_key>/handler/<handler>with Studio's CSRF token, the same calls the authoring MFE makes), on adrag-and-drop-v2block:authz.enable_course_authoringenabled through a course override, and add a Drag and Drop component.course_editorand anothercourse_auditorin that course.studio_submitwith a newdisplay_name.studio_submitwith a differentdisplay_name, then callexpand_static_url.display_name.studio_submit(AuthZ on)studio_submit(AuthZ on)expand_static_url(AuthZ on)studio_submit(AuthZ off)studio_submit(AuthZ off)To check it in the UI: log in as a Course Editor on a course with the flag on, edit a Drag and Drop component, save, and reload the editor. The change should be kept.
Deadline
None.
Other information