From 53270f17b383affdb213d744581c0f850bbe5dde Mon Sep 17 00:00:00 2001 From: ayesha waris <73840786+ayesha-waris@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:07:00 +0500 Subject: [PATCH] chore: removed and merged multiple flags into enable_discussions_mfe flag (#33983) --- .../models/settings/course_metadata.py | 1 - lms/djangoapps/discussion/config/waffle.py | 19 ---------------- lms/djangoapps/discussion/rest_api/api.py | 14 +----------- .../discussion/rest_api/tests/test_api.py | 12 ---------- .../discussion/rest_api/tests/test_views.py | 6 ++--- lms/djangoapps/discussion/toggles.py | 22 ------------------- lms/djangoapps/discussion/toggles_utils.py | 4 ++-- .../djangoapps/discussions/serializers.py | 3 --- .../discussions/tests/test_views.py | 1 - 9 files changed, 5 insertions(+), 77 deletions(-) delete mode 100644 lms/djangoapps/discussion/config/waffle.py diff --git a/cms/djangoapps/models/settings/course_metadata.py b/cms/djangoapps/models/settings/course_metadata.py index e5a0ab6a5b8f..8e0d5d887eeb 100644 --- a/cms/djangoapps/models/settings/course_metadata.py +++ b/cms/djangoapps/models/settings/course_metadata.py @@ -146,7 +146,6 @@ def get_exclude_list_of_fields(cls, course_key): exclude_list.append('allow_anonymous') exclude_list.append('allow_anonymous_to_peers') exclude_list.append('discussion_topics') - return exclude_list @classmethod diff --git a/lms/djangoapps/discussion/config/waffle.py b/lms/djangoapps/discussion/config/waffle.py deleted file mode 100644 index e9fc3aa98ad1..000000000000 --- a/lms/djangoapps/discussion/config/waffle.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -This module contains configuration settings via waffle switches for the discussions. -""" - -from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag - -WAFFLE_NAMESPACE = 'discussions' - -# .. toggle_name: discussions.enable_learners_stats -# .. toggle_implementation: CourseWaffleFlag -# .. toggle_default: False -# .. toggle_description: Waffle flag to enable learners stats -# .. toggle_use_cases: temporary, open_edx -# .. toggle_creation_date: 2022-08-12 -# .. toggle_target_removal_date: 2022-10-02 -# .. toggle_warning: When the flag is ON, API will return learners stats with original values. -# .. This is temporary fix for performance issue in API. -# .. toggle_tickets: INF-444 -ENABLE_LEARNERS_STATS = CourseWaffleFlag(f'{WAFFLE_NAMESPACE}.enable_learners_stats', __name__) diff --git a/lms/djangoapps/discussion/rest_api/api.py b/lms/djangoapps/discussion/rest_api/api.py index d8b02435a41f..34101f211070 100644 --- a/lms/djangoapps/discussion/rest_api/api.py +++ b/lms/djangoapps/discussion/rest_api/api.py @@ -37,7 +37,7 @@ from lms.djangoapps.course_blocks.api import get_course_blocks from lms.djangoapps.courseware.courses import get_course_with_access from lms.djangoapps.courseware.exceptions import CourseAccessRedirect -from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE, ENABLE_LEARNERS_TAB_IN_DISCUSSIONS_MFE +from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE from lms.djangoapps.discussion.views import is_privileged_user from openedx.core.djangoapps.discussions.models import ( DiscussionsConfiguration, @@ -85,7 +85,6 @@ from xmodule.modulestore.django import modulestore from xmodule.tabs import CourseTabList -from ..config.waffle import ENABLE_LEARNERS_STATS from ..django_comment_client.base.views import ( track_comment_created_event, track_comment_deleted_event, @@ -365,7 +364,6 @@ def _format_datetime(dt): "provider": course_config.provider_type, "enable_in_context": course_config.enable_in_context, "group_at_subsection": course_config.plugin_configuration.get("group_at_subsection", False), - 'learners_tab_enabled': ENABLE_LEARNERS_TAB_IN_DISCUSSIONS_MFE.is_enabled(course_key), "edit_reasons": [ {"code": reason_code, "label": label} for (reason_code, label) in EDIT_REASON_CODES.items() @@ -1857,16 +1855,6 @@ def get_course_discussion_user_stats( if order_by == UserOrdering.BY_FLAGS: raise ValidationError({"order_by": "Invalid value"}) - if not ENABLE_LEARNERS_STATS.is_enabled(course_key): - return get_users_without_stats( - username_search_string, - course_key, - page, - page_size, - request, - is_privileged - ) - params = { 'sort_key': str(order_by), 'page': page, diff --git a/lms/djangoapps/discussion/rest_api/tests/test_api.py b/lms/djangoapps/discussion/rest_api/tests/test_api.py index bb9eccd1c641..a9bf98c50a4e 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_api.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_api.py @@ -13,7 +13,6 @@ import httpretty import pytest from django.test import override_settings -from edx_toggles.toggles.testutils import override_waffle_flag from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError from django.test.client import RequestFactory @@ -38,7 +37,6 @@ from common.djangoapps.util.testing import UrlResetMixin from common.test.utils import MockSignalHandlerMixin, disable_signal from lms.djangoapps.discussion.django_comment_client.tests.utils import ForumsEnableMixin -from lms.djangoapps.discussion.toggles import ENABLE_LEARNERS_TAB_IN_DISCUSSIONS_MFE from lms.djangoapps.discussion.rest_api import api from lms.djangoapps.discussion.rest_api.api import ( create_comment, @@ -211,7 +209,6 @@ def test_basic(self): 'is_group_ta': False, 'is_user_admin': False, 'user_roles': {'Student'}, - 'learners_tab_enabled': False, 'edit_reasons': [{'code': 'test-edit-reason', 'label': 'Test Edit Reason'}], 'post_close_reasons': [{'code': 'test-close-reason', 'label': 'Test Close Reason'}], } @@ -230,15 +227,6 @@ def test_privileged_roles(self, role): assert course_meta["has_moderation_privileges"] assert course_meta["user_roles"] == {FORUM_ROLE_STUDENT} | {role} - @ddt.data(True, False) - def test_learner_tab_enabled_flag(self, learners_tab_enabled): - """ - Test the 'learners_tab_enabled' flag. - """ - with override_waffle_flag(ENABLE_LEARNERS_TAB_IN_DISCUSSIONS_MFE, learners_tab_enabled): - course_meta = get_course(self.request, self.course.id) - assert course_meta['learners_tab_enabled'] == learners_tab_enabled - @ddt.ddt @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) diff --git a/lms/djangoapps/discussion/rest_api/tests/test_views.py b/lms/djangoapps/discussion/rest_api/tests/test_views.py index ded21536e7f6..1782a574b05a 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_views.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_views.py @@ -21,7 +21,7 @@ from rest_framework.parsers import JSONParser from rest_framework.test import APIClient, APITestCase -from lms.djangoapps.discussion.config.waffle import ENABLE_LEARNERS_STATS +from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE from lms.djangoapps.discussion.rest_api.utils import get_usernames_from_search_string from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore @@ -535,7 +535,6 @@ def test_basic(self): "is_group_ta": False, 'is_user_admin': False, "user_roles": ["Student"], - 'learners_tab_enabled': False, "edit_reasons": [{"code": "test-edit-reason", "label": "Test Edit Reason"}], "post_close_reasons": [{"code": "test-close-reason", "label": "Test Close Reason"}], } @@ -2842,7 +2841,6 @@ def _get_expected_response(self): 'division_scheme': 'cohort', 'available_division_schemes': ['cohort'], 'reported_content_email_notifications': False, - 'reported_content_email_notifications_flag': False, } def patch_request(self, data, headers=None): @@ -3259,7 +3257,7 @@ def test_post_update_user_role(self, action, user_in_role): @ddt.ddt @httpretty.activate -@override_waffle_flag(ENABLE_LEARNERS_STATS, True) +@override_waffle_flag(ENABLE_DISCUSSIONS_MFE, True) class CourseActivityStatsTest(ForumsEnableMixin, UrlResetMixin, CommentsServiceMockMixin, APITestCase, SharedModuleStoreTestCase): """ diff --git a/lms/djangoapps/discussion/toggles.py b/lms/djangoapps/discussion/toggles.py index 201cd4e7318c..a1c292a4734f 100644 --- a/lms/djangoapps/discussion/toggles.py +++ b/lms/djangoapps/discussion/toggles.py @@ -12,25 +12,3 @@ # .. toggle_creation_date: 2021-11-05 # .. toggle_target_removal_date: 2022-12-05 ENABLE_DISCUSSIONS_MFE = CourseWaffleFlag(f'{WAFFLE_FLAG_NAMESPACE}.enable_discussions_mfe', __name__) - -# .. toggle_name: discussions.enable_learners_tab_in_discussions_mfe -# .. toggle_implementation: CourseWaffleFlag -# .. toggle_default: False -# .. toggle_description: Waffle flag to enable learners tab in the new MFE experience for discussions -# .. toggle_use_cases: temporary, open_edx -# .. toggle_creation_date: 2022-02-21 -# .. toggle_target_removal_date: 2022-05-21 -ENABLE_LEARNERS_TAB_IN_DISCUSSIONS_MFE = CourseWaffleFlag( - f'{WAFFLE_FLAG_NAMESPACE}.enable_learners_tab_in_discussions_mfe', __name__ -) - -# .. toggle_name: discussions.enable_reported_content_email_notifications -# .. toggle_implementation: CourseWaffleFlag -# .. toggle_default: False -# .. toggle_description: Waffle flag to toggle email notifications for reported content for moderators -# .. toggle_use_cases: temporary, open_edx -# .. toggle_creation_date: 2022-03-08 -# .. toggle_target_removal_date: 2022-12-31 -ENABLE_REPORTED_CONTENT_EMAIL_NOTIFICATIONS = CourseWaffleFlag( - f'{WAFFLE_FLAG_NAMESPACE}.enable_reported_content_email_notifications', __name__ -) diff --git a/lms/djangoapps/discussion/toggles_utils.py b/lms/djangoapps/discussion/toggles_utils.py index 982303d5c8d1..10ba260d8117 100644 --- a/lms/djangoapps/discussion/toggles_utils.py +++ b/lms/djangoapps/discussion/toggles_utils.py @@ -1,7 +1,7 @@ """ Utils for Discussions feature toggles """ -from lms.djangoapps.discussion.toggles import ENABLE_REPORTED_CONTENT_EMAIL_NOTIFICATIONS +from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings @@ -10,5 +10,5 @@ def reported_content_email_notification_enabled(course_key): Checks for relevant flag and setting and returns boolean for reported content email notification for course """ - return bool(ENABLE_REPORTED_CONTENT_EMAIL_NOTIFICATIONS.is_enabled(course_key) and + return bool(ENABLE_DISCUSSIONS_MFE.is_enabled(course_key) and CourseDiscussionSettings.get(course_key).reported_content_email_notifications) diff --git a/openedx/core/djangoapps/discussions/serializers.py b/openedx/core/djangoapps/discussions/serializers.py index 46778320c91d..88648a499598 100644 --- a/openedx/core/djangoapps/discussions/serializers.py +++ b/openedx/core/djangoapps/discussions/serializers.py @@ -7,7 +7,6 @@ from rest_framework import serializers from xmodule.modulestore.django import modulestore -from lms.djangoapps.discussion.toggles import ENABLE_REPORTED_CONTENT_EMAIL_NOTIFICATIONS 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 @@ -423,8 +422,6 @@ def to_representation(self, instance: CourseDiscussionSettings) -> dict: 'division_scheme': instance.division_scheme, 'available_division_schemes': available_division_schemes(course_key), 'reported_content_email_notifications': instance.reported_content_email_notifications, - 'reported_content_email_notifications_flag': - ENABLE_REPORTED_CONTENT_EMAIL_NOTIFICATIONS.is_enabled(course_key), } return payload diff --git a/openedx/core/djangoapps/discussions/tests/test_views.py b/openedx/core/djangoapps/discussions/tests/test_views.py index 5b182ebace64..cc17b56d226f 100644 --- a/openedx/core/djangoapps/discussions/tests/test_views.py +++ b/openedx/core/djangoapps/discussions/tests/test_views.py @@ -53,7 +53,6 @@ 'division_scheme': 'none', 'available_division_schemes': [], 'reported_content_email_notifications': False, - 'reported_content_email_notifications_flag': False, } DEFAULT_LTI_CONFIGURATION = { 'lti_1p1_client_key': '',