Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix mako runtime bug with studio_view. TNL-10912 #32912

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion openedx/core/djangoapps/xblock/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class XBlockRuntime(RuntimeShim, Runtime):
block_field_datas: dict[ScopeIds, FieldData | None]
# dict of FieldDataCache objects for XBlock with database-based user state
django_field_data_caches: dict[LearningContextKey, FieldDataCache]
# keep track of view name (student_view, studio_view, etc)
# currently only used to track if we're in the studio_view (see below under service())
view_name: str | None

def __init__(self, system: XBlockRuntimeSystem, user: UserType | None):
super().__init__(
Expand All @@ -114,6 +117,7 @@ def __init__(self, system: XBlockRuntimeSystem, user: UserType | None):
self.user_id = self.user.id
self.block_field_datas = {}
self.django_field_data_caches = {}
self.view_name = None

def handler_url(self, block, handler_name: str, suffix='', query='', thirdparty=False):
"""
Expand Down Expand Up @@ -265,7 +269,13 @@ def service(self, block: XBlock, service_name: str):
deprecated_anonymous_user_id=deprecated_anonymous_student_id
)
elif service_name == "mako":
if self.system.student_data_mode == StudentDataMode.Ephemeral:
# The mako service has a seperate "preview" engine used for views in CMS that mimic LMS views.
# Said engine is only configured for CMS. Therefore, when we are in CMS but not the studio_view,
# we want to use the preview engine. The mako service uses a 'lms.main' namespace to indicate
# the preview engine, and 'main' otherwise.
# For backwards compatibility, we check the student_data_mode (Ephemeral indicates CMS) and the
# view_name for 'studio_view.' self.view_name is set by render() below.
if self.system.student_data_mode == StudentDataMode.Ephemeral and self.view_name != 'studio_view':
return MakoService(namespace_prefix='lms.')
return MakoService()
elif service_name == "i18n":
Expand Down Expand Up @@ -348,6 +358,9 @@ def render(self, block: XBlock, view_name: str, context: dict | None = None):
if (self.user is None or self.user.is_anonymous) and view_name != 'public_view':
raise PermissionDenied

# track this so service() can know
self.view_name = view_name

# We also need to override this method because some XBlocks in the
# edx-platform codebase use methods from builtin_assets.py,
# which create relative URLs (/static/studio/bundles/webpack-foo.js).
Expand Down