Skip to content

fix: persist Course Editor changes in XBlock studio handlers - #39375

Open
efortish wants to merge 1 commit into
openedx:masterfrom
eduNEXT:ks/issue-598-component-handler-editor-writes
Open

efortish wants to merge 1 commit into
openedx:masterfrom
eduNEXT:ks/issue-598-component-handler-editor-writes

Conversation

@efortish

Copy link
Copy Markdown
Contributor

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 call update_item with the legacy has_course_author_access check. Editors are AuthZ-only (they have no entry in LEGACY_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:

  1. Persist with the AuthZ permission. The save now uses user_has_course_permission(user, COURSES_EDIT_COURSE_CONTENT, course_key, LegacyAuthoringPermission.WRITE). When authz.enable_course_authoring is off for the course, this falls back to has_studio_write_access, which is exactly what has_course_author_access called, so legacy users with write access see no change.

  2. No more silent success. For users without edit permission, the view snapshots the block's (and its asides') explicitly set content, settings and children fields before the handler runs, and compares after:

    • fields changed: respond 403 (nothing was going to be persisted anyway);
    • nothing changed (read-only handlers such as 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

Testing instructions

Automated

New TestComponentHandlerAuthz in cms/djangoapps/contentstore/views/tests/test_block.py, using a small test XBlock with one handler that writes a field and one that only reads:

Case Expected
AuthZ on, Course Editor / Staff / Admin calls a writing handler 200, change persisted
AuthZ on, Course Auditor calls a writing handler 403, nothing persisted
AuthZ on, Course Auditor calls a read-only handler 200
AuthZ off, legacy staff calls a writing handler 200, change persisted
AuthZ off, user with no role calls a writing handler 403, nothing persisted

Without the fix, the Editor case and both 403 cases fail. test_block.py and test_container_page.py pass 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 a drag-and-drop-v2 block:

  1. Create a course with authz.enable_course_authoring enabled through a course override, and add a Drag and Drop component.
  2. Assign one user course_editor and another course_auditor in that course.
  3. As the Editor, call studio_submit with a new display_name.
  4. As the Auditor, call studio_submit with a different display_name, then call expand_static_url.
  5. Repeat 3 on a course with the flag off, using a legacy course staff user, and then a user with no role.
  6. Reload the blocks from the modulestore and check display_name.
Step Before (master) After (this PR)
Editor studio_submit (AuthZ on) 200, not saved 200, saved
Auditor studio_submit (AuthZ on) 200, not saved 403, not saved
Auditor expand_static_url (AuthZ on) 200 200
Legacy staff studio_submit (AuthZ off) 200, saved 200, saved
No role studio_submit (AuthZ off) 200, not saved 403, not saved

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

  • No migrations, no new settings.
  • No frontend changes are needed for the Editor case.

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
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 13, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @efortish!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

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 Nov 13, 2026
@efortish
efortish requested a review from BryanttV November 13, 2026 22:31
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Nov 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

Fix XBlock studio handler silently dropping Course Editor writes

2 participants