Skip to content

Commit

Permalink
fix: prevent the 'static/' prefix from getting stripped in asset refe…
Browse files Browse the repository at this point in the history
…rences
  • Loading branch information
ormsbee committed Sep 28, 2024
1 parent c2e1d24 commit 55e7efc
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,30 @@ def _lookup_asset_url(self, block: XBlock, asset_path: str) -> str | None: # py
'library-assets',
kwargs={
'component_version_uuid': component_version.uuid,
'asset_path': asset_path,

# The standard XBlock "static/{asset_path}"" substitution
# strips out the leading "static/" part because it assumes that
# all files will exist in a flat namespace. Learning Core treats
# directories differently, and there may one day be other files
# that are not meant to be externally downloadable at the root
# (e.g. LaTeX source files or graders).
#
# So the transformation looks like this:
#
# 1. The Learning Core ComponentVersion has an asset stored as
# "static/test.png".
# 1. The original OLX content we store references
# "/static/test.png" or "static/test.png".
# 2. The ReplaceURLService XBlock runtime service invokes
# static_replace and strips out "/static/".
# 3. The method we're in now is invoked with a static_path of
# just "test.png", because that's the transformation that
# works for ModuleStore-based courses.
# 4. This method then builds a URL that adds the "static/"
# prefix back when creating the URL.
#
# Which is a very long explanation for why we're re-adding the
# "static/" to the asset path below.
'asset_path': f"static/{asset_path}",
}
)

0 comments on commit 55e7efc

Please sign in to comment.