fix: merge discussions rollout flags (#30989)
* fix: merge discussions rollout flags * test: fixed tests * test: fixed tests
This commit is contained in:
@@ -22,7 +22,7 @@ from lms.djangoapps.courseware.tabs import (
|
||||
)
|
||||
from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase
|
||||
from lms.djangoapps.courseware.views.views import StaticCourseTabView, get_static_tab_fragment
|
||||
from lms.djangoapps.discussion.toggles import ENABLE_VIEW_MFE_IN_IFRAME, ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE
|
||||
from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE
|
||||
from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url
|
||||
from openedx.core.djangolib.testing.utils import get_mock_request
|
||||
from openedx.core.lib.courses import get_course_by_id
|
||||
@@ -758,20 +758,18 @@ class DiscussionLinkTestCase(TabTestCase):
|
||||
expected_can_display_value,
|
||||
discussion_link_in_course="",
|
||||
is_staff=True,
|
||||
is_enrolled=True,
|
||||
in_iframe_flag=True,
|
||||
is_enrolled=True
|
||||
):
|
||||
"""Helper function to verify whether the discussion tab exists and can be displayed"""
|
||||
with patch('common.djangoapps.student.models.CourseEnrollment.is_enrolled') as check_is_enrolled:
|
||||
with override_waffle_flag(ENABLE_VIEW_MFE_IN_IFRAME, in_iframe_flag):
|
||||
self.course.tabs = tab_list
|
||||
self.course.discussion_link = discussion_link_in_course
|
||||
discussion_tab = xmodule_tabs.CourseTabList.get_discussion(self.course)
|
||||
user = self.create_mock_user(is_staff=is_staff, is_enrolled=is_enrolled)
|
||||
check_is_enrolled.return_value = is_enrolled
|
||||
assert ((discussion_tab is not None) and self.is_tab_enabled(discussion_tab, self.course, user) and
|
||||
(discussion_tab.link_func(self.course, reverse)
|
||||
== expected_discussion_link)) == expected_can_display_value
|
||||
self.course.tabs = tab_list
|
||||
self.course.discussion_link = discussion_link_in_course
|
||||
discussion_tab = xmodule_tabs.CourseTabList.get_discussion(self.course)
|
||||
user = self.create_mock_user(is_staff=is_staff, is_enrolled=is_enrolled)
|
||||
check_is_enrolled.return_value = is_enrolled
|
||||
assert ((discussion_tab is not None) and self.is_tab_enabled(discussion_tab, self.course, user) and
|
||||
(discussion_tab.link_func(self.course, reverse)
|
||||
== expected_discussion_link)) == expected_can_display_value
|
||||
|
||||
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": False})
|
||||
def test_explicit_discussion_link(self):
|
||||
@@ -836,17 +834,16 @@ class DiscussionLinkTestCase(TabTestCase):
|
||||
@ddt.data(True, False)
|
||||
def test_tab_link(self, toggle_enabled):
|
||||
if toggle_enabled:
|
||||
expected_link = reverse("forum_form_discussion", args=[str(self.course.id)])
|
||||
else:
|
||||
expected_link = get_discussions_mfe_url(course_key=self.course.id)
|
||||
else:
|
||||
expected_link = reverse("forum_form_discussion", args=[str(self.course.id)])
|
||||
|
||||
with self.settings(FEATURES={'ENABLE_DISCUSSION_SERVICE': True}):
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE, True):
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE, toggle_enabled):
|
||||
self.check_discussion(
|
||||
tab_list=self.tabs_with_discussion,
|
||||
expected_discussion_link=expected_link,
|
||||
expected_can_display_value=True,
|
||||
in_iframe_flag=toggle_enabled,
|
||||
expected_can_display_value=True
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from django.urls import reverse
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
|
||||
from lms.djangoapps.discussion.toggles import ENABLE_VIEW_MFE_IN_IFRAME, ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE
|
||||
from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE
|
||||
from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url
|
||||
from xmodule.tabs import TabFragmentViewMixin
|
||||
|
||||
@@ -44,7 +44,7 @@ class DiscussionTab(TabFragmentViewMixin, EnrolledTab):
|
||||
@property
|
||||
def link_func(self):
|
||||
def _link_func(course, reverse_func):
|
||||
if not ENABLE_VIEW_MFE_IN_IFRAME.is_enabled() and ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE.is_enabled(course.id):
|
||||
if ENABLE_DISCUSSIONS_MFE.is_enabled(course.id):
|
||||
return get_discussions_mfe_url(course_key=course.id)
|
||||
return reverse('forum_form_discussion', args=[str(course.id)])
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ from xmodule.tabs import CourseTabList
|
||||
from lms.djangoapps.course_blocks.api import get_course_blocks
|
||||
from lms.djangoapps.courseware.courses import get_course_with_access
|
||||
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
|
||||
from lms.djangoapps.discussion.toggles import ENABLE_LEARNERS_TAB_IN_DISCUSSIONS_MFE, \
|
||||
ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE
|
||||
from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE, ENABLE_LEARNERS_TAB_IN_DISCUSSIONS_MFE
|
||||
from lms.djangoapps.discussion.toggles_utils import reported_content_email_notification_enabled
|
||||
from lms.djangoapps.discussion.views import is_user_moderator
|
||||
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, DiscussionTopicLink, Provider
|
||||
@@ -1197,7 +1196,7 @@ def _handle_abuse_flagged_field(form_value, user, cc_content):
|
||||
course_key = CourseKey.from_string(cc_content.course_id)
|
||||
if form_value:
|
||||
cc_content.flagAbuse(user, cc_content)
|
||||
if ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE.is_enabled(course_key) and reported_content_email_notification_enabled(
|
||||
if ENABLE_DISCUSSIONS_MFE.is_enabled(course_key) 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)
|
||||
|
||||
@@ -19,7 +19,7 @@ from eventtracking import tracker
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from six.moves.urllib.parse import urljoin
|
||||
|
||||
from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE, ENABLE_VIEW_MFE_IN_IFRAME
|
||||
from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE
|
||||
from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
@@ -208,9 +208,9 @@ def _build_message_context(context): # lint-amnesty, pylint: disable=missing-fu
|
||||
message_context.update(context)
|
||||
thread_author = User.objects.get(id=context['thread_author_id'])
|
||||
comment_author = User.objects.get(id=context['comment_author_id'])
|
||||
show_mfe_post_link = ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE.is_enabled(
|
||||
show_mfe_post_link = ENABLE_DISCUSSIONS_MFE.is_enabled(
|
||||
context['course_id']
|
||||
) and not ENABLE_VIEW_MFE_IN_IFRAME.is_enabled()
|
||||
)
|
||||
post_link = _get_mfe_thread_url(context) if show_mfe_post_link else _get_thread_url(context)
|
||||
|
||||
message_context.update({
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""
|
||||
Tests the forum notification views.
|
||||
"""
|
||||
import itertools
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime
|
||||
@@ -52,12 +51,7 @@ from lms.djangoapps.discussion.django_comment_client.tests.utils import (
|
||||
topic_name_to_id
|
||||
)
|
||||
from lms.djangoapps.discussion.django_comment_client.utils import strip_none
|
||||
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.discussion.toggles import ENABLE_DISCUSSIONS_MFE
|
||||
from lms.djangoapps.discussion.views import _get_discussion_default_topic_id, course_discussions_settings_handler
|
||||
from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory
|
||||
from openedx.core.djangoapps.course_groups.models import CourseUserGroup
|
||||
@@ -1474,11 +1468,6 @@ 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)
|
||||
|
||||
@@ -2296,173 +2285,47 @@ class ForumMFETestCase(ForumsEnableMixin, SharedModuleStoreTestCase):
|
||||
self.staff_user = AdminFactory.create()
|
||||
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id)
|
||||
|
||||
@ddt.data(*itertools.product(("http://test.url", None), (True, False), (True, True)))
|
||||
@ddt.unpack
|
||||
def test_staff_user(self, mfe_url, toggle_enabled, is_staff):
|
||||
"""
|
||||
Verify that the banner is shown with the correct links if the user is staff and the
|
||||
mfe url is configured.
|
||||
"""
|
||||
with override_settings(DISCUSSIONS_MICROFRONTEND_URL=mfe_url):
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE, toggle_enabled):
|
||||
username = self.staff_user.username if is_staff else self.user.username
|
||||
self.client.login(username=username, password='test')
|
||||
response = self.client.get(reverse("forum_form_discussion", args=[self.course.id]))
|
||||
content = response.content.decode('utf8')
|
||||
if mfe_url and toggle_enabled:
|
||||
assert "Welcome to the new discussions experience. Please share your feedback." in content
|
||||
assert "Switch to new experience" not in content
|
||||
else:
|
||||
assert "Welcome to the new discussions experience. Please share your feedback." not in content
|
||||
|
||||
@override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url")
|
||||
@ddt.data(*itertools.product((True, False), ("legacy", "new", None)))
|
||||
@ddt.unpack
|
||||
def test_correct_experience_is_shown(self, toggle_enabled, experience):
|
||||
def test_redirect_from_legacy_base_url_to_new_experience(self):
|
||||
"""
|
||||
Verify that the correct experience is shown based on the MFE toggle flag and the query param.
|
||||
Verify that the legacy url is redirected to MFE homepage when
|
||||
ENABLE_DISCUSSIONS_MFE flag is enabled.
|
||||
"""
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE, toggle_enabled):
|
||||
self.client.login(username=self.staff_user.username, password='test')
|
||||
url = reverse("forum_form_discussion", args=[self.course.id])
|
||||
experience_in_url = ""
|
||||
if experience is not None:
|
||||
experience_in_url = f"discussions_experience={experience}"
|
||||
response = self.client.get(f"{url}?{experience_in_url}")
|
||||
content = response.content.decode('utf8')
|
||||
if toggle_enabled and experience != "legacy":
|
||||
assert "discussions-mfe-tab-embed" in content
|
||||
else:
|
||||
assert "discussions-mfe-tab-embed" not in content
|
||||
|
||||
@override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url")
|
||||
@ddt.data(*itertools.product(("learner", "staff"), (True, False), (True, False)))
|
||||
@ddt.unpack
|
||||
def test_redirect_from_legacy_base_url_to_new_experience(self, user_role, toggle_enabled, in_iframe):
|
||||
"""
|
||||
Verify that the requested is redirected to MFE homepage when
|
||||
ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE flag is enabled. Privileged users will
|
||||
be able to view legacy experience. For learners, if ENABLE_DISCUSSIONS_MFE_BANNER
|
||||
flag is enabled, they will be able to use legacy otherwise they will be redirected
|
||||
to MFE.
|
||||
IF ENABLE_VIEW_IN_IFRAME is disabled then it will redirect to discussions domain
|
||||
"""
|
||||
if user_role == "staff":
|
||||
user = self.staff_user
|
||||
elif user_role == "learner":
|
||||
user = self.user
|
||||
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE, toggle_enabled), \
|
||||
override_waffle_flag(ENABLE_VIEW_MFE_IN_IFRAME, in_iframe):
|
||||
self.client.login(username=user.username, password='test')
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE, True):
|
||||
self.client.login(username=self.user.username, password='test')
|
||||
url = reverse("forum_form_discussion", args=[self.course.id])
|
||||
response = self.client.get(url)
|
||||
content = response.content.decode('utf8')
|
||||
|
||||
if in_iframe:
|
||||
if toggle_enabled:
|
||||
assert "discussions-mfe-tab-embed" in content
|
||||
else:
|
||||
assert "discussions-mfe-tab-embed" not in content
|
||||
else:
|
||||
if toggle_enabled:
|
||||
assert response.status_code == 302
|
||||
expected_url = f"{settings.DISCUSSIONS_MICROFRONTEND_URL}/{str(self.course.id)}"
|
||||
assert response.url == expected_url
|
||||
else:
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 302
|
||||
expected_url = f"{settings.DISCUSSIONS_MICROFRONTEND_URL}/{str(self.course.id)}"
|
||||
assert response.url == expected_url
|
||||
|
||||
@override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url")
|
||||
@ddt.data(*itertools.product(("learner", "staff"), (True, False), (True, False)))
|
||||
@ddt.unpack
|
||||
def test_redirect_from_legacy_profile_url_to_new_experience(self, user_role, toggle_enabled, in_iframe):
|
||||
def test_redirect_from_legacy_profile_url_to_new_experience(self):
|
||||
"""
|
||||
Verify that the requested is redirected to MFE homepage when
|
||||
ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE flag is enabled. This redirect is only
|
||||
for learners and not for privileged users.
|
||||
IF ENABLE_VIEW_IN_IFRAME is disabled then it will redirect to discussions domain
|
||||
Verify that the requested user profile is redirected to MFE learners tab when
|
||||
ENABLE_DISCUSSIONS_MFE flag is enabled
|
||||
"""
|
||||
if user_role == "staff":
|
||||
user = self.staff_user
|
||||
elif user_role == "learner":
|
||||
user = self.user
|
||||
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE, toggle_enabled), \
|
||||
override_waffle_flag(ENABLE_VIEW_MFE_IN_IFRAME, in_iframe):
|
||||
self.client.login(username=user.username, password='test')
|
||||
url = reverse("user_profile", args=[self.course.id, user.id])
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE, True):
|
||||
self.client.login(username=self.user.username, password='test')
|
||||
url = reverse("user_profile", args=[self.course.id, self.user.id])
|
||||
response = self.client.get(url)
|
||||
content = response.content.decode('utf8')
|
||||
|
||||
if in_iframe:
|
||||
if toggle_enabled and user == "learner":
|
||||
assert "discussions-mfe-tab-embed" in content
|
||||
else:
|
||||
assert "discussions-mfe-tab-embed" not in content
|
||||
else:
|
||||
if toggle_enabled:
|
||||
if user_role == "staff":
|
||||
assert "discussions-mfe-tab-embed" not in content
|
||||
else:
|
||||
assert response.status_code == 302
|
||||
expected_url = f"{settings.DISCUSSIONS_MICROFRONTEND_URL}/{str(self.course.id)}/learners"
|
||||
assert response.url == expected_url
|
||||
else:
|
||||
assert "discussions-mfe-tab-embed" not in content
|
||||
assert response.status_code == 302
|
||||
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")
|
||||
@ddt.data(*itertools.product(("learner", "staff"), (True, False), (True, False)))
|
||||
@ddt.unpack
|
||||
def test_correct_experience_for_single_thread_url_for_everyone_flag(self, user_role, toggle_enabled, in_iframe):
|
||||
def test_redirect_from_legacy_single_thread_to_new_experience(self):
|
||||
"""
|
||||
Verify that the correct experience is shown based on the MFE toggle for everyone
|
||||
for Legacy single thread url
|
||||
IF ENABLE_VIEW_IN_IFRAME is disabled then it will redirect to discussions domain
|
||||
Verify that a legacy single url is redirected to corresponding MFE thread url when the ENABLE_DISCUSSIONS_MFE
|
||||
flag is enabled
|
||||
"""
|
||||
if user_role == "staff":
|
||||
user = self.staff_user
|
||||
elif user_role == "learner":
|
||||
user = self.user
|
||||
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE, toggle_enabled), \
|
||||
override_waffle_flag(ENABLE_VIEW_MFE_IN_IFRAME, in_iframe):
|
||||
self.client.login(username=user.username, password='test')
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE, True):
|
||||
self.client.login(username=self.user.username, password='test')
|
||||
url = reverse("single_thread", args=[self.course.id, "test_discussion", "test_thread"])
|
||||
response = self.client.get(url)
|
||||
content = response.content.decode('utf8')
|
||||
if in_iframe:
|
||||
if toggle_enabled and user == "learner":
|
||||
assert "discussions-mfe-tab-embed" in content
|
||||
else:
|
||||
assert "discussions-mfe-tab-embed" not in content
|
||||
else:
|
||||
if toggle_enabled:
|
||||
assert response.status_code == 302
|
||||
expected_url = f"{settings.DISCUSSIONS_MICROFRONTEND_URL}/{str(self.course.id)}/posts/test_thread"
|
||||
assert response.url == expected_url
|
||||
else:
|
||||
assert "discussions-mfe-tab-embed" not in content
|
||||
|
||||
@override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url")
|
||||
@ddt.data(*itertools.product(("legacy", "new"), (True, False)))
|
||||
@ddt.unpack
|
||||
def test_correct_experience_for_learner_banner_flag(self, experience, toggle_enabled):
|
||||
"""
|
||||
Verify that the correct experience is shown based on the MFE toggle for everyone
|
||||
for Legacy single thread url
|
||||
"""
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE, True), \
|
||||
override_waffle_flag(ENABLE_VIEW_MFE_IN_IFRAME, True):
|
||||
with override_waffle_flag(ENABLE_DISCUSSIONS_MFE_BANNER, toggle_enabled):
|
||||
self.client.login(username=self.user.username, password='test')
|
||||
url = reverse("forum_form_discussion", args=[self.course.id])
|
||||
url += f"?discussions_experience={experience}"
|
||||
response = self.client.get(url)
|
||||
content = response.content.decode('utf8')
|
||||
|
||||
if experience == "new":
|
||||
assert "discussions-mfe-tab-embed" in content
|
||||
elif not toggle_enabled and experience == "legacy":
|
||||
assert response.status_code == 302
|
||||
else:
|
||||
assert "discussions-mfe-tab-embed" not in content
|
||||
assert response.status_code == 302
|
||||
expected_url = f"{settings.DISCUSSIONS_MICROFRONTEND_URL}/{str(self.course.id)}/posts/test_thread"
|
||||
assert response.url == expected_url
|
||||
|
||||
@@ -7,23 +7,12 @@ from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag
|
||||
# .. toggle_name: discussions.enable_discussions_mfe
|
||||
# .. toggle_implementation: CourseWaffleFlag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Waffle flag to use the new MFE experience for discussions in the course tab and in-context
|
||||
# .. toggle_description: Waffle flag to use the new MFE experience for discussions in the course tab
|
||||
# .. toggle_use_cases: temporary, open_edx
|
||||
# .. toggle_creation_date: 2021-11-05
|
||||
# .. toggle_target_removal_date: 2022-03-05
|
||||
# .. toggle_target_removal_date: 2022-12-05
|
||||
ENABLE_DISCUSSIONS_MFE = CourseWaffleFlag(f'{WAFFLE_FLAG_NAMESPACE}.enable_discussions_mfe', __name__)
|
||||
|
||||
# .. toggle_name: discussions.enable_discussions_mfe_for_everyone
|
||||
# .. toggle_implementation: CourseWaffleFlag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Waffle flag to use the new MFE experience for discussions in the course tab and in-context
|
||||
# .. toggle_use_cases: temporary, open_edx
|
||||
# .. toggle_creation_date: 2021-04-21
|
||||
# .. toggle_target_removal_date: 2022-03-05
|
||||
ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE = CourseWaffleFlag(
|
||||
f'{WAFFLE_FLAG_NAMESPACE}.enable_discussions_mfe_for_everyone', __name__
|
||||
)
|
||||
|
||||
# .. toggle_name: discussions.enable_learners_tab_in_discussions_mfe
|
||||
# .. toggle_implementation: CourseWaffleFlag
|
||||
# .. toggle_default: False
|
||||
@@ -56,23 +45,3 @@ ENABLE_DISCUSSION_MODERATION_REASON_CODES = CourseWaffleFlag(
|
||||
ENABLE_REPORTED_CONTENT_EMAIL_NOTIFICATIONS = CourseWaffleFlag(
|
||||
f'{WAFFLE_FLAG_NAMESPACE}.enable_reported_content_email_notifications', __name__
|
||||
)
|
||||
|
||||
# .. toggle_name: discussions.enable_mfe_banner_for_learners
|
||||
# .. toggle_implementation: CourseWaffleFlag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Waffle flag to enable new MFE banner for learners
|
||||
# .. toggle_use_cases: temporary, open_edx
|
||||
# .. toggle_creation_date: 2022-06-08
|
||||
# .. toggle_target_removal_date: 2022-09-05
|
||||
ENABLE_DISCUSSIONS_MFE_BANNER = CourseWaffleFlag(f'{WAFFLE_FLAG_NAMESPACE}.enable_mfe_banner_for_learners', __name__)
|
||||
|
||||
# .. toggle_name: discussions.enable_view_mfe_in_iframe
|
||||
# .. toggle_implementation: CourseWaffleFlag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Waffle flag to toggle iframe view for new discussions mfe
|
||||
# .. toggle_use_cases: temporary, open_edx
|
||||
# .. toggle_creation_date: 2022-07-27
|
||||
# .. toggle_target_removal_date: 2022-12-31
|
||||
ENABLE_VIEW_MFE_IN_IFRAME = CourseWaffleFlag(
|
||||
f'{WAFFLE_FLAG_NAMESPACE}.enable_view_mfe_in_iframe', __name__
|
||||
)
|
||||
|
||||
@@ -48,11 +48,7 @@ from lms.djangoapps.discussion.django_comment_client.utils import (
|
||||
strip_none
|
||||
)
|
||||
from lms.djangoapps.discussion.exceptions import TeamDiscussionHiddenFromUserException
|
||||
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.discussion.toggles import ENABLE_DISCUSSIONS_MFE
|
||||
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
|
||||
@@ -274,21 +270,12 @@ def redirect_forum_url_to_new_mfe(request, course_id):
|
||||
Returns the redirect link when user opens default discussion homepage
|
||||
"""
|
||||
course_key = CourseKey.from_string(course_id)
|
||||
discussions_mfe_enabled_for_everyone = ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE.is_enabled(course_key)
|
||||
view_mfe_in_iframe = ENABLE_VIEW_MFE_IN_IFRAME.is_enabled(course_key)
|
||||
privileged_user = is_privileged_user(course_key, request.user)
|
||||
discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key)
|
||||
|
||||
redirect_url = None
|
||||
if discussions_mfe_enabled_for_everyone and (not view_mfe_in_iframe):
|
||||
if discussions_mfe_enabled:
|
||||
mfe_base_url = settings.DISCUSSIONS_MICROFRONTEND_URL
|
||||
redirect_url = f"{mfe_base_url}/{str(course_key)}"
|
||||
elif discussions_mfe_enabled_for_everyone and (not privileged_user):
|
||||
discussion_experience = request.GET.get('discussions_experience', None)
|
||||
banner_enabled = ENABLE_DISCUSSIONS_MFE_BANNER.is_enabled(course_key)
|
||||
redirect_to_mfe = (discussion_experience is None) or (not banner_enabled)
|
||||
if redirect_to_mfe and discussion_experience == "legacy":
|
||||
mfe_context = _discussions_mfe_context(request.GET, course_key, True, False, False)
|
||||
redirect_url = mfe_context['mfe_url']
|
||||
return redirect_url
|
||||
|
||||
|
||||
@@ -344,18 +331,12 @@ def redirect_thread_url_to_new_mfe(request, course_id, thread_id):
|
||||
Returns MFE url of the thread if the user is not privileged
|
||||
"""
|
||||
course_key = CourseKey.from_string(course_id)
|
||||
discussions_mfe_enabled_for_everyone = ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE.is_enabled(course_key)
|
||||
view_mfe_in_iframe = ENABLE_VIEW_MFE_IN_IFRAME.is_enabled(course_key)
|
||||
discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key)
|
||||
redirect_url = None
|
||||
if discussions_mfe_enabled_for_everyone and (not view_mfe_in_iframe):
|
||||
if discussions_mfe_enabled:
|
||||
mfe_base_url = settings.DISCUSSIONS_MICROFRONTEND_URL
|
||||
if thread_id:
|
||||
redirect_url = f"{mfe_base_url}/{str(course_key)}/posts/{thread_id}"
|
||||
elif discussions_mfe_enabled_for_everyone and (not is_privileged_user(course_key, request.user)):
|
||||
discussion_experience = request.GET.get('discussions_experience', None)
|
||||
if (discussion_experience is None) and (thread_id is not None):
|
||||
mfe_context = _discussions_mfe_context(request.GET, course_key, True, False, False)
|
||||
redirect_url = f"{mfe_context['mfe_url']}#posts/{thread_id}"
|
||||
return redirect_url
|
||||
|
||||
|
||||
@@ -671,15 +652,10 @@ def user_profile(request, course_key, user_id):
|
||||
'annotated_content_info': context['annotated_content_info'],
|
||||
})
|
||||
else:
|
||||
discussions_mfe_enabled_for_everyone = ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE.is_enabled(course_key)
|
||||
view_mfe_in_iframe = ENABLE_VIEW_MFE_IN_IFRAME.is_enabled(course_key)
|
||||
privileged_user = is_privileged_user(course_key, request.user)
|
||||
if discussions_mfe_enabled_for_everyone and (not view_mfe_in_iframe):
|
||||
discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key)
|
||||
if discussions_mfe_enabled:
|
||||
mfe_base_url = settings.DISCUSSIONS_MICROFRONTEND_URL
|
||||
return redirect(f"{mfe_base_url}/{str(course_key)}/learners")
|
||||
elif discussions_mfe_enabled_for_everyone and (not privileged_user):
|
||||
mfe_context = _discussions_mfe_context(request.GET, course_key, True, False, False)
|
||||
return redirect(mfe_context['mfe_url'])
|
||||
|
||||
tab_view = CourseTabView()
|
||||
|
||||
@@ -779,8 +755,7 @@ def followed_threads(request, course_key, user_id):
|
||||
def _discussions_mfe_context(query_params: Dict,
|
||||
course_key: CourseKey,
|
||||
is_educator_or_staff=False,
|
||||
legacy_only_view=False,
|
||||
is_privileged=False) -> Optional[Dict]:
|
||||
legacy_only_view=False) -> Optional[Dict]:
|
||||
"""
|
||||
Returns the context for rendering the MFE banner and MFE.
|
||||
|
||||
@@ -795,15 +770,9 @@ def _discussions_mfe_context(query_params: Dict,
|
||||
if not mfe_url:
|
||||
return {"show_banner": False, "show_mfe": False}
|
||||
discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key)
|
||||
discussions_mfe_enabled_for_everyone = ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE.is_enabled(course_key)
|
||||
enabled_for_educator_or_staff = is_educator_or_staff and discussions_mfe_enabled
|
||||
enable_mfe = enabled_for_educator_or_staff or discussions_mfe_enabled_for_everyone
|
||||
# Show the MFE if the new MFE is enabled,
|
||||
# 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 enable_mfe
|
||||
and discussions_mfe_enabled
|
||||
and not legacy_only_view
|
||||
)
|
||||
forum_url = reverse("forum_form_discussion", args=[course_key])
|
||||
@@ -813,9 +782,9 @@ def _discussions_mfe_context(query_params: Dict,
|
||||
"mfe_url": f"{forum_url}?discussions_experience=new",
|
||||
"share_feedback_url": settings.DISCUSSIONS_MFE_FEEDBACK_URL,
|
||||
"course_key": course_key,
|
||||
"show_banner": enable_mfe and (is_privileged or ENABLE_DISCUSSIONS_MFE_BANNER.is_enabled()),
|
||||
"show_banner": discussions_mfe_enabled and is_educator_or_staff,
|
||||
"discussions_mfe_url": mfe_url,
|
||||
"show_in_iframe": ENABLE_VIEW_MFE_IN_IFRAME.is_enabled(),
|
||||
"show_in_iframe": False,
|
||||
}
|
||||
|
||||
|
||||
@@ -887,9 +856,7 @@ class DiscussionBoardFragmentView(EdxFragmentView):
|
||||
# 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)
|
||||
is_educator_or_staff = is_course_staff(course_key, request.user) or GlobalStaff().has_user(request.user)
|
||||
is_privileged = is_privileged_user(course_key, request.user)
|
||||
mfe_context = _discussions_mfe_context(request.GET, course_key, is_educator_or_staff, force_legacy_view,
|
||||
is_privileged)
|
||||
mfe_context = _discussions_mfe_context(request.GET, course_key, is_educator_or_staff, force_legacy_view)
|
||||
if mfe_context["show_mfe"]:
|
||||
fragment = Fragment(render_to_string('discussion/discussion_mfe_embed.html', mfe_context))
|
||||
fragment.add_css(
|
||||
|
||||
Reference in New Issue
Block a user