Skip to content

Require library view access to preview, accept, or ignore library updates #670

In review
openedx/openedx-platform
#39470

Description

@BryanttV

Description

Course and library permissions are managed separately, so a user can hold course permissions for library updates without being allowed to view the source library. As defined in the Library updates in Authoring product proposal, previewing, accepting, or ignoring an update must require permission to view the source library, in addition to the relevant course permission. This applies library access rules consistently and removes the authorization path through course references.

Current Behavior

Action Is library view access enforced?
Preview (container, container children, block metadata, block embed) Not always. openedx/openedx-platform#39107 grants access through the course when the request includes a downstream_block_id whose upstream link points to the requested resource, and the user has courses.view_library_updates in that course.
Accept (POST /api/contentstore/v2/downstreams/{usage_key}/sync) Yes, since the revert in openedx/openedx-platform#39336. A denied block sync is reported as an invalid upstream (400), while the container sync raises a permission error.
Ignore (DELETE /api/contentstore/v2/downstreams/{usage_key}/sync) No. Only courses.manage_library_updates is checked.

The course-based preview access trusts the upstream link stored in the course. That link can be set through course content, so it does not prove that the user is allowed to read the library item. See this review discussion.

Expected Behavior

Action Required permissions
Preview an update Permission to view the source library. The course-level courses.view_library_updates permission no longer grants access to library content.
Accept an update courses.manage_library_updates and permission to view the source library
Ignore an update courses.manage_library_updates and permission to view the source library

"Permission to view the source library" means CAN_VIEW_THIS_CONTENT_LIBRARY, which already covers AuthZ. It applies whether or not AuthZ course authoring is enabled for the course.

Users without library access can still view the content already incorporated into the course and can still see that updates are available. The course keeps its current version until an authorized user accepts the update.

So that the frontend can show the right actions, the downstreams summary (GET /api/contentstore/v2/downstreams/{course_key}/summary) reports for each source library whether the current user can view it:

{
  "upstream_context_key": "lib:Org:Lib",
  "can_view_upstream_library": false
}

Acceptance Criteria

Preview

Accept and ignore

  • POST and DELETE on /api/contentstore/v2/downstreams/{usage_key}/sync require both courses.manage_library_updates and permission to view the source library.
  • Both methods return 403 when the user can manage library updates in the course but cannot view the source library, for components and for containers.
  • A rejected request does not modify the course. In particular, a rejected accept of a video component does not delete its transcripts, and a rejected ignore does not record a declined version.
  • Users with both permissions can accept and ignore updates as before.

Library access in the summary

  • Each item in the downstreams summary response includes a boolean can_view_upstream_library for the current user. The existing fields do not change.
  • The value is based on the same rule that is enforced for preview, accept, and ignore, including access granted by AuthZ, public read, and legacy library permissions.
  • The value is false if the source library no longer exists, and the request does not fail.
  • The API documentation of the endpoint includes the new field.

Unchanged behavior

  • The downstreams list, the downstreams summary, and the upstream link information of course blocks still report available updates to users without library access, subject to their existing course permission checks.
  • Course content that was already incorporated from a library remains viewable to users who can view the course.

Tests

  • Tests cover preview, accept, and ignore for users with and without library view access, for components and containers, with AuthZ course authoring enabled and disabled.
  • Tests cover can_view_upstream_library for users with and without library view access, including a course that uses both accessible and restricted libraries.

Out of Scope

Technical Notes

  • cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py: SyncFromUpstreamView and _load_accessible_block. The POST handler calls clear_transcripts() before the library permission is checked, so the check must happen first.
  • cms/lib/xblock/upstream_sync.py: decline_sync() performs no library permission check.
  • cms/lib/xblock/upstream_sync_block.py (_load_upstream_block) turns PermissionDenied into BadUpstream, which the view returns as 400.
  • cms/lib/xblock/upstream_sync_container.py: sync_from_upstream_container() already requires CAN_VIEW_THIS_CONTENT_LIBRARY.
  • DownstreamSummaryView and PublishableEntityLinksSummarySerializer (cms/djangoapps/contentstore/rest_api/v2/serializers/downstreams.py): the summary is already grouped by library, so the permission only needs to be checked once per library.
  • Bypass call sites:
    • openedx/core/djangoapps/authz/decorators.py
    • openedx/core/djangoapps/content_libraries/rest_api/containers.py
    • openedx/core/djangoapps/content_libraries/rest_api/blocks.py
    • openedx/core/djangoapps/xblock/rest_api/views.py
  • The legacy Studio preview modal still sends downstream_block_id. It does not need to change, since the parameter will have no effect.
  • Library asset URLs (/library_assets/component_versions/...) already require library view access, so they need no change.

Related Issues

This change supersedes the earlier approach of granting library access through course permissions:

Metadata

Metadata

Assignees

Labels

willow

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions