Skip to content

Commit c812297

Browse files
fix: create preferences for all types instead of core (#36984)
1 parent cfe4059 commit c812297

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

  • openedx/core/djangoapps/notifications/email

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,31 +331,25 @@ def create_missing_account_level_preferences(notifications, preferences, user):
331331
Creates missing account level preferences for notifications
332332
"""
333333
preferences = list(preferences)
334-
notification_types = list(set(
335-
(notification.app_name, "core") if COURSE_NOTIFICATION_TYPES[notification.notification_type]["is_core"]
336-
else (notification.app_name, notification.notification_type)
337-
for notification in notifications
338-
))
334+
notification_types = list(set(notification.notification_type for notification in notifications))
339335
missing_prefs = []
340336
for notification_type in notification_types:
341-
if not any(
342-
preference.app == notification_type[0] and preference.type == notification_type[1]
343-
for preference in preferences
344-
):
345-
if notification_type[1] == "core":
346-
app_pref = COURSE_NOTIFICATION_APPS.get(notification_type[0], {})
337+
if not any(preference.type == notification_type for preference in preferences):
338+
type_pref = COURSE_NOTIFICATION_TYPES.get(notification_type, {})
339+
app_name = type_pref["notification_app"]
340+
if type_pref.get('is_core', False):
341+
app_pref = COURSE_NOTIFICATION_APPS.get(app_name, {})
347342
default_pref = {
348-
"notification_app": notification_type[0],
349343
"web": app_pref["core_web"],
350344
"push": app_pref["core_push"],
351345
"email": app_pref["core_email"],
352346
"email_cadence": app_pref["core_email_cadence"]
353347
}
354348
else:
355-
default_pref = COURSE_NOTIFICATION_TYPES.get(notification_type[1], {})
349+
default_pref = COURSE_NOTIFICATION_TYPES.get(notification_type, {})
356350
missing_prefs.append(
357351
NotificationPreference(
358-
user=user, type=notification_type[1], app=notification_type[0], web=default_pref['web'],
352+
user=user, type=notification_type, app=app_name, web=default_pref['web'],
359353
push=default_pref['push'], email=default_pref['email'], email_cadence=default_pref['email_cadence'],
360354
)
361355
)

0 commit comments

Comments
 (0)