Skip to content

fix: create duplicated xblocks in the destination course - #39409

Open
BryanttV wants to merge 1 commit into
masterfrom
fix/reject-cross-course-duplicate
Open

BryanttV wants to merge 1 commit into
masterfrom
fix/reject-cross-course-duplicate

Conversation

@BryanttV

@BryanttV BryanttV commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

POST /xblock/ with a duplicate_source_locator and a parent_locator from two different courses created the new block in the source course (the key was built from the source location) and attached it as a child of a parent in the destination course. The result was a dangling child in the destination course that could not be loaded or deleted. With AuthZ enabled, the source course was also never checked, so a user without access to it could write there.

This PR:

  • Builds the key of the duplicated block in the parent's course (or library) instead of the source's (duplicate_block in cms/djangoapps/contentstore/utils.py). This also fixes duplicating a v1 library block into a course, which returned 200 but created the copy in the library and left the course with a dangling child.
  • Requires view access on the source course in the xblock handler, in both modes (_check_duplicate_source_view_access in xblock_storage_handlers/view_handlers.py):
    • courses.view_course when AuthZ is enabled for the source course.
    • has_studio_read_access otherwise, including v1 libraries, which AuthZ does not cover.
  • Keeps the existing write-access requirement on the destination.

Affected roles: Course Author, Course Staff, Library Author.

Behavior change: A user who can edit the destination but cannot view the source course now gets 403 when duplicating across courses. When AuthZ is enabled, this check was previously skipped.

Supporting Information

Testing Instructions

  1. Create two courses, A (source) and B (destination), each with a section, subsection, unit, and at least one component in A.

  2. Log in as a user with edit access on B and view access on A.

  3. In A, get the usage key of a component. In B, get the usage key of a unit.

  4. Send POST /xblock/ with this body:

    {
      "duplicate_source_locator": "<component usage key in A>",
      "parent_locator": "<unit usage key in B>"
    }
  5. Verify the response is 200 and the returned locator belongs to course B. Verify the component appears in the unit in B, and that A is unchanged.

  6. Remove the user's access to A and repeat step 4. Verify the response is 403, and that nothing was created in A or B.

  7. Grant access to A but remove edit access on B and repeat step 4. Verify the response is 403.

  8. Repeat steps 4 to 7 with AuthZ enabled for the courses (AUTHZ_COURSE_AUTHORING_FLAG), using roles that grant or lack courses.view_course on A and edit permission on B.

  9. Duplicate a block from a v1 library into a course. Verify the copy is created in the course and can be loaded and deleted there.

  10. Run the automated tests:

    pytest cms/djangoapps/contentstore/tests/test_xblock_handler_permissions.py
    pytest cms/djangoapps/contentstore/tests/test_libraries.py -k duplicate_library_block_into_course

Deadline

Willow

Other Information

  • No migrations or new settings.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Nov 19, 2026
@openedx-webhooks

openedx-webhooks commented Nov 19, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @BryanttV!

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 19, 2026
@BryanttV
BryanttV force-pushed the fix/reject-cross-course-duplicate branch 5 times, most recently from 59f49d2 to faa6504 Compare November 19, 2026 23:53
@BryanttV BryanttV changed the title fix: reject duplicating xblocks across courses fix: create duplicated xblocks in the destination course Nov 20, 2026
@BryanttV
BryanttV force-pushed the fix/reject-cross-course-duplicate branch from faa6504 to fe1d708 Compare November 20, 2026 17:03
@BryanttV
BryanttV marked this pull request as ready for review November 20, 2026 17:29
POST /xblock/ with a duplicate_source_locator and a parent_locator from
two different courses created the new block in the source course (the key
is built from the source location) and attached it as a child of a parent
in another course. With authz enabled the source course was never checked,
so a user without access to it could write there, and the destination
course was left with a dangling child that could not be loaded or deleted.

- Build the key of the duplicated block in the parent's course (or
  library) instead of the source's. This also fixes duplicating a v1
  library block into a course, which returned 200 but created the copy in
  the library and left the course with a dangling child.
- Require view access on the source course in the xblock handler in both
  modes: courses.view_course when authz is enabled for the source course,
  has_studio_read_access otherwise (including v1 libraries). Write access
  on the destination is still required as before.

Part of openedx/openedx-authz#602.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

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

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

Duplicating XBlocks across courses creates the block in the source course

2 participants