From 067ebd79ce8d8d3ab89562f37f742043e62b17ad Mon Sep 17 00:00:00 2001 From: Saad Yousaf Date: Fri, 12 Aug 2022 15:13:06 +0500 Subject: [PATCH] fix: fix inIframe query param for discussion MFE link (#30846) Co-authored-by: SaadYousaf --- .../templates/discussion/discussion_mfe_embed.html | 3 ++- lms/djangoapps/discussion/views.py | 3 ++- openedx/core/djangoapps/discussions/url_helpers.py | 5 ----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/discussion/templates/discussion/discussion_mfe_embed.html b/lms/djangoapps/discussion/templates/discussion/discussion_mfe_embed.html index ffd4725796..3950ce2ed2 100644 --- a/lms/djangoapps/discussion/templates/discussion/discussion_mfe_embed.html +++ b/lms/djangoapps/discussion/templates/discussion/discussion_mfe_embed.html @@ -16,7 +16,8 @@ from openedx.core.djangolib.js_utils import js_escaped_string const mfeUrl = (new URL("${discussions_mfe_url | n, js_escaped_string}")); const iframe = document.querySelector('#discussions-mfe-tab-embed'); let timestamp = "?no-cache=" + Date.now(); - iframe.src = mfeUrl.href + window.location.hash.slice(1) + timestamp; + let showInIframe = "&inIframe=" + "${show_in_iframe | n, js_escaped_string}"; + iframe.src = mfeUrl.href + window.location.hash.slice(1) + timestamp + showInIframe; window.addEventListener("message", (event) => { const payload = event.data.payload; if (event.origin !== mfeUrl.origin) { diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index 0403a4e1b2..de46629458 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -52,7 +52,7 @@ from lms.djangoapps.discussion.toggles import ( ENABLE_DISCUSSIONS_MFE, ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE, ENABLE_DISCUSSIONS_MFE_BANNER, -) + ENABLE_VIEW_MFE_IN_IFRAME) from lms.djangoapps.experiments.utils import get_experiment_user_metadata_context from lms.djangoapps.teams import api as team_api from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url @@ -789,6 +789,7 @@ def _discussions_mfe_context(query_params: Dict, "course_key": course_key, "show_banner": enable_mfe and (is_privileged or ENABLE_DISCUSSIONS_MFE_BANNER.is_enabled()), "discussions_mfe_url": mfe_url, + "show_in_iframe": ENABLE_VIEW_MFE_IN_IFRAME.is_enabled(), } diff --git a/openedx/core/djangoapps/discussions/url_helpers.py b/openedx/core/djangoapps/discussions/url_helpers.py index 1d1d293eec..60b29d9197 100644 --- a/openedx/core/djangoapps/discussions/url_helpers.py +++ b/openedx/core/djangoapps/discussions/url_helpers.py @@ -7,8 +7,6 @@ from urllib.parse import urlencode from django.conf import settings from opaque_keys.edx.keys import CourseKey -from lms.djangoapps.discussion.toggles import ENABLE_VIEW_MFE_IN_IFRAME - def _get_url_with_view_query_params(path: str, view: Optional[str] = None) -> str: """ @@ -30,9 +28,6 @@ def _get_url_with_view_query_params(path: str, view: Optional[str] = None) -> st if view == "in_context": query_params.update({'inContext': True}) - if ENABLE_VIEW_MFE_IN_IFRAME.is_enabled(): - query_params.update({'inIframe': True}) - if query_params: url = f"{url}?{urlencode(query_params)}"