Skip to content

Commit

Permalink
fix: add setting override
Browse files Browse the repository at this point in the history
  • Loading branch information
luisfelipec95 committed Mar 5, 2024
1 parent c5ba9a5 commit 34e4606
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lms/djangoapps/courseware/tests/test_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions lms/djangoapps/discussion/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2280,14 +2280,17 @@ 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()
self.user = UserFactory.create()
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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions lms/djangoapps/discussion/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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")

Expand Down
7 changes: 6 additions & 1 deletion openedx/core/djangoapps/discussions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)

0 comments on commit 34e4606

Please sign in to comment.