Skip to content

Commit

Permalink
Merge pull request #32912 from openedx/kenclary/TNL-10912
Browse files Browse the repository at this point in the history
fix: fix mako runtime bug with studio_view. TNL-10912
  • Loading branch information
kenclary authored Aug 15, 2023
2 parents 2ea5b1d + af07ab7 commit fa22e01
Showing 1 changed file with 14 additions and 1 deletion.
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

0 comments on commit fa22e01

Please sign in to comment.