From 45cd459ddec2ca73d16fc00dfcd2feaccb16efa6 Mon Sep 17 00:00:00 2001 From: Saad Yousaf Date: Mon, 29 Apr 2024 12:57:49 +0500 Subject: [PATCH] feat: add flag for showing/hiding new discussion sidebar view on course home page. (#34561) Co-authored-by: Saad Yousaf --- .../course_metadata/serializers.py | 1 + .../course_home_api/course_metadata/views.py | 2 ++ lms/djangoapps/course_home_api/toggles.py | 22 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/lms/djangoapps/course_home_api/course_metadata/serializers.py b/lms/djangoapps/course_home_api/course_metadata/serializers.py index 2bafd7427a2e..7683a9089453 100644 --- a/lms/djangoapps/course_home_api/course_metadata/serializers.py +++ b/lms/djangoapps/course_home_api/course_metadata/serializers.py @@ -57,3 +57,4 @@ class CourseHomeMetadataSerializer(VerifiedModeSerializer): user_timezone = serializers.CharField() can_view_certificate = serializers.BooleanField() course_modes = CourseModeSerrializer(many=True) + is_new_discussion_sidebar_view_enabled = serializers.BooleanField() diff --git a/lms/djangoapps/course_home_api/course_metadata/views.py b/lms/djangoapps/course_home_api/course_metadata/views.py index e42c3ea3b71d..248f90389d40 100644 --- a/lms/djangoapps/course_home_api/course_metadata/views.py +++ b/lms/djangoapps/course_home_api/course_metadata/views.py @@ -11,6 +11,7 @@ from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser from lms.djangoapps.certificates.api import certificates_viewable_for_course +from lms.djangoapps.course_home_api.toggles import new_discussion_sidebar_view_is_enabled from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.core.djangoapps.courseware_api.utils import get_celebrations_dict @@ -137,6 +138,7 @@ def get(self, request, *args, **kwargs): 'user_timezone': user_timezone, 'can_view_certificate': certificates_viewable_for_course(course), 'course_modes': course_modes, + 'is_new_discussion_sidebar_view_enabled': new_discussion_sidebar_view_is_enabled(course_key), } context = self.get_serializer_context() context['course'] = course diff --git a/lms/djangoapps/course_home_api/toggles.py b/lms/djangoapps/course_home_api/toggles.py index 759f8bc48465..c14362163036 100644 --- a/lms/djangoapps/course_home_api/toggles.py +++ b/lms/djangoapps/course_home_api/toggles.py @@ -21,6 +21,21 @@ ) +# Waffle flag to enable new discussion sidebar view on course home page +# +# .. toggle_name: course_home.new_discussion_sidebar_view +# .. toggle_implementation: CourseWaffleFlag +# .. toggle_default: False +# .. toggle_description: This toggle controls the user interface behavior of the discussion sidebar on course home page. +# .. toggle_use_cases: open_edx, temporary +# .. toggle_creation_date: 2024-04-22 +# .. toggle_target_removal_date: None +# .. toggle_tickets: INF-1338 +COURSE_HOME_NEW_DISCUSSION_SIDEBAR_VIEW = CourseWaffleFlag( + f'{WAFFLE_FLAG_NAMESPACE}.new_discussion_sidebar_view', __name__ +) + + def course_home_mfe_progress_tab_is_active(course_key): # Avoiding a circular dependency from .models import DisableProgressPageStackedConfig @@ -29,3 +44,10 @@ def course_home_mfe_progress_tab_is_active(course_key): COURSE_HOME_MICROFRONTEND_PROGRESS_TAB.is_enabled(course_key) and not DisableProgressPageStackedConfig.current(course_key=course_key).disabled ) + + +def new_discussion_sidebar_view_is_enabled(course_key): + """ + Returns True if the new discussion sidebar view is enabled for the given course. + """ + return COURSE_HOME_NEW_DISCUSSION_SIDEBAR_VIEW.is_enabled(course_key)