From ec86ca969e7a938e830c3381d78b1dff38719305 Mon Sep 17 00:00:00 2001 From: Paulo Viadanna Date: Mon, 9 Sep 2024 08:54:15 -0300 Subject: [PATCH] fix: unhide discussions when enabling it --- .../djangoapps/discussions/serializers.py | 6 ++++++ .../discussions/tests/test_views.py | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/openedx/core/djangoapps/discussions/serializers.py b/openedx/core/djangoapps/discussions/serializers.py index 88648a499598..e63a330ba74a 100644 --- a/openedx/core/djangoapps/discussions/serializers.py +++ b/openedx/core/djangoapps/discussions/serializers.py @@ -354,6 +354,12 @@ def _update_course_configuration( key not in LegacySettingsSerializer.Meta.fields_cohorts ) } + # toogle discussion tab is_hidden + for tab in course.tabs: + if tab.tab_id == 'discussion' and tab.is_hidden == validated_data.get('enabled'): + tab.is_hidden = not validated_data.get('enabled') + save = True + break if save: modulestore().update_item(course, self.context['user_id']) return instance diff --git a/openedx/core/djangoapps/discussions/tests/test_views.py b/openedx/core/djangoapps/discussions/tests/test_views.py index cc17b56d226f..7564242727d3 100644 --- a/openedx/core/djangoapps/discussions/tests/test_views.py +++ b/openedx/core/djangoapps/discussions/tests/test_views.py @@ -387,6 +387,26 @@ def test_add_valid_configuration(self, provider_type): assert data['plugin_configuration'] == {'key': 'value'} assert data['lti_configuration'] == DEFAULT_LTI_CONFIGURATION + @ddt.data( + True, + False, + ) + def test_enabled_configuration(self, enabled): + """ + Test that enabling discussions unhides it. + """ + payload = { + "provider_type": Provider.PIAZZA, + "enabled": enabled, + } + self._post(payload) + + data = self.get() + for tab in self.store.get_course(self.course.id).tabs: + if tab.tab_id == "discussion": + assert data["enabled"] == (not tab.is_hidden) + break + def test_change_plugin_configuration(self): """ Tests custom config values persist that when changing discussion