From 6042972235d088f9afdd62f4b5804d0df2d3a3cc Mon Sep 17 00:00:00 2001 From: Kshitij Sobti Date: Thu, 3 Mar 2022 16:49:12 +0530 Subject: [PATCH] fix: Use legacy view for legacy URLs (#30006) If a user navigates to a legacy URL, then use the legacy view for discussions. --- lms/djangoapps/discussion/tests/test_views.py | 5 +++++ lms/djangoapps/discussion/views.py | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lms/djangoapps/discussion/tests/test_views.py b/lms/djangoapps/discussion/tests/test_views.py index 733c1ac346..a9ec1959b2 100644 --- a/lms/djangoapps/discussion/tests/test_views.py +++ b/lms/djangoapps/discussion/tests/test_views.py @@ -1468,6 +1468,11 @@ class UserProfileTestCase(ForumsEnableMixin, UrlResetMixin, ModuleStoreTestCase) def test_html(self, mock_request): self.check_html(mock_request) + @override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url") + @override_waffle_flag(ENABLE_DISCUSSIONS_MFE, True) + def test_html_with_mfe_enabled(self, mock_request): + self.check_html(mock_request) + def test_ajax(self, mock_request): self.check_ajax(mock_request) diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index 79572a129f..84cf8ce119 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -703,7 +703,7 @@ def followed_threads(request, course_key, user_id): raise Http404 # lint-amnesty, pylint: disable=raise-missing-from -def _discussions_mfe_context(query_params: Dict, course_key: CourseKey, user: User) -> Optional[Dict]: +def _discussions_mfe_context(query_params: Dict, course_key: CourseKey, legacy_only_view=False) -> Optional[Dict]: """ Returns the context for rendering the MFE banner and MFE. @@ -718,11 +718,14 @@ def _discussions_mfe_context(query_params: Dict, course_key: CourseKey, user: Us if not mfe_url: return {"show_banner": False, "show_mfe": False} discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key) - show_mfe = False # Show the MFE if the new MFE is enabled, - # or if the legacy experience is not requested via query param - if query_params.get("discussions_experience", "").lower() != "legacy" and discussions_mfe_enabled: - show_mfe = True + # and if the legacy experience is not requested via query param + # and if the current view isn't only that's only supported by the legacy view + show_mfe = ( + query_params.get("discussions_experience", "").lower() != "legacy" + and discussions_mfe_enabled + and not legacy_only_view + ) forum_url = reverse("forum_form_discussion", args=[course_key]) return { "show_mfe": show_mfe, @@ -762,7 +765,9 @@ class DiscussionBoardFragmentView(EdxFragmentView): Fragment: The fragment representing the discussion board """ course_key = CourseKey.from_string(course_id) - mfe_context = _discussions_mfe_context(request.GET, course_key, request.user) + # Force using the legacy view if a user profile is requested or the URL contains a specific topic or thread + force_legacy_view = (profile_page_context or thread_id or discussion_id) + mfe_context = _discussions_mfe_context(request.GET, course_key, force_legacy_view) if mfe_context["show_mfe"]: fragment = Fragment(render_to_string('discussion/discussion_mfe_embed.html', mfe_context)) fragment.add_css(