diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 5ca92f92a3b8..d249fdac3ca9 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_SIDEBAR_DISABLED, COURSEWARE_MICROFRONTEND_SEARCH_ENABLED, COURSEWARE_OPTIMIZED_RENDER_XBLOCK, COURSEWARE_SHOW_DEFAULT_RIGHT_SIDEBAR, @@ -3815,6 +3816,42 @@ def test_is_mfe_search_waffle_disabled(self): 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/Notifications Sidebar waffle flag status. diff --git a/lms/djangoapps/courseware/toggles.py b/lms/djangoapps/courseware/toggles.py index 565b759f23fa..8a46858cf00d 100644 --- a/lms/djangoapps/courseware/toggles.py +++ b/lms/djangoapps/courseware/toggles.py @@ -83,6 +83,19 @@ f'{WAFFLE_FLAG_NAMESPACE}.disable_navigation_sidebar_blocks_caching', __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.show_default_right_sidebar # .. toggle_implementation: WaffleFlag # .. toggle_default: False @@ -209,6 +222,13 @@ def courseware_disable_navigation_sidebar_blocks_caching(course_key=None): return COURSEWARE_MICROFRONTEND_NAVIGATION_SIDEBAR_BLOCKS_DISABLE_CACHING.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_show_default_right_sidebar_is_enabled(course_key=None): """ Return whether the courseware.show_default_right_sidebar flag is on. diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index e7ba9342dcc0..5607d2a6af98 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -92,6 +92,7 @@ course_is_invitation_only, courseware_mfe_search_is_enabled, courseware_show_default_right_sidebar_is_enabled, + courseware_mfe_sidebar_is_disabled, ) from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient from lms.djangoapps.courseware.utils import ( @@ -2288,6 +2289,21 @@ def courseware_mfe_search_enabled(request, course_id=None): return JsonResponse(payload) +@api_view(['GET']) +def courseware_mfe_sidebar_enabled(request, course_id=None): + """ + GET endpoint to expose whether the course may display navigation sidebar. + """ + try: + course_key = CourseKey.from_string(course_id) if course_id else None + except InvalidKeyError: + return JsonResponse({"error": "Invalid course_id"}) + + return JsonResponse({ + "enabled": not courseware_mfe_sidebar_is_disabled(course_key) + }) + + @api_view(['GET']) def courseware_mfe_show_default_right_sidebar_is_enabled(request, course_id=None): """ @@ -2301,4 +2317,3 @@ def courseware_mfe_show_default_right_sidebar_is_enabled(request, course_id=None return JsonResponse({ "enabled": courseware_show_default_right_sidebar_is_enabled(course_key) }) - diff --git a/lms/urls.py b/lms/urls.py index 4d4afacd4a42..b7b6d49fed7c 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -749,6 +749,11 @@ 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_show_default_right_sidebar_is_enabled,