Repository navigation
Conversation
_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.
|
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. 🔘 Update the status of your PRYour 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Description
A Course Editor (has
courses.edit_course_contentbut notcourses.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_xblockthen published anyway. So an Editor could:{"publish": "make_public", "metadata": {...}}and publish the block;{"publish": "republish", "metadata": {...}}on a published unit and make the change live right away.The helper is now
_get_xblock_authz_permissionsand returns every permission a request needs;_check_xblock_permissionrequires all of them. When the request carries content:make_public, orrepublishon a block outsideDIRECT_ONLY_CATEGORIESthat already has a published version._save_publishesmirrors the publish logic at the end of_save_xblock.Unchanged:
make_public,republishordiscard_changeswithout content) still require publish permission only.republishon a section, a subsection or a never-published unit) still require edit permission only.authz.enable_course_authoringoff, 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
republishplus 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
openedx-authz.Testing instructions
Automated
cms/djangoapps/contentstore/tests/test_xblock_handler_permissions.py:XBlockHandlerAuthzPermissionsTest:make_publicwith content, andrepublishwith content on a published unit, check both edit and publish.republishwith content on a never-published unit checks edit only. The old test that expected edit only formake_publicwith content was encoding the bug, so it now expects both.XBlockHandlerPublishAuthzTest, with real AuthZ roles:make_publicrepublishon a published unitrepublishon a never-published unitmake_publicWithout 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.pyandviews/tests/test_container_page.pypass.Manual (verified on a local Tutor devstack)
Course with
authz.enable_course_authoringon through a course override, one published unit and one never-published unit, acourse_editoruser and acourse_staffuser. Each case callsPOST /xblock/<unit>over HTTP (LMS login, SSO into Studio) from a clean state, then reads the published branch:make_public+display_nameon the draft unitrepublish+visible_to_staff_onlyon the published unitrepublish+display_nameon the draft unitmake_public+display_nameon the draft unitDeadline
None.
Other information
_check_xblock_permissioncalls the helper. Its return value is only compared againstNone(by_duplicate_xblock), so returning a list doesn't change any caller.