|
32 | 32 | get_language_preference_for_users, |
33 | 33 | get_start_end_date, |
34 | 34 | get_text_for_notification_type, |
35 | | - is_email_notification_flag_enabled, |
36 | 35 | ) |
37 | 36 | from ..base_notification import COURSE_NOTIFICATION_APPS |
38 | | -from ..config.waffle import ENABLE_EMAIL_NOTIFICATIONS |
| 37 | +from ..config.waffle import DISABLE_EMAIL_NOTIFICATIONS |
39 | 38 |
|
40 | 39 | User = get_user_model() |
41 | 40 | logger = get_task_logger(__name__) |
@@ -76,16 +75,16 @@ def send_digest_email_to_user( |
76 | 75 | start_date: Datetime object |
77 | 76 | end_date: Datetime object |
78 | 77 | """ |
| 78 | + if DISABLE_EMAIL_NOTIFICATIONS.is_enabled(): |
| 79 | + return |
79 | 80 |
|
80 | 81 | if cadence_type not in [EmailCadence.IMMEDIATELY, EmailCadence.DAILY, EmailCadence.WEEKLY]: |
81 | 82 | raise ValueError('Invalid cadence_type') |
82 | 83 | logger.info(f'<Email Cadence> Sending email to user {user.username} ==Temp Log==') |
83 | 84 | if not user.has_usable_password(): |
84 | 85 | logger.info(f'<Email Cadence> User is disabled {user.username} ==Temp Log==') |
85 | 86 | return |
86 | | - if not is_email_notification_flag_enabled(user): |
87 | | - logger.info(f'<Email Cadence> Flag disabled for {user.username} ==Temp Log==') |
88 | | - return |
| 87 | + |
89 | 88 | notifications = Notification.objects.filter(user=user, email=True, |
90 | 89 | created__gte=start_date, created__lte=end_date) |
91 | 90 | if not notifications: |
@@ -147,19 +146,21 @@ def send_immediate_cadence_email(email_notification_mapping, course_key): |
147 | 146 | 2. Second notification → Schedule buffer job (15 min) |
148 | 147 | 3. Third+ notifications → Just mark as scheduled (no new job) |
149 | 148 | """ |
| 149 | + if DISABLE_EMAIL_NOTIFICATIONS.is_enabled(): |
| 150 | + return |
| 151 | + |
150 | 152 | if not email_notification_mapping: |
151 | 153 | return |
152 | 154 | user_list = email_notification_mapping.keys() |
153 | 155 | users = list(User.objects.filter(id__in=user_list)) |
154 | 156 | language_prefs = get_language_preference_for_users(user_list) |
155 | 157 | course_name = get_course_info(course_key).get("name", course_key) |
| 158 | + |
156 | 159 | for user in users: |
157 | 160 | if not user.has_usable_password(): |
158 | 161 | logger.info(f'<Immediate Email> User is disabled {user.username}') |
159 | 162 | continue |
160 | | - if not is_email_notification_flag_enabled(user): |
161 | | - logger.info(f'<Immediate Email> Flag disabled for {user.username}') |
162 | | - continue |
| 163 | + |
163 | 164 | notification = email_notification_mapping.get(user.id, None) |
164 | 165 | if not notification: |
165 | 166 | logger.info(f'<Immediate Email> No notification for {user.username}') |
@@ -394,7 +395,7 @@ def send_buffered_digest( |
394 | 395 | """ |
395 | 396 | try: |
396 | 397 | # Re-check feature flags |
397 | | - if not ENABLE_EMAIL_NOTIFICATIONS.is_enabled(): |
| 398 | + if DISABLE_EMAIL_NOTIFICATIONS.is_enabled(): |
398 | 399 | logger.info('Email notifications disabled, cancelling digest') |
399 | 400 | return |
400 | 401 |
|
|
0 commit comments