From ccfeede8e6d8ac249a66cd553c4eb7f89f4d9034 Mon Sep 17 00:00:00 2001 From: Paulo Viadanna Date: Mon, 2 Sep 2024 14:36:16 -0300 Subject: [PATCH] fix: unhide discussion tab when enabling it --- openedx/core/djangoapps/discussions/utils.py | 13 +++++++++++++ openedx/core/djangoapps/discussions/views.py | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/discussions/utils.py b/openedx/core/djangoapps/discussions/utils.py index 7c26a4e482e6..fe5c88fff92f 100644 --- a/openedx/core/djangoapps/discussions/utils.py +++ b/openedx/core/djangoapps/discussions/utils.py @@ -191,3 +191,16 @@ def get_course_division_scheme(course_discussion_settings: CourseDiscussionSetti ): division_scheme = CourseDiscussionSettings.NONE return division_scheme + + +def show_discussion_tab(course_key, user_id: int) -> None: + """ + Toggle the visibility of the discussion tab in the course. + """ + store = modulestore() + course = store.get_course(course_key) + for tab in course.tabs: + if tab.tab_id == 'discussion': + tab.is_hidden = False + store.update_item(course, user_id) + break diff --git a/openedx/core/djangoapps/discussions/views.py b/openedx/core/djangoapps/discussions/views.py index 9d27d8f5f8e1..adbb5867050f 100644 --- a/openedx/core/djangoapps/discussions/views.py +++ b/openedx/core/djangoapps/discussions/views.py @@ -21,6 +21,7 @@ DiscussionsConfigurationSerializer, DiscussionsProvidersSerializer, ) +from .utils import show_discussion_tab class DiscussionsConfigurationSettingsView(APIView): @@ -120,8 +121,9 @@ def update_configuration_data(request, course_key_string): new_provider_type = serializer.validated_data.get('provider_type', None) if new_provider_type is not None and new_provider_type != configuration.provider_type: check_course_permissions(course, request.user, 'change_provider') - serializer.save() + if configuration.is_enabled(course_key): + show_discussion_tab(course_key, request.user.id) return serializer.data