diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py index d0a81795ce..caee696b3f 100644 --- a/cms/djangoapps/contentstore/tests/test_course_settings.py +++ b/cms/djangoapps/contentstore/tests/test_course_settings.py @@ -34,6 +34,8 @@ from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRol from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util import milestones_helpers from common.djangoapps.xblock_django.models import XBlockStudioConfigurationFlag +from openedx.core.djangoapps.discussions.config.waffle import ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND, \ + OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG from openedx.core.djangoapps.models.course_details import CourseDetails from xmodule.fields import Date from xmodule.modulestore import ModuleStoreEnum @@ -93,6 +95,7 @@ class CourseSettingsEncoderTest(CourseTestCase): self.assertEqual(jsondetails['string'], 'string') +@ddt.ddt class CourseAdvanceSettingViewTest(CourseTestCase, MilestonesTestCaseMixin): """ Tests for AdvanceSettings View. @@ -119,6 +122,26 @@ class CourseAdvanceSettingViewTest(CourseTestCase, MilestonesTestCaseMixin): self.assertEqual(settings_fields["display_name"], "Mobile Course Available") self.assertEqual(settings_fields["deprecated"], True) + @ddt.data( + (False, False, True), + (True, False, False), + (True, True, True) + ) + @ddt.unpack + def test_discussion_fields_available(self, is_pages_and_resources_enabled, + is_legacy_discussion_setting_enabled, fields_visible): + """ + Test to check the availability of discussion related fields when relevant flags are enabled + """ + + with override_waffle_flag(ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND, is_pages_and_resources_enabled): + with override_waffle_flag(OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG, is_legacy_discussion_setting_enabled): + response = self.client.get_html(self.course_setting_url).content.decode('utf-8') + self.assertEqual('allow_anonymous' in response, fields_visible) + self.assertEqual('allow_anonymous_to_peers' in response, fields_visible) + self.assertEqual('discussion_blackouts' in response, fields_visible) + self.assertEqual('discussion_topics' in response, fields_visible) + @ddt.ddt class CourseDetailsViewTest(CourseTestCase, MilestonesTestCaseMixin): diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index 5a58599dd6..a029bfc0e8 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -2,7 +2,6 @@ Unit tests for instructor_dashboard.py. """ - import datetime import re from unittest.mock import patch @@ -30,6 +29,9 @@ from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from lms.djangoapps.grades.config.waffle import WRITABLE_GRADEBOOK, waffle_flags from lms.djangoapps.instructor.toggles import DATA_DOWNLOAD_V2 from lms.djangoapps.instructor.views.gradebook_api import calculate_page_info +from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted +from openedx.core.djangoapps.discussions.config.waffle import ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND, \ + OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG from openedx.core.djangoapps.site_configuration.models import SiteConfiguration from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase @@ -104,6 +106,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT """ Verify that the instructor tab appears for staff only. """ + def has_instructor_tab(user, course): """Returns true if the "Instructor" tab is shown.""" tabs = get_course_tab_list(user, course) @@ -135,6 +138,33 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT ) assert has_instructor_tab(org_researcher, self.course) + @ddt.data( + ('staff', False, False, True), + ('staff', True, False, False), + ('staff', True, True, True), + ) + @ddt.unpack + def test_discussion_tab(self, access_role, is_pages_and_resources_enabled, is_legacy_discussion_setting_enabled, + is_discussion_tab_available): + """ + Verify that the Discussion tab only shows up when Pages & Resources flag is off for course + """ + discussion_section = '' + + with override_waffle_flag(ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND, is_pages_and_resources_enabled): + with override_waffle_flag(OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG, is_legacy_discussion_setting_enabled): + CourseAccessRoleFactory( + course_id=self.course.id, + user=self.user, + role=access_role, + org=self.course.id.org + ) + set_course_cohorted(self.course.id, True) + self.client.login(username=self.user.username, password='test') + response = self.client.get(self.url).content.decode('utf-8') + self.assertEqual(discussion_section in response, is_discussion_tab_available) + @ddt.data( ('staff', False, False), ('instructor', False, False), @@ -154,7 +184,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT download_section = '' if waffle_status: - download_section = '' user = UserFactory.create(is_staff=access_role == 'global_staff') CourseAccessRoleFactory( @@ -438,7 +468,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT ) @ddt.unpack def test_ccx_coaches_option_on_admin_list_management_instructor( - self, ccx_feature_flag, enable_ccx, expected_result + self, ccx_feature_flag, enable_ccx, expected_result ): """ Test whether the "CCX Coaches" option is visible or hidden depending on the value of course.enable_ccx. diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 5dd0e567ca..bc7ab88ff8 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -52,7 +52,8 @@ from lms.djangoapps.courseware.module_render import get_module_by_usage_id from lms.djangoapps.discussion.django_comment_client.utils import available_division_schemes, has_forum_access from lms.djangoapps.grades.api import is_writable_gradebook_enabled from openedx.core.djangoapps.course_groups.cohorts import DEFAULT_COHORT_NAME, get_course_cohorts, is_course_cohorted -from openedx.core.djangoapps.discussions.config.waffle import ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND +from openedx.core.djangoapps.discussions.config.waffle import ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND, \ + OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, CourseDiscussionSettings from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.verified_track_content.models import VerifiedTrackCohortedCourse @@ -140,7 +141,12 @@ def instructor_dashboard_2(request, course_id): # lint-amnesty, pylint: disable _section_cohort_management(course, access), _section_student_admin(course, access), ] - if not ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND.is_enabled(course_key): + + discussion_section_visible = bool((ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND.is_enabled(course_key) and + OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG.is_enabled(course_key)) or not + ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND.is_enabled(course_key)) + + if discussion_section_visible: sections_content.append(_section_discussions_management(course, access)) sections.extend(sections_content)