Skip to content

Commit

Permalink
fix: component asset api views
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Nov 4, 2024
1 parent d0dbb8d commit 7f08c15
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content_libraries/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
path('library_assets/', include([
path(
'component_versions/<uuid:component_version_uuid>/<path:asset_path>',
views.component_version_asset,
views.LibraryComponentAssetView.as_view(),
name='library-assets',
),
path(
'blocks/<usage_v2:usage_key>/<path:asset_path>',
views.component_draft_asset,
views.LibraryComponentDraftAssetView.as_view(),
name='library-draft-assets',
),
])
Expand Down
34 changes: 21 additions & 13 deletions openedx/core/djangoapps/content_libraries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,8 +1163,7 @@ def get(self, request):
return JsonResponse(self.lti_tool_config.get_jwks(), safe=False)


@require_safe
def component_version_asset(request, component_version_uuid, asset_path):
def get_component_version_asset(request, component_version_uuid, asset_path):
"""
Serves static assets associated with particular Component versions.
Expand Down Expand Up @@ -1234,16 +1233,25 @@ def component_version_asset(request, component_version_uuid, asset_path):
)


@require_safe
def component_draft_asset(request, usage_key, asset_path):
"""
Serves the draft version of static assets associated with a Library Component.
@view_auth_classes()
class LibraryComponentAssetView(APIView):
@convert_exceptions
def get(self, request, component_version_uuid, asset_path):
return get_component_version_asset(request, component_version_uuid, asset_path)

See `component_version_asset` for more details
"""
try:
component_version_uuid = api.get_component_from_usage_key(usage_key).versioning.draft.uuid
except ObjectDoesNotExist as exc:
raise Http404() from exc

return component_version_asset(request, component_version_uuid, asset_path)
@view_auth_classes()
class LibraryComponentDraftAssetView(APIView):
@convert_exceptions
def get(self, request, usage_key, asset_path):
"""
Serves the draft version of static assets associated with a Library Component.
See `component_version_asset` for more details
"""
try:
component_version_uuid = api.get_component_from_usage_key(usage_key).versioning.draft.uuid
except ObjectDoesNotExist as exc:
raise Http404() from exc

return get_component_version_asset(request, component_version_uuid, asset_path)

0 comments on commit 7f08c15

Please sign in to comment.