diff --git a/openedx/core/djangoapps/discussions/serializers.py b/openedx/core/djangoapps/discussions/serializers.py index 88648a499598..1514a696f195 100644 --- a/openedx/core/djangoapps/discussions/serializers.py +++ b/openedx/core/djangoapps/discussions/serializers.py @@ -7,6 +7,8 @@ from rest_framework import serializers from xmodule.modulestore.django import modulestore +from opaque_keys.edx.keys import CourseKey + from openedx.core.djangoapps.discussions.tasks import update_discussions_settings_from_course_task from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings from openedx.core.lib.courses import get_course_by_id @@ -265,6 +267,14 @@ def update(self, instance: DiscussionsConfiguration, validated_data: dict) -> Di course_overview_id=instance.context_key, type='discussion' ).update(is_hidden=not instance.enabled) + # do the same for the modulestore representation + store = modulestore() + course = store.get_course(instance.context_key) + for tab in course.tabs: + if tab.tab_id == 'discussion': + tab.is_hidden = not instance.enabled + store.update_item(course, self.context['user_id']) + break update_discussions_settings_from_course_task.delay(str(instance.context_key)) return instance diff --git a/openedx/core/djangoapps/discussions/utils.py b/openedx/core/djangoapps/discussions/utils.py index fe5c88fff92f..7c26a4e482e6 100644 --- a/openedx/core/djangoapps/discussions/utils.py +++ b/openedx/core/djangoapps/discussions/utils.py @@ -191,16 +191,3 @@ 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 adbb5867050f..9d27d8f5f8e1 100644 --- a/openedx/core/djangoapps/discussions/views.py +++ b/openedx/core/djangoapps/discussions/views.py @@ -21,7 +21,6 @@ DiscussionsConfigurationSerializer, DiscussionsProvidersSerializer, ) -from .utils import show_discussion_tab class DiscussionsConfigurationSettingsView(APIView): @@ -121,9 +120,8 @@ 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