From 608f1994b742355da2ecb99218ffbe2ab1219b7a Mon Sep 17 00:00:00 2001 From: SaadYousaf Date: Mon, 21 Jun 2021 22:08:49 +0500 Subject: [PATCH] refactor: move waffle flag calculation to utils file and other updates --- .../contentstore/tests/test_course_settings.py | 7 +++++-- .../models/settings/course_metadata.py | 6 ++---- .../tests/views/test_instructor_dashboard.py | 4 +++- .../instructor/views/instructor_dashboard.py | 9 ++------- .../core/djangoapps/discussions/config/waffle.py | 4 ++-- .../discussions/config/waffle_utils.py | 16 ++++++++++++++++ 6 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 openedx/core/djangoapps/discussions/config/waffle_utils.py diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py index caee696b3f..aac15a55b4 100644 --- a/cms/djangoapps/contentstore/tests/test_course_settings.py +++ b/cms/djangoapps/contentstore/tests/test_course_settings.py @@ -34,8 +34,10 @@ 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, \ +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 @@ -125,7 +127,8 @@ class CourseAdvanceSettingViewTest(CourseTestCase, MilestonesTestCaseMixin): @ddt.data( (False, False, True), (True, False, False), - (True, True, True) + (True, True, True), + (False, True, True) ) @ddt.unpack def test_discussion_fields_available(self, is_pages_and_resources_enabled, diff --git a/cms/djangoapps/models/settings/course_metadata.py b/cms/djangoapps/models/settings/course_metadata.py index 5bf8a5eb64..0dbf338218 100644 --- a/cms/djangoapps/models/settings/course_metadata.py +++ b/cms/djangoapps/models/settings/course_metadata.py @@ -14,8 +14,7 @@ from xblock.fields import Scope from cms.djangoapps.contentstore import toggles from common.djangoapps.xblock_django.models import XBlockStudioConfigurationFlag -from openedx.core.djangoapps.discussions.config.waffle import OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG, \ - ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND +from openedx.core.djangoapps.discussions.config.waffle_utils import legacy_discussion_experience_enabled from openedx.core.lib.teams_config import TeamsetType from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG from xmodule.modulestore.django import modulestore @@ -143,8 +142,7 @@ class CourseMetadata: if not settings.PROCTORING_BACKENDS or settings.PROCTORING_BACKENDS.get('proctortrack') is None: exclude_list.append('proctoring_escalation_email') - if (ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND.is_enabled(course_key) and - not OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG.is_enabled(course_key)): + if not legacy_discussion_experience_enabled(course_key): exclude_list.append('discussion_blackouts') exclude_list.append('allow_anonymous') exclude_list.append('allow_anonymous_to_peers') diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index a029bfc0e8..b4f27c7636 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -30,8 +30,10 @@ 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, \ +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 diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index bc7ab88ff8..474ead4712 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -52,8 +52,7 @@ 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, \ - OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG +from openedx.core.djangoapps.discussions.config.waffle_utils import legacy_discussion_experience_enabled 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 @@ -142,11 +141,7 @@ def instructor_dashboard_2(request, course_id): # lint-amnesty, pylint: disable _section_student_admin(course, access), ] - 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: + if legacy_discussion_experience_enabled(course_key): sections_content.append(_section_discussions_management(course, access)) sections.extend(sections_content) diff --git a/openedx/core/djangoapps/discussions/config/waffle.py b/openedx/core/djangoapps/discussions/config/waffle.py index 2232e0e428..a1d05c0d0e 100644 --- a/openedx/core/djangoapps/discussions/config/waffle.py +++ b/openedx/core/djangoapps/discussions/config/waffle.py @@ -29,12 +29,12 @@ OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG = CourseWaffleFlag( # .. toggle_name: discussions.pages_and_resources_mfe # .. toggle_implementation: CourseWaffleFlag # .. toggle_default: False -# .. toggle_description: Waffle flag to link existing studio views to the new Pages and Resources experience. +# .. toggle_description: Waffle flag to enable new Pages and Resources experience for course. # .. toggle_use_cases: temporary, open_edx # .. toggle_creation_date: 2021-05-24 # .. toggle_target_removal_date: 2021-12-31 # .. toggle_warnings: Also set settings.COURSE_AUTHORING_MICROFRONTEND_URL. -# .. toggle_tickets: None +# .. toggle_tickets: https://openedx.atlassian.net/browse/TNL-7791 ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND = CourseWaffleFlag( waffle_namespace=WAFFLE_NAMESPACE, flag_name='pages_and_resources_mfe', diff --git a/openedx/core/djangoapps/discussions/config/waffle_utils.py b/openedx/core/djangoapps/discussions/config/waffle_utils.py new file mode 100644 index 0000000000..d44b7af5ad --- /dev/null +++ b/openedx/core/djangoapps/discussions/config/waffle_utils.py @@ -0,0 +1,16 @@ +""" +Utils methods for Discussion app waffle flags. +""" + +from openedx.core.djangoapps.discussions.config.waffle import ( + ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND, + OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG +) + + +def legacy_discussion_experience_enabled(course_key): + """ + Checks for relevant flags and returns a boolean whether to show legacy discussion settings or not + """ + return bool(OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG.is_enabled(course_key) or + not ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND.is_enabled(course_key))