Skip to content

Commit 4793f88

Browse files
chore: Remove notification app waffle flags (#37086)
1 parent c988688 commit 4793f88

14 files changed

Lines changed: 89 additions & 218 deletions

File tree

lms/djangoapps/discussion/rest_api/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def _format_datetime(dt):
379379
],
380380
'show_discussions': bool(discussion_tab and discussion_tab.is_enabled(course, request.user)),
381381
'is_notify_all_learners_enabled': can_user_notify_all_learners(
382-
course_key, user_roles, is_course_staff, is_course_admin
382+
user_roles, is_course_staff, is_course_admin
383383
),
384384
'captcha_settings': {
385385
'enabled': is_captcha_enabled(course_key),

lms/djangoapps/discussion/rest_api/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def send_thread_created_notification(thread_id, course_key_str, user_id, notify_
4040
is_course_staff = CourseStaffRole(course_key).has_user(user)
4141
is_course_admin = CourseInstructorRole(course_key).has_user(user)
4242
user_roles = get_user_role_names(user, course_key)
43-
if not can_user_notify_all_learners(course_key, user_roles, is_course_staff, is_course_admin):
43+
if not can_user_notify_all_learners(user_roles, is_course_staff, is_course_admin):
4444
return
4545

4646
course = get_course_with_access(user, 'load', course_key, check_if_enrolled=True)

lms/djangoapps/discussion/rest_api/tests/test_tasks.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
FORUM_ROLE_STUDENT,
2828
CourseDiscussionSettings
2929
)
30-
from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS, ENABLE_NOTIFY_ALL_LEARNERS
30+
from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS
3131
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
3232
from xmodule.modulestore.tests.factories import CourseFactory
3333

@@ -187,14 +187,14 @@ def test_not_authenticated(self):
187187
"""
188188

189189
@ddt.data(
190-
('new_question_post', False, False),
191-
('new_discussion_post', False, False),
192-
('new_discussion_post', True, True),
193-
('new_discussion_post', True, False),
190+
('new_question_post', False),
191+
('new_discussion_post', False),
192+
('new_discussion_post', True),
193+
('new_discussion_post', True),
194194
)
195195
@ddt.unpack
196196
def test_notification_is_send_to_all_enrollments(
197-
self, notification_type, notify_all_learners, waffle_flag_enabled
197+
self, notification_type, notify_all_learners
198198
):
199199
"""
200200
Tests notification is sent to all users if course is not cohorted
@@ -204,29 +204,27 @@ def test_notification_is_send_to_all_enrollments(
204204
"discussion" if notification_type == "new_discussion_post" else "question"
205205
)
206206

207-
with override_waffle_flag(ENABLE_NOTIFY_ALL_LEARNERS, active=waffle_flag_enabled):
208-
thread = self._create_thread(thread_type=thread_type)
209-
handler = mock.Mock()
210-
COURSE_NOTIFICATION_REQUESTED.connect(handler)
207+
thread = self._create_thread(thread_type=thread_type)
208+
handler = mock.Mock()
209+
COURSE_NOTIFICATION_REQUESTED.connect(handler)
210+
211+
send_thread_created_notification(
212+
thread['id'],
213+
str(self.course.id),
214+
self.author.id,
215+
notify_all_learners
216+
)
217+
self.assertEqual(handler.call_count, 1)
211218

212-
send_thread_created_notification(
213-
thread['id'],
214-
str(self.course.id),
215-
self.author.id,
216-
notify_all_learners
219+
if handler.call_count:
220+
course_notification_data = handler.call_args[1]['course_notification_data']
221+
expected_type = (
222+
'new_instructor_all_learners_post'
223+
if notify_all_learners
224+
else notification_type
217225
)
218-
expected_handler_calls = 0 if notify_all_learners and not waffle_flag_enabled else 1
219-
self.assertEqual(handler.call_count, expected_handler_calls)
220-
221-
if handler.call_count:
222-
course_notification_data = handler.call_args[1]['course_notification_data']
223-
expected_type = (
224-
'new_instructor_all_learners_post'
225-
if notify_all_learners and waffle_flag_enabled
226-
else notification_type
227-
)
228-
self.assertEqual(course_notification_data.notification_type, expected_type)
229-
self.assertEqual(course_notification_data.audience_filters, {})
226+
self.assertEqual(course_notification_data.notification_type, expected_type)
227+
self.assertEqual(course_notification_data.audience_filters, {})
230228

231229
@ddt.data(
232230
('cohort_1', 'new_question_post'),

lms/djangoapps/discussion/rest_api/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from lms.djangoapps.discussion.config.settings import ENABLE_CAPTCHA_IN_DISCUSSION
2020
from lms.djangoapps.discussion.django_comment_client.utils import has_discussion_privileges
21-
from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFY_ALL_LEARNERS
2221
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, PostingRestriction
2322
from openedx.core.djangoapps.django_comment_common.models import (
2423
FORUM_ROLE_ADMINISTRATOR,
@@ -393,12 +392,11 @@ def is_posting_allowed(posting_restrictions: str, blackout_schedules: List):
393392
return False
394393

395394

396-
def can_user_notify_all_learners(course_key, user_roles, is_course_staff, is_course_admin):
395+
def can_user_notify_all_learners(user_roles, is_course_staff, is_course_admin):
397396
"""
398397
Check if user posting is allowed to notify all learners based on the given restrictions
399398
400399
Args:
401-
course_key (CourseKey): CourseKey for which user creating any discussion post.
402400
user_roles (Dict): Roles of the posting user
403401
is_course_staff (Boolean): Whether the user has a course staff access.
404402
is_course_admin (Boolean): Whether the user has a course admin access.
@@ -412,7 +410,7 @@ def can_user_notify_all_learners(course_key, user_roles, is_course_staff, is_cou
412410
is_course_admin,
413411
])
414412

415-
return is_staff_or_instructor and ENABLE_NOTIFY_ALL_LEARNERS.is_enabled(course_key)
413+
return is_staff_or_instructor
416414

417415

418416
def verify_recaptcha_token(token):

openedx/core/djangoapps/notifications/config/waffle.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,6 @@
2929
# .. toggle_tickets: INF-1259
3030
ENABLE_EMAIL_NOTIFICATIONS = WaffleFlag(f'{WAFFLE_NAMESPACE}.enable_email_notifications', __name__)
3131

32-
# .. toggle_name: notifications.enable_ora_grade_notifications
33-
# .. toggle_implementation: CourseWaffleFlag
34-
# .. toggle_default: False
35-
# .. toggle_description: Waffle flag to enable ORA grade notifications
36-
# .. toggle_use_cases: temporary, open_edx
37-
# .. toggle_creation_date: 2024-09-10
38-
# .. toggle_target_removal_date: 2024-10-10
39-
# .. toggle_tickets: INF-1304
40-
ENABLE_ORA_GRADE_NOTIFICATION = CourseWaffleFlag(f"{WAFFLE_NAMESPACE}.enable_ora_grade_notifications", __name__)
41-
42-
# .. toggle_name: notifications.enable_notification_grouping
43-
# .. toggle_implementation: CourseWaffleFlag
44-
# .. toggle_default: False
45-
# .. toggle_description: Waffle flag to enable the Notifications Grouping feature
46-
# .. toggle_use_cases: temporary, open_edx
47-
# .. toggle_creation_date: 2024-07-22
48-
# .. toggle_target_removal_date: 2025-06-01
49-
# .. toggle_warning: When the flag is ON, Notifications Grouping feature is enabled.
50-
# .. toggle_tickets: INF-1472
51-
ENABLE_NOTIFICATION_GROUPING = CourseWaffleFlag(f'{WAFFLE_NAMESPACE}.enable_notification_grouping', __name__)
52-
53-
# .. toggle_name: notifications.post_enable_notify_all_learners
54-
# .. toggle_implementation: CourseWaffleFlag
55-
# .. toggle_default: False
56-
# .. toggle_description: Waffle flag to enable the notify all learners on discussion post
57-
# .. toggle_use_cases: open_edx
58-
# .. toggle_creation_date: 2025-06-11
59-
# .. toggle_warning: When the flag is ON, notification to all learners feature is enabled on discussion post.
60-
# .. toggle_tickets: INF-1917
61-
ENABLE_NOTIFY_ALL_LEARNERS = CourseWaffleFlag(f'{WAFFLE_NAMESPACE}.enable_post_notify_all_learners', __name__)
62-
6332
# .. toggle_name: notifications.enable_push_notifications
6433
# .. toggle_implementation: CourseWaffleFlag
6534
# .. toggle_default: False
@@ -69,14 +38,3 @@
6938
# .. toggle_target_removal_date: 2026-05-27
7039
# .. toggle_warning: When the flag is ON, Notifications will go through ace push channels.
7140
ENABLE_PUSH_NOTIFICATIONS = CourseWaffleFlag(f'{WAFFLE_NAMESPACE}.enable_push_notifications', __name__)
72-
73-
# .. toggle_name: notifications.enable_account_level_preferences
74-
# .. toggle_implementation: CourseWaffleFlag
75-
# .. toggle_default: False
76-
# .. toggle_description: Waffle flag to enable account level preferences for notifications
77-
# .. toggle_use_cases: temporary, open_edx
78-
# .. toggle_creation_date: 2025-04-29
79-
# .. toggle_target_removal_date: 2025-07-29
80-
# .. toggle_warning: When the flag is ON, account level preferences for notifications are enabled.
81-
# .. toggle_tickets: INF-1472
82-
ENABLE_ACCOUNT_LEVEL_PREFERENCES = WaffleFlag(f'{WAFFLE_NAMESPACE}.enable_account_level_preferences', __name__)

openedx/core/djangoapps/notifications/email/tasks.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from edx_ace.recipient import Recipient
1111
from edx_django_utils.monitoring import set_code_owner_attribute
1212

13-
from openedx.core.djangoapps.notifications.config.waffle import ENABLE_ACCOUNT_LEVEL_PREFERENCES
1413
from openedx.core.djangoapps.notifications.email_notifications import EmailCadence
1514
from openedx.core.djangoapps.notifications.models import (
1615
CourseNotificationPreference,
@@ -26,12 +25,10 @@
2625
create_email_digest_context,
2726
create_email_template_context,
2827
filter_email_enabled_notifications,
29-
filter_notification_with_email_enabled_preferences,
3028
get_course_info,
3129
get_language_preference_for_users,
3230
get_start_end_date,
3331
get_text_for_notification_type,
34-
get_unique_course_ids,
3532
is_email_notification_flag_enabled,
3633
)
3734

@@ -102,14 +99,9 @@ def send_digest_email_to_user(user, cadence_type, start_date, end_date, user_lan
10299
return
103100

104101
with translation_override(user_language):
105-
if ENABLE_ACCOUNT_LEVEL_PREFERENCES.is_enabled():
106-
preferences = NotificationPreference.objects.filter(user=user)
107-
notifications = filter_email_enabled_notifications(notifications, preferences, user,
108-
cadence_type=cadence_type)
109-
else:
110-
course_ids = get_unique_course_ids(notifications)
111-
preferences = get_user_preferences_for_courses(course_ids, user)
112-
notifications = filter_notification_with_email_enabled_preferences(notifications, preferences, cadence_type)
102+
preferences = NotificationPreference.objects.filter(user=user)
103+
notifications = filter_email_enabled_notifications(notifications, preferences, user,
104+
cadence_type=cadence_type)
113105

114106
if not notifications:
115107
logger.info(f'<Email Cadence> No filtered notification for {user.username} ==Temp Log==')

openedx/core/djangoapps/notifications/email/tests/test_tasks.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from common.djangoapps.student.tests.factories import UserFactory
1212
from openedx.core.djangoapps.notifications.config.waffle import (
13-
ENABLE_ACCOUNT_LEVEL_PREFERENCES, ENABLE_NOTIFICATIONS, ENABLE_EMAIL_NOTIFICATIONS
13+
ENABLE_NOTIFICATIONS, ENABLE_EMAIL_NOTIFICATIONS
1414
)
1515
from openedx.core.djangoapps.notifications.tasks import send_notifications
1616
from openedx.core.djangoapps.notifications.email_notifications import EmailCadence
@@ -127,7 +127,6 @@ def test_notification_content(self, cadence_type, created_time, notification_cre
127127
assert mock_func.called is notification_created
128128

129129

130-
@override_waffle_flag(ENABLE_ACCOUNT_LEVEL_PREFERENCES, True)
131130
@ddt.ddt
132131
class TestEmailDigestForUserWithAccountPreferences(ModuleStoreTestCase):
133132
"""
@@ -331,23 +330,22 @@ def test_email_send_for_digest_preference(self, mock_func):
331330
self.preference.save()
332331
with override_waffle_flag(ENABLE_EMAIL_NOTIFICATIONS, True):
333332
send_digest_email_to_user(self.user, EmailCadence.DAILY, start_date, end_date)
334-
assert mock_func.called
333+
assert not mock_func.called
335334

336-
@ddt.data(True, False)
337335
@patch('edx_ace.ace.send')
338-
def test_email_send_for_email_preference_value(self, pref_value, mock_func):
336+
def test_email_send_for_email_preference_value(self, mock_func):
339337
"""
340338
Tests email is sent iff preference value is True
341339
"""
342340
start_date, end_date = get_start_end_date(EmailCadence.DAILY)
343341
config = self.preference.notification_preference_config
344342
types = config['discussion']['notification_types']
345343
types['new_discussion_post']['email_cadence'] = EmailCadence.DAILY
346-
types['new_discussion_post']['email'] = pref_value
344+
types['new_discussion_post']['email'] = True
347345
self.preference.save()
348346
with override_waffle_flag(ENABLE_EMAIL_NOTIFICATIONS, True):
349347
send_digest_email_to_user(self.user, EmailCadence.DAILY, start_date, end_date)
350-
assert mock_func.called is pref_value
348+
assert not mock_func.called
351349

352350
@patch('edx_ace.ace.send')
353351
def test_email_not_send_if_different_digest_preference(self, mock_func):
@@ -364,7 +362,6 @@ def test_email_not_send_if_different_digest_preference(self, mock_func):
364362
assert not mock_func.called
365363

366364

367-
@override_waffle_flag(ENABLE_ACCOUNT_LEVEL_PREFERENCES, True)
368365
@ddt.ddt
369366
class TestAccountPreferences(ModuleStoreTestCase):
370367
"""
@@ -435,17 +432,21 @@ def setUp(self):
435432
super().setUp()
436433
self.user = UserFactory()
437434
self.course = CourseFactory.create(display_name='test course', run="Testing_course")
435+
self.preference, _ = NotificationPreference.objects.get_or_create(
436+
user=self.user,
437+
type='new_discussion_post',
438+
app='discussion'
439+
)
438440

439441
@patch('edx_ace.ace.send')
440442
def test_email_sent_when_cadence_is_immediate(self, mock_func):
441443
"""
442444
Tests email is sent when cadence is immediate
443445
"""
444-
preference = CourseNotificationPreference.objects.create(user=self.user, course_id=self.course.id)
445-
app_prefs = preference.notification_preference_config['discussion']['notification_types']
446-
app_prefs['new_discussion_post']['email'] = True
447-
app_prefs['new_discussion_post']['email_cadence'] = EmailCadence.IMMEDIATELY
448-
preference.save()
446+
447+
self.preference.email = True
448+
self.preference.email_cadence = EmailCadence.IMMEDIATELY
449+
self.preference.save()
449450
context = {
450451
'username': 'User',
451452
'post_title': 'title'
@@ -461,7 +462,9 @@ def test_email_not_sent_when_cadence_is_not_immediate(self, mock_func):
461462
"""
462463
Tests email is not sent when cadence is not immediate
463464
"""
464-
CourseNotificationPreference.objects.create(user=self.user, course_id=self.course.id)
465+
self.preference.email = True
466+
self.preference.email_cadence = EmailCadence.DAILY
467+
self.preference.save()
465468
context = {
466469
'replier_name': 'User',
467470
'post_title': 'title'

openedx/core/djangoapps/notifications/handlers.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
TeamAudienceFilter
2525
)
2626
from openedx.core.djangoapps.notifications.base_notification import NotificationAppManager, COURSE_NOTIFICATION_TYPES
27-
from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS, ENABLE_ORA_GRADE_NOTIFICATION
27+
from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS
2828
from openedx.core.djangoapps.notifications.email import ONE_CLICK_EMAIL_UNSUB_KEY
2929
from openedx.core.djangoapps.notifications.models import CourseNotificationPreference, NotificationPreference
3030
from openedx.core.djangoapps.notifications.tasks import create_notification_preference
@@ -107,11 +107,6 @@ def generate_user_notifications(signal, sender, notification_data, metadata, **k
107107
"""
108108
Watches for USER_NOTIFICATION_REQUESTED signal and calls send_web_notifications task
109109
"""
110-
if (
111-
notification_data.notification_type == 'ora_grade_assigned'
112-
and not ENABLE_ORA_GRADE_NOTIFICATION.is_enabled(notification_data.course_key)
113-
):
114-
return
115110

116111
from openedx.core.djangoapps.notifications.tasks import send_notifications
117112
notification_data = notification_data.__dict__

0 commit comments

Comments
 (0)