chore: removed obsolete feature flags (#34942)

This commit is contained in:
Ahtisham Shahid
2024-06-27 13:58:54 +05:00
committed by GitHub
parent 8c40057c10
commit 15e2834825
13 changed files with 57 additions and 172 deletions

View File

@@ -5,12 +5,12 @@ from celery import shared_task
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)

View File

@@ -6,10 +6,8 @@ import unittest
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()

View File

@@ -8,15 +8,16 @@ import ddt
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 @@ from openedx.core.djangoapps.django_comment_common.models import (
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

View File

@@ -10,19 +10,17 @@ from django.utils.html import strip_tags
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()

View File

@@ -12,15 +12,3 @@ from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag
# .. 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__
)

View File

@@ -18,46 +18,6 @@ WAFFLE_NAMESPACE = 'notifications'
# .. 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

View File

@@ -8,20 +8,20 @@ from django.db import IntegrityError, transaction
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__

View File

@@ -12,7 +12,7 @@ from openedx.core.djangoapps.notifications.models import (
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 @@ class UserCourseNotificationPreferenceSerializer(serializers.ModelSerializer):
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

View File

@@ -18,13 +18,13 @@ from openedx.core.djangoapps.notifications.base_notification import (
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(

View File

@@ -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 common.djangoapps.student.tests.factories import UserFactory
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 @@ from ..tasks import (
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 @@ class SendNotificationsTest(ModuleStoreTestCase):
@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 @@ class SendBatchNotificationsTest(ModuleStoreTestCase):
@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 @@ class SendBatchNotificationsTest(ModuleStoreTestCase):
"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 @@ class SendBatchNotificationsTest(ModuleStoreTestCase):
"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")

View File

@@ -19,18 +19,13 @@ from common.djangoapps.student.models import CourseEnrollment
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 @@ class CourseEnrollmentListViewTest(ModuleStoreTestCase):
)
@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 @@ class CourseEnrollmentPostSaveTest(ModuleStoreTestCase):
@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 @@ class UserNotificationPreferenceAPITest(ModuleStoreTestCase):
}
}
}
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 @@ class UserNotificationPreferenceAPITest(ModuleStoreTestCase):
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 @@ class UserNotificationPreferenceAPITest(ModuleStoreTestCase):
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 @@ class UserNotificationPreferenceAPITest(ModuleStoreTestCase):
@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 @@ class UserNotificationChannelPreferenceAPITest(ModuleStoreTestCase):
}
}
}
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 @@ class NotificationCountViewSetTestCase(ModuleStoreTestCase):
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):
"""

View File

@@ -3,13 +3,11 @@ Utils function for notifications app
"""
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.

View File

@@ -375,7 +375,7 @@ class NotificationCountView(APIView):
.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