From c556bc583f6ce8225fde9432e82de6385ac23f47 Mon Sep 17 00:00:00 2001 From: Adam Butterworth Date: Tue, 28 Jan 2020 11:50:49 -0500 Subject: [PATCH 1/3] Links in courseware iframed in MFEs navigate parent window --- lms/envs/common.py | 1 + lms/envs/devstack.py | 3 +++ lms/envs/production.py | 1 + lms/templates/courseware/courseware-chromeless.html | 12 ++++++++++++ 4 files changed, 17 insertions(+) diff --git a/lms/envs/common.py b/lms/envs/common.py index a7b9c8fd8f5b..72b0100d938a 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -3755,6 +3755,7 @@ def _make_locale_paths(settings): # pylint: disable=missing-docstring ORDER_HISTORY_MICROFRONTEND_URL = None ACCOUNT_MICROFRONTEND_URL = None PROGRAM_MANAGER_MICROFRONTEND_URL = None +LEARNING_MICROFRONTEND_URL = None ############### Settings for the ace_common plugin ################# ACE_ENABLED_CHANNELS = ['django_email'] diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index 8670c3c68904..a9aca7b837e0 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -293,3 +293,6 @@ def should_show_debug_toolbar(request): EDXNOTES_INTERNAL_API = 'http://edx.devstack.edxnotesapi:18120/api/v1' EDXNOTES_CLIENT_NAME = 'edx_notes_api-backend-service' + +############## Settings for Microfrontends ######################### +LEARNING_MICROFRONTEND_URL = 'http://localhost:2000/' diff --git a/lms/envs/production.py b/lms/envs/production.py index 2e54a4b95430..b152be49f2c7 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -1133,6 +1133,7 @@ def get_env_setting(setting): PROFILE_MICROFRONTEND_URL = ENV_TOKENS.get('PROFILE_MICROFRONTEND_URL', PROFILE_MICROFRONTEND_URL) ORDER_HISTORY_MICROFRONTEND_URL = ENV_TOKENS.get('ORDER_HISTORY_MICROFRONTEND_URL', ORDER_HISTORY_MICROFRONTEND_URL) ACCOUNT_MICROFRONTEND_URL = ENV_TOKENS.get('ACCOUNT_MICROFRONTEND_URL', ACCOUNT_MICROFRONTEND_URL) +LEARNING_MICROFRONTEND_URL = ENV_TOKENS.get('LEARNING_MICROFRONTEND_URL', LEARNING_MICROFRONTEND_URL) ############### Settings for edx-rbac ############### SYSTEM_WIDE_ROLE_CLASSES = ENV_TOKENS.get('SYSTEM_WIDE_ROLE_CLASSES') or SYSTEM_WIDE_ROLE_CLASSES diff --git a/lms/templates/courseware/courseware-chromeless.html b/lms/templates/courseware/courseware-chromeless.html index 05928daad96f..956bf15f6510 100644 --- a/lms/templates/courseware/courseware-chromeless.html +++ b/lms/templates/courseware/courseware-chromeless.html @@ -45,6 +45,18 @@ ${HTML(fragment.head_html())} + + <%block name="js_extra"> From 7cbcaecb5faae10b84b58c1f274375d76eb969ec Mon Sep 17 00:00:00 2001 From: Adam Butterworth Date: Tue, 28 Jan 2020 15:02:46 -0500 Subject: [PATCH 2/3] Update courseware-chromeless.html --- lms/templates/courseware/courseware-chromeless.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lms/templates/courseware/courseware-chromeless.html b/lms/templates/courseware/courseware-chromeless.html index 956bf15f6510..5e7d1fd4fe8a 100644 --- a/lms/templates/courseware/courseware-chromeless.html +++ b/lms/templates/courseware/courseware-chromeless.html @@ -53,7 +53,9 @@ if (window !== window.parent) { var learningAppReferrer = "${settings.LEARNING_MICROFRONTEND_URL}"; if (document.referrer === learningAppReferrer) { - document.write(''); + var baseElement = document.createElement('base'); + baseElement.setAttribute('target', '_parent'); + document.head.appendChild(baseElement); } } From 3e94a49f31e54f37108ca41bd442f47d85eb4928 Mon Sep 17 00:00:00 2001 From: Adam Butterworth Date: Tue, 28 Jan 2020 15:05:24 -0500 Subject: [PATCH 3/3] Update courseware-chromeless.html --- lms/templates/courseware/courseware-chromeless.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/templates/courseware/courseware-chromeless.html b/lms/templates/courseware/courseware-chromeless.html index 5e7d1fd4fe8a..c9a9cb2e43ad 100644 --- a/lms/templates/courseware/courseware-chromeless.html +++ b/lms/templates/courseware/courseware-chromeless.html @@ -51,7 +51,7 @@ // then add a base tag in the head (of the iframe document) to force links // in this iframe to navigate the parent window. if (window !== window.parent) { - var learningAppReferrer = "${settings.LEARNING_MICROFRONTEND_URL}"; + var learningAppReferrer = "${settings.LEARNING_MICROFRONTEND_URL | n, js_escaped_string}"; if (document.referrer === learningAppReferrer) { var baseElement = document.createElement('base'); baseElement.setAttribute('target', '_parent');