Skip to content

fix: require publish permission when an xblock save also publishes - #39423

Draft
efortish wants to merge 1 commit into
openedx:masterfrom
eduNEXT:ks/issue-600-publish-permission
Draft

efortish wants to merge 1 commit into
openedx:masterfrom
eduNEXT:ks/issue-600-publish-permission

Conversation

@efortish

Copy link
Copy Markdown
Contributor

Description

A Course Editor (has courses.edit_course_content but not courses.publish_course_content) can publish content through the xblock handler. _get_xblock_authz_permission (cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py) chose the permission from the shape of the request body: a publish action only required publish permission when the body had no content field. With any content field (metadata, data, children, ...) it required edit permission only, and _save_xblock then published anyway. So an Editor could:

  • send {"publish": "make_public", "metadata": {...}} and publish the block;
  • send {"publish": "republish", "metadata": {...}} on a published unit and make the change live right away.

The helper is now _get_xblock_authz_permissions and returns every permission a request needs; _check_xblock_permission requires all of them. When the request carries content:

  • edit permission is always required;
  • publish permission is also required when the save will publish: make_public, or republish on a block outside DIRECT_ONLY_CATEGORIES that already has a published version. _save_publishes mirrors the publish logic at the end of _save_xblock.

Unchanged:

  • Pure publish actions (make_public, republish or discard_changes without content) still require publish permission only.
  • Edits that don't publish (no publish action, or republish on a section, a subsection or a never-published unit) still require edit permission only.
  • With authz.enable_course_authoring off, the legacy check is untouched.

Roles impacted: Course Author. Course Editors can no longer publish through a save request. Roles with publish permission (Course Staff, Course Admin) are not affected.

Open product question (why this is a draft): the authoring MFE sends republish plus metadata from the unit Configure modal (name, visibility, group access) and from component "Manage access". The MFE hides the Publish buttons from Editors, but not those dialogs. With this PR, an Editor who uses them on a published unit gets a 403. The alternative is to save the change as a draft and skip the publish for users without publish permission. I followed the issue's acceptance criteria (any request that publishes requires publish permission) and asked which behavior we want in openedx/openedx-authz#600.

Supporting information

Testing instructions

Automated

cms/djangoapps/contentstore/tests/test_xblock_handler_permissions.py:

  • XBlockHandlerAuthzPermissionsTest: make_public with content, and republish with content on a published unit, check both edit and publish. republish with content on a never-published unit checks edit only. The old test that expected edit only for make_public with content was encoding the bug, so it now expects both.
  • New XBlockHandlerPublishAuthzTest, with real AuthZ roles:
Case Expected
Editor, content + make_public 403, unit stays unpublished
Editor, content + republish on a published unit 403, change not saved
Editor, content + republish on a never-published unit 200, saved, still unpublished
Editor, content only 200
Course Staff, content + make_public 200, published

Without the fix, the two 403 cases and the two "checks both" cases fail. The file (55 tests), views/tests/test_block.py, rest_api/v1/views/tests/test_xblock_viewset.py and views/tests/test_container_page.py pass.

Manual (verified on a local Tutor devstack)

Course with authz.enable_course_authoring on through a course override, one published unit and one never-published unit, a course_editor user and a course_staff user. Each case calls POST /xblock/<unit> over HTTP (LMS login, SSO into Studio) from a clean state, then reads the published branch:

Case Before (master) After (this PR)
Editor, make_public + display_name on the draft unit 200, published 403, not published
Editor, republish + visible_to_staff_only on the published unit 200, live unit hidden from learners 403, live unit unchanged
Editor, republish + display_name on the draft unit 200, not published 200, not published
Course Staff, make_public + display_name on the draft unit 200, published 200, published

Deadline

None.

Other information

  • No migrations, no new settings.
  • Only _check_xblock_permission calls the helper. Its return value is only compared against None (by _duplicate_xblock), so returning a list doesn't change any caller.

_get_xblock_authz_permission picked the permission from the shape of the
request body: a publish action with any content field only required
courses.edit_course_content, but _save_xblock still published. A Course
Editor (edit without publish) could publish by adding a field such as
metadata to a make_public request, or push live changes to a published
unit with republish.

The permission helper now returns every permission the request needs.
Requests that publish (make_public, or republish on a non direct-only
block that already has a published version) require publish permission
in addition to edit permission. Pure publish actions and edits that do
not publish keep their current permission.
@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.

🔘 Update the status of your PR

Your 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:

  • 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.

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: Needs Triage

Development

Successfully merging this pull request may close these issues.

Require publish permission when a save request publishes content

2 participants