Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create a new setting USE_DISCUSSIONS_MFE #809

Merged
merged 9 commits into from
Mar 7, 2024
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
3 changes: 2 additions & 1 deletion lms/djangoapps/discussion/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE
from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url
from openedx.core.djangoapps.discussions.utils import use_discussions_mfe
from xmodule.tabs import TabFragmentViewMixin

import lms.djangoapps.discussion.django_comment_client.utils as utils
Expand Down Expand Up @@ -44,7 +45,7 @@ def is_enabled(cls, course, user=None):
@property
def link_func(self):
def _link_func(course, reverse_func):
if ENABLE_DISCUSSIONS_MFE.is_enabled(course.id):
if ENABLE_DISCUSSIONS_MFE.is_enabled(course.id) and use_discussions_mfe(course.org):
return get_discussions_mfe_url(course_key=course.id)
return reverse('forum_form_discussion', args=[str(course.id)])

Expand Down
10 changes: 7 additions & 3 deletions lms/djangoapps/discussion/rest_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
from lms.djangoapps.discussion.toggles_utils import reported_content_email_notification_enabled
from lms.djangoapps.discussion.views import is_privileged_user
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, DiscussionTopicLink, Provider
from openedx.core.djangoapps.discussions.utils import get_accessible_discussion_xblocks
from openedx.core.djangoapps.discussions.utils import (
get_accessible_discussion_xblocks,
use_discussions_mfe
)
from openedx.core.djangoapps.django_comment_common import comment_client
from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment
from openedx.core.djangoapps.django_comment_common.comment_client.course import (
Expand Down Expand Up @@ -1351,8 +1354,9 @@ def _handle_abuse_flagged_field(form_value, user, cc_content, request):
if form_value:
cc_content.flagAbuse(user, cc_content)
track_discussion_reported_event(request, course, cc_content)
if ENABLE_DISCUSSIONS_MFE.is_enabled(course_key) and reported_content_email_notification_enabled(
course_key):
if ENABLE_DISCUSSIONS_MFE.is_enabled(course_key) and use_discussions_mfe(
course.org) and reported_content_email_notification_enabled(
course_key):
if cc_content.type == 'thread':
thread_flagged.send(sender='flag_abuse_for_thread', user=user, post=cc_content)
else:
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_DISCUSSION_MFE_ENABLED = settings.FEATURES.copy()
FEATURES_WITH_DISCUSSION_MFE_ENABLED['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")
@override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url", FEATURES=FEATURES_WITH_DISCUSSION_MFE_ENABLED)
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")
@override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url", FEATURES=FEATURES_WITH_DISCUSSION_MFE_ENABLED)
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")
@override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url", FEATURES=FEATURES_WITH_DISCUSSION_MFE_ENABLED)
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: 6 additions & 4 deletions lms/djangoapps/discussion/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
available_division_schemes,
get_discussion_categories_ids,
get_divided_discussions,
get_group_names_by_id
get_group_names_by_id,
use_discussions_mfe
)
from openedx.core.djangoapps.django_comment_common.models import (
FORUM_ROLE_ADMINISTRATOR,
Expand Down Expand Up @@ -273,7 +274,7 @@ def redirect_forum_url_to_new_mfe(request, course_id):
discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key)

redirect_url = None
if discussions_mfe_enabled:
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 @@ -333,7 +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
if discussions_mfe_enabled:

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 @@ -653,7 +655,7 @@ def user_profile(request, course_key, user_id):
})
else:
discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key)
if discussions_mfe_enabled:
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
21 changes: 21 additions & 0 deletions openedx/core/djangoapps/discussions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
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 @@ -191,3 +193,22 @@ def get_course_division_scheme(course_discussion_settings: CourseDiscussionSetti
):
division_scheme = CourseDiscussionSettings.NONE
return division_scheme


def use_discussions_mfe(org) -> bool:
"""
Checks with the org if the tenant enables the
Discussions MFE.
Returns:
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", ENABLE_MFE_FOR_TESTING or False
)

return bool(use_discussions)
Loading