Skip to content

Commit

Permalink
feat: add endpoint to get draft version of a library component asset
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Oct 21, 2024
1 parent 23c4276 commit 2a8ac2d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
16 changes: 12 additions & 4 deletions openedx/core/djangoapps/content_libraries/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,17 @@
path('pub/jwks/', views.LtiToolJwksView.as_view(), name='lti-pub-jwks'),
])),
])),
path(
'library_assets/<uuid:component_version_uuid>/<path:asset_path>',
views.component_version_asset,
name='library-assets',
path('library_assets/', include([
path(
'<uuid:component_version_uuid>/<path:asset_path>',
views.component_version_asset,
name='library-assets',
),
path(
'<str:usage_key_str>/<path:asset_path>',
views.component_draft_asset,
name='library-draft-assets',
),
])
),
]
15 changes: 15 additions & 0 deletions openedx/core/djangoapps/content_libraries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,18 @@ def component_version_asset(request, component_version_uuid, asset_path):
content.read_file().chunks(),
headers=redirect_response.headers,
)


@require_safe
def component_draft_asset(request, usage_key_str, asset_path):
"""
Serves the draft version of static assets associated with a Library Component.
See `component_version_asset` for more details
"""
key = LibraryUsageLocatorV2.from_string(usage_key_str)
learning_package = authoring.get_learning_package_by_key(key.lib_key)
component = api.get_component_from_usage_key(key)
publishable_entity = authoring.get_publishable_entity_by_key(learning_package.id, component.key)
component_version_uuid = authoring.get_draft_version(publishable_entity.id).uuid
return component_version_asset(request, component_version_uuid, asset_path)

0 comments on commit 2a8ac2d

Please sign in to comment.