From 34e4606d7b405534d8687d2c6a28b56e873e238a Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Tue, 5 Mar 2024 11:14:57 -0500 Subject: [PATCH] fix: add setting override --- lms/djangoapps/courseware/tests/test_tabs.py | 2 +- lms/djangoapps/discussion/tests/test_views.py | 9 ++++++--- lms/djangoapps/discussion/views.py | 10 ++++------ openedx/core/djangoapps/discussions/utils.py | 7 ++++++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lms/djangoapps/courseware/tests/test_tabs.py b/lms/djangoapps/courseware/tests/test_tabs.py index db59fa373bc..93251e2471d 100644 --- a/lms/djangoapps/courseware/tests/test_tabs.py +++ b/lms/djangoapps/courseware/tests/test_tabs.py @@ -839,7 +839,7 @@ def test_tab_link(self, toggle_enabled): else: expected_link = reverse("forum_form_discussion", args=[str(self.course.id)]) - with self.settings(FEATURES={'ENABLE_DISCUSSION_SERVICE': True}): + with self.settings(FEATURES={'ENABLE_DISCUSSION_SERVICE': True, 'ENABLE_MFE_FOR_TESTING': True}): with override_waffle_flag(ENABLE_DISCUSSIONS_MFE, toggle_enabled): self.check_discussion( tab_list=self.tabs_with_discussion, diff --git a/lms/djangoapps/discussion/tests/test_views.py b/lms/djangoapps/discussion/tests/test_views.py index 58a05b671d0..a3515fe0c5c 100644 --- a/lms/djangoapps/discussion/tests/test_views.py +++ b/lms/djangoapps/discussion/tests/test_views.py @@ -2280,6 +2280,9 @@ class ForumMFETestCase(ForumsEnableMixin, SharedModuleStoreTestCase): Tests that the MFE upgrade banner and MFE is shown in the correct situation with the correct UI """ + features_with_enable_mfe_settings = settings.FEATURES.copy() + features_with_enable_mfe_settings['ENABLE_MFE_FOR_TESTING']=True + def setUp(self): super().setUp() self.course = CourseFactory.create() @@ -2287,7 +2290,7 @@ def setUp(self): self.staff_user = AdminFactory.create() CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id) - @override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url", USE_DISCUSSIONS_MFE_FRONTEND=True) + @override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url", FEATURES=features_with_enable_mfe_settings) def test_redirect_from_legacy_base_url_to_new_experience(self): """ Verify that the legacy url is redirected to MFE homepage when @@ -2302,7 +2305,7 @@ def test_redirect_from_legacy_base_url_to_new_experience(self): expected_url = f"{settings.DISCUSSIONS_MICROFRONTEND_URL}/{str(self.course.id)}" assert response.url == expected_url - @override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url", USE_DISCUSSIONS_MFE_FRONTEND=True) + @override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url", FEATURES=features_with_enable_mfe_settings) def test_redirect_from_legacy_profile_url_to_new_experience(self): """ Verify that the requested user profile is redirected to MFE learners tab when @@ -2317,7 +2320,7 @@ def test_redirect_from_legacy_profile_url_to_new_experience(self): expected_url = f"{settings.DISCUSSIONS_MICROFRONTEND_URL}/{str(self.course.id)}/learners" assert response.url == expected_url - @override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url", USE_DISCUSSIONS_MFE_FRONTEND=True) + @override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url", FEATURES=features_with_enable_mfe_settings) def test_redirect_from_legacy_single_thread_to_new_experience(self): """ Verify that a legacy single url is redirected to corresponding MFE thread url when the ENABLE_DISCUSSIONS_MFE diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index 27e244930e0..d7645bcbf16 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -272,10 +272,9 @@ def redirect_forum_url_to_new_mfe(request, course_id): """ course_key = CourseKey.from_string(course_id) discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key) - course = get_course_with_access(request.user, 'load', course_key) redirect_url = None - if discussions_mfe_enabled and use_discussions_mfe(course.org): + if discussions_mfe_enabled and use_discussions_mfe(course_key.org): mfe_base_url = settings.DISCUSSIONS_MICROFRONTEND_URL redirect_url = f"{mfe_base_url}/{str(course_key)}" return redirect_url @@ -335,8 +334,8 @@ def redirect_thread_url_to_new_mfe(request, course_id, thread_id): course_key = CourseKey.from_string(course_id) discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key) redirect_url = None - course = get_course_with_access(request.user, 'load', course_key) - if discussions_mfe_enabled and use_discussions_mfe(course.org): + + if discussions_mfe_enabled and use_discussions_mfe(course_key.org): mfe_base_url = settings.DISCUSSIONS_MICROFRONTEND_URL if thread_id: redirect_url = f"{mfe_base_url}/{str(course_key)}/posts/{thread_id}" @@ -655,9 +654,8 @@ def user_profile(request, course_key, user_id): 'annotated_content_info': context['annotated_content_info'], }) else: - course = get_course_with_access(request.user, 'load', course_key) discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key) - if discussions_mfe_enabled and use_discussions_mfe(course.org): + if discussions_mfe_enabled and use_discussions_mfe(course_key.org): mfe_base_url = settings.DISCUSSIONS_MICROFRONTEND_URL return redirect(f"{mfe_base_url}/{str(course_key)}/learners") diff --git a/openedx/core/djangoapps/discussions/utils.py b/openedx/core/djangoapps/discussions/utils.py index 8fd8807c2ac..b67ab9127fa 100644 --- a/openedx/core/djangoapps/discussions/utils.py +++ b/openedx/core/djangoapps/discussions/utils.py @@ -18,6 +18,7 @@ from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID, Group # lint-amnesty, pylint: disable=wrong-import-order from xmodule.partitions.partitions_service import PartitionService # lint-amnesty, pylint: disable=wrong-import-order from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from edx_toggles.toggles import SettingDictToggle log = logging.getLogger(__name__) @@ -202,8 +203,12 @@ def use_discussions_mfe(org) -> bool: True if the MFE setting is activated, by default the MFE is deactivated """ + ENABLE_MFE_FOR_TESTING = SettingDictToggle( + "FEATURES", "ENABLE_MFE_FOR_TESTING", default=False, module_name=__name__ + ).is_enabled() + use_discussions = configuration_helpers.get_value_for_org( - org, "USE_DISCUSSIONS_MFE_FRONTEND", False + org, "USE_DISCUSSIONS_MFE_FRONTEND", ENABLE_MFE_FOR_TESTING or False ) return bool(use_discussions)