From 220954f5eccd1bd94d41c3c22bd123e53c54890b Mon Sep 17 00:00:00 2001 From: NiedielnitsevIvan <81557788+NiedielnitsevIvan@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:37:06 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20[AXIMST-629]=20waffle=20flag=20for=20di?= =?UTF-8?q?splaying=20discussions=20tab=20in=20=E2=80=A6=20(#2514)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: [AXIMST-629] new waffle flag for displaying discussions tab in learning MFE by default * test: [AXIMST-629] add tests for new waffle flag view * style: [AXIMST-629] improve flag naming --- lms/djangoapps/courseware/tests/test_views.py | 73 +++++++++++++++++++ lms/djangoapps/courseware/toggles.py | 40 ++++++++++ lms/djangoapps/courseware/views/views.py | 31 +++++++- lms/urls.py | 10 +++ 4 files changed, 153 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 1d6c358ffd19..5f8bd1c49f18 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -78,6 +78,7 @@ from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin, get_expiration_banner_text, set_preview_mode from lms.djangoapps.courseware.testutils import RenderXBlockTestMixin from lms.djangoapps.courseware.toggles import ( + COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED, COURSEWARE_MICROFRONTEND_SEARCH_ENABLED, COURSEWARE_OPTIMIZED_RENDER_XBLOCK, ) @@ -3784,3 +3785,75 @@ def test_is_mfe_search_disabled(self): self.assertEqual(response.status_code, 200) self.assertEqual(body, {'enabled': False}) + + +class TestCoursewareMFESidebarEnabledAPI(SharedModuleStoreTestCase): + """ + Tests the endpoint to fetch the Courseware Sidebar waffle flag status. + """ + + def setUp(self): + super().setUp() + + self.course = CourseFactory.create() + + self.client = APIClient() + self.apiUrl = reverse('courseware_sidebar_enabled_view', kwargs={'course_id': str(self.course.id)}) + + @override_waffle_flag(COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED, active=True) + def test_courseware_mfe_sidebar_disabled(self): + """ + Getter to check if user is allowed to show the Courseware navigation sidebar. + """ + response = self.client.get(self.apiUrl, content_type='application/json') + body = json.loads(response.content.decode('utf-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(body, {'enabled': False}) + + @override_waffle_flag(COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED, active=False) + def test_is_mfe_sidebar_enabled(self): + """ + Getter to check if user is allowed to show the Courseware navigation sidebar. + """ + response = self.client.get(self.apiUrl, content_type='application/json') + body = json.loads(response.content.decode('utf-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(body, {'enabled': True}) + + +class TestMFEDiscussionSidebarEnabledAPI(SharedModuleStoreTestCase): + """ + Tests the endpoint to fetch the Courseware Discussion Sidebar waffle flag status. + """ + + def setUp(self): + super().setUp() + + self.course = CourseFactory.create() + + self.client = APIClient() + self.apiUrl = reverse('discussion_sidebar_enabled_view', kwargs={'course_id': str(self.course.id)}) + + @override_waffle_flag(COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED, active=True) + def test_is_mfe_discussion_sidebar_opening_disabled(self): + """ + Getter to check if discussion sidebar shouldn't be opened by default. + """ + response = self.client.get(self.apiUrl, content_type='application/json') + body = json.loads(response.content.decode('utf-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(body, {'enabled': False}) + + @override_waffle_flag(COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED, active=False) + def test_is_mfe_discussion_sidebar_opening_enabled(self): + """ + Getter to check if discussion sidebar should be opened by default. + """ + response = self.client.get(self.apiUrl, content_type='application/json') + body = json.loads(response.content.decode('utf-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(body, {'enabled': True}) diff --git a/lms/djangoapps/courseware/toggles.py b/lms/djangoapps/courseware/toggles.py index 18ff56e2f4c1..f13d6fcd6668 100644 --- a/lms/djangoapps/courseware/toggles.py +++ b/lms/djangoapps/courseware/toggles.py @@ -68,6 +68,32 @@ f'{WAFFLE_FLAG_NAMESPACE}.mfe_courseware_search', __name__ ) +# .. toggle_name: courseware.disable_navigation_sidebar +# .. toggle_implementation: WaffleFlag +# .. toggle_default: False +# .. toggle_description: Disable navi sidebar on Learning MFE +# .. toggle_use_cases: temporary +# .. toggle_creation_date: 2024-03-07 +# .. toggle_target_removal_date: None +# .. toggle_tickets: AXIMST-611 +# .. toggle_warning: None. +COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED = CourseWaffleFlag( + f'{WAFFLE_FLAG_NAMESPACE}.disable_navigation_sidebar', __name__ +) + +# .. toggle_name: courseware.disable_default_opening_discussion_sidebar +# .. toggle_implementation: WaffleFlag +# .. toggle_default: False +# .. toggle_description: Disable opening the discussion sidebar by default on Learning MFE. +# .. toggle_use_cases: temporary +# .. toggle_creation_date: 2024-03-13 +# .. toggle_target_removal_date: None +# .. toggle_tickets: AXIMST-629 +# .. toggle_warning: None. +COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED = CourseWaffleFlag( + f'{WAFFLE_FLAG_NAMESPACE}.disable_default_opening_discussion_sidebar', __name__ +) + # .. toggle_name: courseware.mfe_progress_milestones_streak_discount_enabled # .. toggle_implementation: CourseWaffleFlag # .. toggle_default: False @@ -170,3 +196,17 @@ def courseware_mfe_search_is_enabled(course_key=None): Return whether the courseware.mfe_courseware_search flag is on. """ return COURSEWARE_MICROFRONTEND_SEARCH_ENABLED.is_enabled(course_key) + + +def courseware_mfe_sidebar_is_disabled(course_key=None): + """ + Return whether the courseware.disable_navigation_sidebar flag is on. + """ + return COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED.is_enabled(course_key) + + +def courseware_mfe_discussion_sidebar_opening_is_disabled(course_key=None): + """ + Return whether the courseware.disable_default_opening_discussion_sidebar flag is on. + """ + return COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED.is_enabled(course_key) diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 3d70a763582d..a21f4952aeb0 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -86,7 +86,12 @@ from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule from lms.djangoapps.courseware.permissions import MASQUERADE_AS_STUDENT, VIEW_COURSE_HOME, VIEW_COURSEWARE -from lms.djangoapps.courseware.toggles import course_is_invitation_only, courseware_mfe_search_is_enabled +from lms.djangoapps.courseware.toggles import ( + course_is_invitation_only, + courseware_mfe_discussion_sidebar_opening_is_disabled, + courseware_mfe_search_is_enabled, + courseware_mfe_sidebar_is_disabled, +) from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient from lms.djangoapps.courseware.utils import ( _use_new_financial_assistance_flow, @@ -2268,3 +2273,27 @@ def courseware_mfe_search_enabled(request, course_id=None): payload = {"enabled": courseware_mfe_search_is_enabled(course_key)} return JsonResponse(payload) + + +@api_view(['GET']) +def courseware_mfe_sidebar_enabled(request, course_id=None): + """ + Simple GET endpoint to expose whether the course may display navigation sidebar. + """ + course_key = CourseKey.from_string(course_id) if course_id else None + + return JsonResponse({ + "enabled": not courseware_mfe_sidebar_is_disabled(course_key) + }) + + +@api_view(['GET']) +def courseware_mfe_discussion_sidebar_opening_is_enabled(request, course_id=None): + """ + Simple GET endpoint to expose whether the course may open discussion sidebar by default. + """ + course_key = CourseKey.from_string(course_id) if course_id else None + + return JsonResponse({ + "enabled": not courseware_mfe_discussion_sidebar_opening_is_disabled(course_key) + }) diff --git a/lms/urls.py b/lms/urls.py index c7a0d49da4d7..c519136b5a96 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -749,6 +749,16 @@ courseware_views.courseware_mfe_search_enabled, name='courseware_search_enabled_view', ), + re_path( + fr'^courses/{settings.COURSE_ID_PATTERN}/courseware-sidebar/enabled/$', + courseware_views.courseware_mfe_sidebar_enabled, + name='courseware_sidebar_enabled_view', + ), + re_path( + fr'^courses/{settings.COURSE_ID_PATTERN}/discussion-sidebar/enabled/$', + courseware_views.courseware_mfe_discussion_sidebar_opening_is_enabled, + name='discussion_sidebar_enabled_view', + ), ] urlpatterns += [