From 048ae0689669946770e2c997b93377aa0953352e Mon Sep 17 00:00:00 2001 From: Ivan Niedielnitsev <81557788+NiedielnitsevIvan@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:17:56 +0300 Subject: [PATCH] feat: [AXIMST-783] change disscussion feature flag name (#2537) * feat: [AXIMST-783] change disscussion feature flag name * test: [AXIMST-783] fix tests --- lms/djangoapps/courseware/tests/test_views.py | 18 ++++++++-------- lms/djangoapps/courseware/toggles.py | 21 +++++++++++-------- lms/djangoapps/courseware/views/views.py | 11 ++++++---- lms/urls.py | 6 +++--- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index ed0b4bf5b7e0..d584b58fbc7d 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -78,10 +78,10 @@ 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_SIDEBAR_DISABLED, COURSEWARE_MICROFRONTEND_SEARCH_ENABLED, COURSEWARE_OPTIMIZED_RENDER_XBLOCK, + COURSEWARE_SHOW_DEFAULT_RIGHT_SIDEBAR, ) from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient from lms.djangoapps.courseware.views.views import ( @@ -3826,7 +3826,7 @@ def test_is_mfe_sidebar_enabled(self): class TestMFEDiscussionSidebarEnabledAPI(SharedModuleStoreTestCase): """ - Tests the endpoint to fetch the Courseware Discussion Sidebar waffle flag status. + Tests the endpoint to fetch the Courseware Discussion/Notifications Sidebar waffle flag status. """ def setUp(self): @@ -3835,12 +3835,12 @@ def setUp(self): self.course = CourseFactory.create() self.client = APIClient() - self.apiUrl = reverse('discussion_sidebar_enabled_view', kwargs={'course_id': str(self.course.id)}) + self.apiUrl = reverse('show_default_right_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): + @override_waffle_flag(COURSEWARE_SHOW_DEFAULT_RIGHT_SIDEBAR, active=False) + def test_is_mfe_show_default_right_sidebar_disabled(self): """ - Getter to check if discussion sidebar shouldn't be opened by default. + Getter to check if right 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')) @@ -3848,10 +3848,10 @@ def test_is_mfe_discussion_sidebar_opening_disabled(self): 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): + @override_waffle_flag(COURSEWARE_SHOW_DEFAULT_RIGHT_SIDEBAR, active=True) + def test_is_mfe_show_default_right_sidebar_enabled(self): """ - Getter to check if discussion sidebar should be opened by default. + Getter to check if right sidebar should be opened by default. """ response = self.client.get(self.apiUrl, content_type='application/json') body = json.loads(response.content.decode('utf-8')) diff --git a/lms/djangoapps/courseware/toggles.py b/lms/djangoapps/courseware/toggles.py index a4dfed7e696a..ba319ca98928 100644 --- a/lms/djangoapps/courseware/toggles.py +++ b/lms/djangoapps/courseware/toggles.py @@ -94,17 +94,20 @@ f'{WAFFLE_FLAG_NAMESPACE}.disable_navigation_sidebar', __name__ ) -# .. toggle_name: courseware.disable_default_opening_discussion_sidebar +# .. toggle_name: courseware.show_default_right_sidebar # .. toggle_implementation: WaffleFlag # .. toggle_default: False -# .. toggle_description: Disable opening the discussion sidebar by default on Learning MFE. +# .. toggle_description: If waffle flag disabled +# Discussions or Notifications sidebar shouldn't be displayed at all on Learning MFE. +# If waffle flag enabled - Discussions opens always on the pages with discussions, +# if user is in Audit and course has verified mode - show Notifications. # .. toggle_use_cases: temporary -# .. toggle_creation_date: 2024-03-13 +# .. toggle_creation_date: 2024-04-11 # .. toggle_target_removal_date: None -# .. toggle_tickets: AXIMST-629 +# .. toggle_tickets: FC-0056 # .. toggle_warning: None. -COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED = CourseWaffleFlag( - f'{WAFFLE_FLAG_NAMESPACE}.disable_default_opening_discussion_sidebar', __name__ +COURSEWARE_SHOW_DEFAULT_RIGHT_SIDEBAR = CourseWaffleFlag( + f'{WAFFLE_FLAG_NAMESPACE}.show_default_right_sidebar', __name__ ) # .. toggle_name: courseware.mfe_progress_milestones_streak_discount_enabled @@ -218,11 +221,11 @@ def courseware_mfe_sidebar_is_disabled(course_key=None): return COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED.is_enabled(course_key) -def courseware_mfe_discussion_sidebar_opening_is_disabled(course_key=None): +def courseware_show_default_right_sidebar_is_enabled(course_key=None): """ - Return whether the courseware.disable_default_opening_discussion_sidebar flag is on. + Return whether the courseware.show_default_right_sidebar flag is on. """ - return COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED.is_enabled(course_key) + return COURSEWARE_SHOW_DEFAULT_RIGHT_SIDEBAR.is_enabled(course_key) def courseware_mfe_navigation_sidebar_blocks_caching_is_enabled(course_key=None): diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index a21f4952aeb0..b1a849e853b8 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -88,9 +88,9 @@ 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_discussion_sidebar_opening_is_disabled, courseware_mfe_search_is_enabled, courseware_mfe_sidebar_is_disabled, + courseware_show_default_right_sidebar_is_enabled, ) from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient from lms.djangoapps.courseware.utils import ( @@ -2288,12 +2288,15 @@ def courseware_mfe_sidebar_enabled(request, course_id=None): @api_view(['GET']) -def courseware_mfe_discussion_sidebar_opening_is_enabled(request, course_id=None): +def courseware_mfe_show_default_right_sidebar_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 + 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_discussion_sidebar_opening_is_disabled(course_key) + "enabled": courseware_show_default_right_sidebar_is_enabled(course_key) }) diff --git a/lms/urls.py b/lms/urls.py index c519136b5a96..e6f287d2b8d2 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -755,9 +755,9 @@ 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', + fr'^courses/{settings.COURSE_ID_PATTERN}/show-default-right-sidebar/enabled/$', + courseware_views.courseware_mfe_show_default_right_sidebar_is_enabled, + name='show_default_right_sidebar_enabled_view', ), ]