diff --git a/lms/djangoapps/discussion/rest_api/tasks.py b/lms/djangoapps/discussion/rest_api/tasks.py index 628d93d15bc1..5f0bf8ed40ea 100644 --- a/lms/djangoapps/discussion/rest_api/tasks.py +++ b/lms/djangoapps/discussion/rest_api/tasks.py @@ -5,12 +5,12 @@ from django.contrib.auth import get_user_model from edx_django_utils.monitoring import set_code_owner_attribute from opaque_keys.edx.locator import CourseKey + from lms.djangoapps.courseware.courses import get_course_with_access +from lms.djangoapps.discussion.rest_api.discussions_notifications import DiscussionNotificationSender from openedx.core.djangoapps.django_comment_common.comment_client import Comment from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread -from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS, ENABLE_COURSEWIDE_NOTIFICATIONS -from lms.djangoapps.discussion.rest_api.discussions_notifications import DiscussionNotificationSender - +from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS User = get_user_model() @@ -22,7 +22,7 @@ def send_thread_created_notification(thread_id, course_key_str, user_id): Send notification when a new thread is created """ course_key = CourseKey.from_string(course_key_str) - if not (ENABLE_NOTIFICATIONS.is_enabled(course_key) and ENABLE_COURSEWIDE_NOTIFICATIONS.is_enabled(course_key)): + if not ENABLE_NOTIFICATIONS.is_enabled(course_key): return thread = Thread(id=thread_id).retrieve() user = User.objects.get(id=user_id) diff --git a/lms/djangoapps/discussion/rest_api/tests/test_discussions_notifications.py b/lms/djangoapps/discussion/rest_api/tests/test_discussions_notifications.py index adc8235d43c6..eeed292037d1 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_discussions_notifications.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_discussions_notifications.py @@ -6,10 +6,8 @@ from unittest.mock import MagicMock, patch import pytest -from edx_toggles.toggles.testutils import override_waffle_flag from lms.djangoapps.discussion.rest_api.discussions_notifications import DiscussionNotificationSender -from lms.djangoapps.discussion.toggles import ENABLE_REPORTED_CONTENT_NOTIFICATIONS @patch('lms.djangoapps.discussion.rest_api.discussions_notifications.DiscussionNotificationSender' @@ -22,7 +20,6 @@ class TestDiscussionNotificationSender(unittest.TestCase): Tests for the DiscussionNotificationSender class """ - @override_waffle_flag(ENABLE_REPORTED_CONTENT_NOTIFICATIONS, True) def setUp(self): self.thread = MagicMock() self.course = MagicMock() diff --git a/lms/djangoapps/discussion/rest_api/tests/test_tasks.py b/lms/djangoapps/discussion/rest_api/tests/test_tasks.py index 29e63524b2b2..26146857366b 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_tasks.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_tasks.py @@ -8,15 +8,16 @@ import httpretty from django.conf import settings from edx_toggles.toggles.testutils import override_waffle_flag -from openedx_events.learning.signals import USER_NOTIFICATION_REQUESTED, COURSE_NOTIFICATION_REQUESTED +from openedx_events.learning.signals import COURSE_NOTIFICATION_REQUESTED, USER_NOTIFICATION_REQUESTED from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import StaffFactory, UserFactory from lms.djangoapps.discussion.django_comment_client.tests.factories import RoleFactory from lms.djangoapps.discussion.rest_api.tasks import ( + send_response_endorsed_notifications, send_response_notifications, - send_thread_created_notification, - send_response_endorsed_notifications) + send_thread_created_notification +) from lms.djangoapps.discussion.rest_api.tests.utils import ThreadMock, make_minimal_cs_thread from openedx.core.djangoapps.course_groups.models import CohortMembership, CourseCohortsSettings from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory @@ -28,7 +29,7 @@ FORUM_ROLE_STUDENT, CourseDiscussionSettings ) -from openedx.core.djangoapps.notifications.config.waffle import ENABLE_COURSEWIDE_NOTIFICATIONS, ENABLE_NOTIFICATIONS +from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory @@ -47,7 +48,6 @@ def _get_mfe_url(course_id, post_id): @httpretty.activate @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @override_waffle_flag(ENABLE_NOTIFICATIONS, active=True) -@override_waffle_flag(ENABLE_COURSEWIDE_NOTIFICATIONS, active=True) class TestNewThreadCreatedNotification(DiscussionAPIViewTestMixin, ModuleStoreTestCase): """ Test cases related to new_discussion_post and new_question_post notification types diff --git a/lms/djangoapps/discussion/signals/handlers.py b/lms/djangoapps/discussion/signals/handlers.py index 8c4991cd0289..35288cdbd9be 100644 --- a/lms/djangoapps/discussion/signals/handlers.py +++ b/lms/djangoapps/discussion/signals/handlers.py @@ -10,19 +10,17 @@ from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryLocator -from lms.djangoapps.discussion.rest_api.discussions_notifications import DiscussionNotificationSender -from lms.djangoapps.discussion.toggles import ENABLE_REPORTED_CONTENT_NOTIFICATIONS -from xmodule.modulestore.django import SignalHandler, modulestore - from lms.djangoapps.discussion import tasks +from lms.djangoapps.discussion.rest_api.discussions_notifications import DiscussionNotificationSender from lms.djangoapps.discussion.rest_api.tasks import ( + send_response_endorsed_notifications, send_response_notifications, - send_thread_created_notification, - send_response_endorsed_notifications + send_thread_created_notification ) from openedx.core.djangoapps.django_comment_common import signals from openedx.core.djangoapps.site_configuration.models import SiteConfiguration from openedx.core.djangoapps.theming.helpers import get_current_site +from xmodule.modulestore.django import SignalHandler, modulestore log = logging.getLogger(__name__) @@ -101,8 +99,6 @@ def send_reported_content_notification(sender, user, post, **kwargs): Sends notification for reported content. """ course_key = CourseKey.from_string(post.course_id) - if not ENABLE_REPORTED_CONTENT_NOTIFICATIONS.is_enabled(course_key): - return course = modulestore().get_course(course_key) DiscussionNotificationSender(post, course, user).send_reported_content_notification() diff --git a/lms/djangoapps/discussion/toggles.py b/lms/djangoapps/discussion/toggles.py index 29918c45a983..a1c292a4734f 100644 --- a/lms/djangoapps/discussion/toggles.py +++ b/lms/djangoapps/discussion/toggles.py @@ -12,15 +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_reported_content_notifications -# .. toggle_implementation: CourseWaffleFlag -# .. toggle_default: False -# .. toggle_description: Waffle flag to enable reported content notifications. -# .. toggle_use_cases: temporary, open_edx -# .. toggle_creation_date: 18-Jan-2024 -# .. toggle_target_removal_date: 18-Feb-2024 -ENABLE_REPORTED_CONTENT_NOTIFICATIONS = CourseWaffleFlag( - f'{WAFFLE_FLAG_NAMESPACE}.enable_reported_content_notifications', - __name__ -) diff --git a/openedx/core/djangoapps/notifications/config/waffle.py b/openedx/core/djangoapps/notifications/config/waffle.py index fa1d02adf1d3..af89bb68574f 100644 --- a/openedx/core/djangoapps/notifications/config/waffle.py +++ b/openedx/core/djangoapps/notifications/config/waffle.py @@ -18,46 +18,6 @@ # .. toggle_tickets: INF-866 ENABLE_NOTIFICATIONS = CourseWaffleFlag(f'{WAFFLE_NAMESPACE}.enable_notifications', __name__) -# .. toggle_name: notifications.show_notifications_tray -# .. toggle_implementation: CourseWaffleFlag -# .. toggle_default: False -# .. toggle_description: Waffle flag to show notifications tray -# .. toggle_use_cases: temporary, open_edx -# .. toggle_creation_date: 2023-06-07 -# .. toggle_target_removal_date: 2023-12-07 -# .. toggle_tickets: INF-902 -SHOW_NOTIFICATIONS_TRAY = CourseWaffleFlag(f"{WAFFLE_NAMESPACE}.show_notifications_tray", __name__) - -# .. toggle_name: notifications.enable_notifications_filters -# .. toggle_implementation: CourseWaffleFlag -# .. toggle_default: False -# .. toggle_description: Waffle flag to enable filters in notifications task -# .. toggle_use_cases: temporary, open_edx -# .. toggle_creation_date: 2023-06-07 -# .. toggle_target_removal_date: 2024-06-01 -# .. toggle_tickets: INF-902 -ENABLE_NOTIFICATIONS_FILTERS = CourseWaffleFlag(f"{WAFFLE_NAMESPACE}.enable_notifications_filters", __name__) - -# .. toggle_name: notifications.enable_coursewide_notifications -# .. toggle_implementation: CourseWaffleFlag -# .. toggle_default: False -# .. toggle_description: Waffle flag to enable coursewide notifications -# .. toggle_use_cases: temporary, open_edx -# .. toggle_creation_date: 2023-10-25 -# .. toggle_target_removal_date: 2024-06-01 -# .. toggle_tickets: INF-1145 -ENABLE_COURSEWIDE_NOTIFICATIONS = CourseWaffleFlag(f"{WAFFLE_NAMESPACE}.enable_coursewide_notifications", __name__) - -# .. toggle_name: notifications.enable_ora_staff_notifications -# .. toggle_implementation: CourseWaffleFlag -# .. toggle_default: False -# .. toggle_description: Waffle flag to enable ORA staff notifications -# .. toggle_use_cases: temporary, open_edx -# .. toggle_creation_date: 2024-04-04 -# .. toggle_target_removal_date: 2024-06-04 -# .. toggle_tickets: INF-1304 -ENABLE_ORA_STAFF_NOTIFICATION = CourseWaffleFlag(f"{WAFFLE_NAMESPACE}.enable_ora_staff_notifications", __name__) - # .. toggle_name: notifications.enable_email_notifications # .. toggle_implementation: WaffleFlag # .. toggle_default: False diff --git a/openedx/core/djangoapps/notifications/handlers.py b/openedx/core/djangoapps/notifications/handlers.py index 6d7e7a77148f..505f4b5e7024 100644 --- a/openedx/core/djangoapps/notifications/handlers.py +++ b/openedx/core/djangoapps/notifications/handlers.py @@ -8,20 +8,20 @@ from django.dispatch import receiver from openedx_events.learning.signals import ( COURSE_ENROLLMENT_CREATED, - COURSE_UNENROLLMENT_COMPLETED, - USER_NOTIFICATION_REQUESTED, COURSE_NOTIFICATION_REQUESTED, + COURSE_UNENROLLMENT_COMPLETED, + USER_NOTIFICATION_REQUESTED ) from common.djangoapps.student.models import CourseEnrollment from openedx.core.djangoapps.notifications.audience_filters import ( - ForumRoleAudienceFilter, - EnrollmentAudienceFilter, - TeamAudienceFilter, CohortAudienceFilter, CourseRoleAudienceFilter, + EnrollmentAudienceFilter, + ForumRoleAudienceFilter, + TeamAudienceFilter ) -from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS, ENABLE_ORA_STAFF_NOTIFICATION +from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS from openedx.core.djangoapps.notifications.models import CourseNotificationPreference log = logging.getLogger(__name__) @@ -108,11 +108,6 @@ def generate_course_notifications(signal, sender, course_notification_data, meta """ Watches for COURSE_NOTIFICATION_REQUESTED signal and calls send_notifications task """ - if ( - course_notification_data.notification_type == 'ora_staff_notification' - and not ENABLE_ORA_STAFF_NOTIFICATION.is_enabled(course_notification_data.course_key) - ): - return from openedx.core.djangoapps.notifications.tasks import send_notifications course_notification_data = course_notification_data.__dict__ diff --git a/openedx/core/djangoapps/notifications/serializers.py b/openedx/core/djangoapps/notifications/serializers.py index 3b6877cc29f7..d56fb820f64a 100644 --- a/openedx/core/djangoapps/notifications/serializers.py +++ b/openedx/core/djangoapps/notifications/serializers.py @@ -12,7 +12,7 @@ get_notification_channels, get_additional_notification_channel_settings ) from .base_notification import COURSE_NOTIFICATION_APPS, COURSE_NOTIFICATION_TYPES, EmailCadence -from .utils import filter_course_wide_preferences, remove_preferences_with_no_access +from .utils import remove_preferences_with_no_access def add_info_to_notification_config(config_obj): @@ -73,7 +73,6 @@ def to_representation(self, instance): course_id = self.context['course_id'] user = self.context['user'] preferences = add_info_to_notification_config(preferences) - preferences = filter_course_wide_preferences(course_id, preferences) preferences = remove_preferences_with_no_access(preferences, user) return preferences diff --git a/openedx/core/djangoapps/notifications/tasks.py b/openedx/core/djangoapps/notifications/tasks.py index a876b513cbcf..4fcec36214af 100644 --- a/openedx/core/djangoapps/notifications/tasks.py +++ b/openedx/core/djangoapps/notifications/tasks.py @@ -18,13 +18,13 @@ get_default_values_of_preference, get_notification_content ) -from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS, ENABLE_NOTIFICATIONS_FILTERS +from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS from openedx.core.djangoapps.notifications.events import notification_generated_event from openedx.core.djangoapps.notifications.filters import NotificationFilter from openedx.core.djangoapps.notifications.models import ( CourseNotificationPreference, Notification, - get_course_notification_preference_config_version, + get_course_notification_preference_config_version ) from openedx.core.djangoapps.notifications.utils import clean_arguments, get_list_in_batches @@ -137,10 +137,9 @@ def send_notifications(user_ids, course_key: str, app_name, notification_type, c generated_notification_audience = [] for batch_user_ids in get_list_in_batches(user_ids, batch_size): - if ENABLE_NOTIFICATIONS_FILTERS.is_enabled(course_key): - logger.info(f'Sending notifications to {len(batch_user_ids)} users in {course_key}') - batch_user_ids = NotificationFilter().apply_filters(batch_user_ids, course_key, notification_type) - logger.info(f'After applying filters, sending notifications to {len(batch_user_ids)} users in {course_key}') + logger.info(f'Sending notifications to {len(batch_user_ids)} users in {course_key}') + batch_user_ids = NotificationFilter().apply_filters(batch_user_ids, course_key, notification_type) + logger.info(f'After applying filters, sending notifications to {len(batch_user_ids)} users in {course_key}') # check if what is preferences of user and make decision to send notification or not preferences = CourseNotificationPreference.objects.filter( diff --git a/openedx/core/djangoapps/notifications/tests/test_tasks.py b/openedx/core/djangoapps/notifications/tests/test_tasks.py index 036d4d326198..5058c0f492c3 100644 --- a/openedx/core/djangoapps/notifications/tests/test_tasks.py +++ b/openedx/core/djangoapps/notifications/tests/test_tasks.py @@ -2,12 +2,12 @@ Tests for notifications tasks. """ +import datetime from unittest.mock import patch -import datetime import ddt -from django.core.exceptions import ValidationError from django.conf import settings +from django.core.exceptions import ValidationError from edx_toggles.toggles.testutils import override_waffle_flag from common.djangoapps.student.models import CourseEnrollment @@ -15,7 +15,6 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from .utils import create_notification from ..config.waffle import ENABLE_NOTIFICATIONS from ..models import CourseNotificationPreference, Notification from ..tasks import ( @@ -24,6 +23,7 @@ send_notifications, update_user_preference ) +from .utils import create_notification @patch('openedx.core.djangoapps.notifications.models.COURSE_NOTIFICATION_CONFIG_VERSION', 1) @@ -225,7 +225,6 @@ def test_notification_not_created_when_context_is_incomplete(self): @ddt.ddt -@patch('openedx.core.djangoapps.notifications.tasks.ENABLE_NOTIFICATIONS_FILTERS.is_enabled', lambda x: False) class SendBatchNotificationsTest(ModuleStoreTestCase): """ Test that notification and notification preferences are created in batches @@ -255,9 +254,9 @@ def _create_users(self, num_of_users): @override_waffle_flag(ENABLE_NOTIFICATIONS, active=True) @ddt.data( - (settings.NOTIFICATION_CREATION_BATCH_SIZE, 1, 2), - (settings.NOTIFICATION_CREATION_BATCH_SIZE + 10, 2, 4), - (settings.NOTIFICATION_CREATION_BATCH_SIZE - 10, 1, 2), + (settings.NOTIFICATION_CREATION_BATCH_SIZE, 7, 3), + (settings.NOTIFICATION_CREATION_BATCH_SIZE + 10, 9, 6), + (settings.NOTIFICATION_CREATION_BATCH_SIZE - 10, 7, 3), ) @ddt.unpack def test_notification_is_send_in_batch(self, creation_size, prefs_query_count, notifications_query_count): @@ -307,7 +306,7 @@ def test_preference_not_created_for_default_off_preference(self): "username": "Test Author" } with override_waffle_flag(ENABLE_NOTIFICATIONS, active=True): - with self.assertNumQueries(1): + with self.assertNumQueries(7): send_notifications(user_ids, str(self.course.id), notification_app, notification_type, context, "http://test.url") @@ -326,7 +325,7 @@ def test_preference_created_for_default_on_preference(self): "replier_name": "Replier Name" } with override_waffle_flag(ENABLE_NOTIFICATIONS, active=True): - with self.assertNumQueries(3): + with self.assertNumQueries(9): send_notifications(user_ids, str(self.course.id), notification_app, notification_type, context, "http://test.url") diff --git a/openedx/core/djangoapps/notifications/tests/test_views.py b/openedx/core/djangoapps/notifications/tests/test_views.py index ca5572ed9f55..b90d22063874 100644 --- a/openedx/core/djangoapps/notifications/tests/test_views.py +++ b/openedx/core/djangoapps/notifications/tests/test_views.py @@ -19,18 +19,13 @@ from common.djangoapps.student.roles import CourseStaffRole from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.discussion.django_comment_client.tests.factories import RoleFactory -from lms.djangoapps.discussion.toggles import ENABLE_REPORTED_CONTENT_NOTIFICATIONS from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR ) -from openedx.core.djangoapps.notifications.config.waffle import ( - ENABLE_COURSEWIDE_NOTIFICATIONS, - ENABLE_NOTIFICATIONS, - SHOW_NOTIFICATIONS_TRAY -) +from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS from openedx.core.djangoapps.notifications.models import CourseNotificationPreference, Notification from openedx.core.djangoapps.notifications.serializers import NotificationCourseEnrollmentSerializer from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -80,26 +75,23 @@ def setUp(self): ) @override_waffle_flag(ENABLE_NOTIFICATIONS, active=True) - @ddt.data((False,), (True,)) @ddt.unpack - def test_course_enrollment_list_view(self, show_notifications_tray): + def test_course_enrollment_list_view(self): """ Test the CourseEnrollmentListView. """ self.client.login(username=self.user.username, password=self.TEST_PASSWORD) - # Enable or disable the waffle flag based on the test case data - with override_waffle_flag(SHOW_NOTIFICATIONS_TRAY, active=show_notifications_tray): - url = reverse('enrollment-list') - response = self.client.get(url) + url = reverse('enrollment-list') + response = self.client.get(url) - self.assertEqual(response.status_code, status.HTTP_200_OK) - data = response.data['results'] - enrollments = CourseEnrollment.objects.filter(user=self.user, is_active=True) - expected_data = NotificationCourseEnrollmentSerializer(enrollments, many=True).data + self.assertEqual(response.status_code, status.HTTP_200_OK) + data = response.data['results'] + enrollments = CourseEnrollment.objects.filter(user=self.user, is_active=True) + expected_data = NotificationCourseEnrollmentSerializer(enrollments, many=True).data - self.assertEqual(len(data), 1) - self.assertEqual(data, expected_data) - self.assertEqual(response.data['show_preferences'], show_notifications_tray) + self.assertEqual(len(data), 1) + self.assertEqual(data, expected_data) + self.assertEqual(response.data['show_preferences'], True) def test_course_enrollment_api_permission(self): """ @@ -172,7 +164,6 @@ def test_course_enrollment_post_save(self): @override_waffle_flag(ENABLE_NOTIFICATIONS, active=True) -@override_waffle_flag(ENABLE_REPORTED_CONTENT_NOTIFICATIONS, active=True) @ddt.ddt class UserNotificationPreferenceAPITest(ModuleStoreTestCase): """ @@ -321,11 +312,6 @@ def _expected_api_response(self, course=None): } } } - if not ENABLE_COURSEWIDE_NOTIFICATIONS.is_enabled(course.id): - app_prefs = response['notification_preference_config']['discussion'] - notification_types = app_prefs['notification_types'] - for notification_type in ['new_discussion_post', 'new_question_post']: - notification_types.pop(notification_type) return response def test_get_user_notification_preference_without_login(self): @@ -336,7 +322,6 @@ def test_get_user_notification_preference_without_login(self): self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) @mock.patch("eventtracking.tracker.emit") - @override_waffle_flag(ENABLE_COURSEWIDE_NOTIFICATIONS, active=True) def test_get_user_notification_preference(self, mock_emit): """ Test get user notification preference. @@ -351,7 +336,6 @@ def test_get_user_notification_preference(self, mock_emit): self.assertEqual(event_name, 'edx.notifications.preferences.viewed') @mock.patch("eventtracking.tracker.emit") - @override_waffle_flag(ENABLE_COURSEWIDE_NOTIFICATIONS, active=True) @mock.patch.dict(COURSE_NOTIFICATION_TYPES, { **COURSE_NOTIFICATION_TYPES, **{ @@ -473,7 +457,6 @@ def test_info_is_not_saved_in_json(self): @override_waffle_flag(ENABLE_NOTIFICATIONS, active=True) -@override_waffle_flag(ENABLE_REPORTED_CONTENT_NOTIFICATIONS, active=True) @ddt.ddt class UserNotificationChannelPreferenceAPITest(ModuleStoreTestCase): """ @@ -624,11 +607,6 @@ def _expected_api_response(self, course=None): } } } - if not ENABLE_COURSEWIDE_NOTIFICATIONS.is_enabled(course.id): - app_prefs = response['notification_preference_config']['discussion'] - notification_types = app_prefs['notification_types'] - for notification_type in ['new_discussion_post', 'new_question_post']: - notification_types.pop(notification_type) return response @ddt.data( @@ -910,24 +888,21 @@ def setUp(self): Notification.objects.create(user=self.user, app_name='App Name 2', notification_type='Type A') Notification.objects.create(user=self.user, app_name='App Name 3', notification_type='Type C') - @ddt.data((False,), (True,)) + @override_waffle_flag(ENABLE_NOTIFICATIONS, active=True) @ddt.unpack - def test_get_unseen_notifications_count_with_show_notifications_tray(self, show_notifications_tray_enabled): + def test_get_unseen_notifications_count_with_show_notifications_tray(self): """ Test that the endpoint returns the correct count of unseen notifications and show_notifications_tray value. """ self.client.login(username=self.user.username, password=self.TEST_PASSWORD) + # Make a request to the view + response = self.client.get(self.url) - # Enable or disable the waffle flag based on the test case data - with override_waffle_flag(SHOW_NOTIFICATIONS_TRAY, active=show_notifications_tray_enabled): - # Make a request to the view - response = self.client.get(self.url) - - self.assertEqual(response.status_code, 200) - self.assertEqual(response.data['count'], 4) - self.assertEqual(response.data['count_by_app_name'], { - 'App Name 1': 2, 'App Name 2': 1, 'App Name 3': 1, 'discussion': 0, 'updates': 0, 'grading': 0}) - self.assertEqual(response.data['show_notifications_tray'], show_notifications_tray_enabled) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data['count'], 4) + self.assertEqual(response.data['count_by_app_name'], { + 'App Name 1': 2, 'App Name 2': 1, 'App Name 3': 1, 'discussion': 0, 'updates': 0, 'grading': 0}) + self.assertEqual(response.data['show_notifications_tray'], True) def test_get_unseen_notifications_count_for_unauthenticated_user(self): """ diff --git a/openedx/core/djangoapps/notifications/utils.py b/openedx/core/djangoapps/notifications/utils.py index 5ce592bb413d..249eaf874995 100644 --- a/openedx/core/djangoapps/notifications/utils.py +++ b/openedx/core/djangoapps/notifications/utils.py @@ -3,13 +3,11 @@ """ from typing import Dict, List -from common.djangoapps.student.models import CourseEnrollment, CourseAccessRole -from lms.djangoapps.discussion.toggles import ENABLE_REPORTED_CONTENT_NOTIFICATIONS +from common.djangoapps.student.models import CourseAccessRole, CourseEnrollment from openedx.core.djangoapps.django_comment_common.models import Role +from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS from openedx.core.lib.cache_utils import request_cached -from .config.waffle import ENABLE_COURSEWIDE_NOTIFICATIONS, SHOW_NOTIFICATIONS_TRAY - def find_app_in_normalized_apps(app_name, apps_list): """ @@ -42,7 +40,7 @@ def get_show_notifications_tray(user): ).values_list('course_id', flat=True) for course_id in learner_enrollments_course_ids: - if SHOW_NOTIFICATIONS_TRAY.is_enabled(course_id): + if ENABLE_NOTIFICATIONS.is_enabled(course_id): show_notifications_tray = True break @@ -58,27 +56,6 @@ def get_list_in_batches(input_list, batch_size): yield input_list[index: index + batch_size] -def filter_course_wide_preferences(course_key, preferences): - """ - If course wide notifications is disabled for course, it filters course_wide - preferences from response - """ - if ENABLE_COURSEWIDE_NOTIFICATIONS.is_enabled(course_key): - return preferences - course_wide_notification_types = ['new_discussion_post', 'new_question_post'] - - if not ENABLE_REPORTED_CONTENT_NOTIFICATIONS.is_enabled(course_key): - course_wide_notification_types.append('content_reported') - - config = preferences['notification_preference_config'] - for app_prefs in config.values(): - notification_types = app_prefs['notification_types'] - for course_wide_type in course_wide_notification_types: - if course_wide_type in notification_types.keys(): - notification_types.pop(course_wide_type) - return preferences - - def get_user_forum_roles(user_id: int, course_id: str) -> List[str]: """ Get forum roles for the given user in the specified course. diff --git a/openedx/core/djangoapps/notifications/views.py b/openedx/core/djangoapps/notifications/views.py index cc830dbb8d7f..547847f55e55 100644 --- a/openedx/core/djangoapps/notifications/views.py +++ b/openedx/core/djangoapps/notifications/views.py @@ -375,7 +375,7 @@ def get(self, request): .annotate(count=Count('*')) ) count_total = 0 - show_notifications_tray = get_show_notifications_tray(request.user) + show_notifications_tray = get_show_notifications_tray(self.request.user) count_by_app_name_dict = { app_name: 0 for app_name in COURSE_NOTIFICATION_APPS