Skip to content

Commit ad513cb

Browse files
fix: removed course_id from notification flag implementation (#37716)
1 parent c2fad03 commit ad513cb

File tree

6 files changed

+18
-29
lines changed

6 files changed

+18
-29
lines changed

lms/djangoapps/discussion/rest_api/tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def send_thread_created_notification(thread_id, course_key_str, user_id, notify_
3131
Send notification when a new thread is created
3232
"""
3333
course_key = CourseKey.from_string(course_key_str)
34-
if not ENABLE_NOTIFICATIONS.is_enabled(course_key):
34+
if not ENABLE_NOTIFICATIONS.is_enabled():
3535
return
3636
thread = Thread(id=thread_id).retrieve()
3737
user = User.objects.get(id=user_id)
@@ -55,7 +55,7 @@ def send_response_notifications(thread_id, course_key_str, user_id, comment_id,
5555
Send notifications to users who are subscribed to the thread.
5656
"""
5757
course_key = CourseKey.from_string(course_key_str)
58-
if not ENABLE_NOTIFICATIONS.is_enabled(course_key):
58+
if not ENABLE_NOTIFICATIONS.is_enabled():
5959
return
6060
thread = Thread(id=thread_id).retrieve()
6161
user = User.objects.get(id=user_id)
@@ -74,7 +74,7 @@ def send_response_endorsed_notifications(thread_id, response_id, course_key_str,
7474
Send notifications when a response is marked answered/ endorsed
7575
"""
7676
course_key = CourseKey.from_string(course_key_str)
77-
if not ENABLE_NOTIFICATIONS.is_enabled(course_key):
77+
if not ENABLE_NOTIFICATIONS.is_enabled():
7878
return
7979
thread = Thread(id=thread_id).retrieve()
8080
response = Comment(id=response_id).retrieve()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
# .. toggle_description: Waffle flag to enable the Notifications feature
1414
# .. toggle_use_cases: temporary, open_edx
1515
# .. toggle_creation_date: 2023-05-05
16-
# .. toggle_target_removal_date: 2023-11-05
16+
# .. toggle_target_removal_date: None
1717
# .. toggle_warning: When the flag is ON, Notifications feature is enabled.
1818
# .. toggle_tickets: INF-866
19-
ENABLE_NOTIFICATIONS = CourseWaffleFlag(f'{WAFFLE_NAMESPACE}.enable_notifications', __name__)
19+
ENABLE_NOTIFICATIONS = WaffleFlag(f'{WAFFLE_NAMESPACE}.enable_notifications', __name__)
2020

2121
# .. toggle_name: notifications.enable_email_notifications
2222
# .. toggle_implementation: WaffleFlag

openedx/core/djangoapps/notifications/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def send_notifications(user_ids, course_key: str, app_name, notification_type, c
104104
"""
105105
# pylint: disable=too-many-statements
106106
course_key = CourseKey.from_string(course_key)
107-
if not ENABLE_NOTIFICATIONS.is_enabled(course_key):
107+
if not ENABLE_NOTIFICATIONS.is_enabled():
108108
return
109109

110110
if not is_notification_valid(notification_type, context):

openedx/core/djangoapps/notifications/tests/test_tasks_with_account_level_pref.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ def _create_users(self, num_of_users):
216216

217217
@override_waffle_flag(ENABLE_NOTIFICATIONS, active=True)
218218
@ddt.data(
219-
(settings.NOTIFICATION_CREATION_BATCH_SIZE, 12, 3),
220-
(settings.NOTIFICATION_CREATION_BATCH_SIZE + 10, 14, 5),
221-
(settings.NOTIFICATION_CREATION_BATCH_SIZE - 10, 12, 3),
219+
(settings.NOTIFICATION_CREATION_BATCH_SIZE, 10, 3),
220+
(settings.NOTIFICATION_CREATION_BATCH_SIZE + 10, 12, 5),
221+
(settings.NOTIFICATION_CREATION_BATCH_SIZE - 10, 10, 3),
222222
)
223223
@ddt.unpack
224224
def test_notification_is_send_in_batch(self, creation_size, prefs_query_count, notifications_query_count):
@@ -268,7 +268,7 @@ def test_preference_not_created_for_default_off_preference(self):
268268
"username": "Test Author"
269269
}
270270
with override_waffle_flag(ENABLE_NOTIFICATIONS, active=True):
271-
with self.assertNumQueries(12):
271+
with self.assertNumQueries(10):
272272
send_notifications(user_ids, str(self.course.id), notification_app, notification_type,
273273
context, "http://test.url")
274274

@@ -288,7 +288,7 @@ def test_preference_created_for_default_on_preference(self):
288288
"replier_name": "Replier Name"
289289
}
290290
with override_waffle_flag(ENABLE_NOTIFICATIONS, active=True):
291-
with self.assertNumQueries(14):
291+
with self.assertNumQueries(12):
292292
send_notifications(user_ids, str(self.course.id), notification_app, notification_type,
293293
context, "http://test.url")
294294

openedx/core/djangoapps/notifications/utils.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
from typing import Dict, List, Set
55

6-
from common.djangoapps.student.models import CourseAccessRole, CourseEnrollment
6+
from common.djangoapps.student.models import CourseAccessRole
77
from openedx.core.djangoapps.django_comment_common.models import Role
88
from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS
99
from openedx.core.lib.cache_utils import request_cached
@@ -29,22 +29,11 @@ def find_pref_in_normalized_prefs(pref_name, app_name, prefs_list):
2929
return None
3030

3131

32-
def get_show_notifications_tray(user):
32+
def get_show_notifications_tray():
3333
"""
34-
Returns show_notifications_tray as boolean for the courses in which user is enrolled
34+
Returns whether notifications tray is enabled via waffle flag
3535
"""
36-
show_notifications_tray = False
37-
learner_enrollments_course_ids = CourseEnrollment.objects.filter(
38-
user=user,
39-
is_active=True
40-
).values_list('course_id', flat=True)
41-
42-
for course_id in learner_enrollments_course_ids:
43-
if ENABLE_NOTIFICATIONS.is_enabled(course_id):
44-
show_notifications_tray = True
45-
break
46-
47-
return show_notifications_tray
36+
return ENABLE_NOTIFICATIONS.is_enabled()
4837

4938

5039
def get_list_in_batches(input_list, batch_size):

openedx/core/djangoapps/notifications/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get(self, request):
131131
.annotate(count=Count('*'))
132132
)
133133
count_total = 0
134-
show_notifications_tray = get_show_notifications_tray(self.request.user)
134+
show_notifications_tray = get_show_notifications_tray()
135135
count_by_app_name_dict = {
136136
app_name: 0
137137
for app_name in COURSE_NOTIFICATION_APPS
@@ -330,7 +330,7 @@ def get(self, request):
330330
return Response({
331331
'status': 'success',
332332
'message': 'Notification preferences retrieved successfully.',
333-
'show_preferences': get_show_notifications_tray(self.request.user),
333+
'show_preferences': get_show_notifications_tray(),
334334
'data': structured_preferences
335335
}, status=status.HTTP_200_OK)
336336

@@ -438,7 +438,7 @@ def _prepare_response_data(self, validated_data):
438438
return {
439439
'status': 'success',
440440
'message': 'Notification preferences update completed',
441-
'show_preferences': get_show_notifications_tray(self.request.user),
441+
'show_preferences': get_show_notifications_tray(),
442442
'data': {
443443
'updated_value': updated_value,
444444
'notification_type': validated_data['notification_type'],

0 commit comments

Comments
 (0)