|
36 | 36 | from unidecode import unidecode |
37 | 37 |
|
38 | 38 | from weblate.accounts.avatar import get_user_display |
39 | | -from weblate.accounts.data import create_default_notifications |
40 | 39 | from weblate.accounts.notifications import ( |
41 | 40 | NOTIFICATIONS, |
42 | 41 | NotificationFrequency, |
@@ -157,6 +156,61 @@ class WeblateAccountsConf(AppConf): |
157 | 156 | r"{URL_PREFIX}/site.webmanifest$", # The request for the manifest is made without credentials |
158 | 157 | ) |
159 | 158 |
|
| 159 | + DEFAULT_NOTIFICATIONS: ClassVar[ |
| 160 | + list[tuple[NotificationScope, NotificationFrequency, str]] |
| 161 | + ] = [ |
| 162 | + ( |
| 163 | + NotificationScope.SCOPE_ALL, |
| 164 | + NotificationFrequency.FREQ_INSTANT, |
| 165 | + "MentionCommentNotificaton", |
| 166 | + ), |
| 167 | + ( |
| 168 | + NotificationScope.SCOPE_WATCHED, |
| 169 | + NotificationFrequency.FREQ_INSTANT, |
| 170 | + "LastAuthorCommentNotificaton", |
| 171 | + ), |
| 172 | + ( |
| 173 | + NotificationScope.SCOPE_WATCHED, |
| 174 | + NotificationFrequency.FREQ_INSTANT, |
| 175 | + "MentionCommentNotificaton", |
| 176 | + ), |
| 177 | + ( |
| 178 | + NotificationScope.SCOPE_WATCHED, |
| 179 | + NotificationFrequency.FREQ_INSTANT, |
| 180 | + "NewAnnouncementNotificaton", |
| 181 | + ), |
| 182 | + ( |
| 183 | + NotificationScope.SCOPE_WATCHED, |
| 184 | + NotificationFrequency.FREQ_WEEKLY, |
| 185 | + "NewStringNotificaton", |
| 186 | + ), |
| 187 | + ( |
| 188 | + NotificationScope.SCOPE_ADMIN, |
| 189 | + NotificationFrequency.FREQ_INSTANT, |
| 190 | + "MergeFailureNotification", |
| 191 | + ), |
| 192 | + ( |
| 193 | + NotificationScope.SCOPE_ADMIN, |
| 194 | + NotificationFrequency.FREQ_INSTANT, |
| 195 | + "ParseErrorNotification", |
| 196 | + ), |
| 197 | + ( |
| 198 | + NotificationScope.SCOPE_ADMIN, |
| 199 | + NotificationFrequency.FREQ_INSTANT, |
| 200 | + "NewTranslationNotificaton", |
| 201 | + ), |
| 202 | + ( |
| 203 | + NotificationScope.SCOPE_ADMIN, |
| 204 | + NotificationFrequency.FREQ_INSTANT, |
| 205 | + "NewAlertNotificaton", |
| 206 | + ), |
| 207 | + ( |
| 208 | + NotificationScope.SCOPE_ADMIN, |
| 209 | + NotificationFrequency.FREQ_INSTANT, |
| 210 | + "NewAnnouncementNotificaton", |
| 211 | + ), |
| 212 | + ] |
| 213 | + |
160 | 214 | # Multi-level rate limiting for email notifications |
161 | 215 | # Each tuple contains (max_emails, time_window_seconds) |
162 | 216 | RATELIMIT_NOTIFICATION_LIMITS: ClassVar[list[tuple[int, int]]] = [ |
@@ -1329,3 +1383,13 @@ def create_profile_callback(sender, instance, created=False, **kwargs) -> None: |
1329 | 1383 | # Create subscriptions |
1330 | 1384 | if not instance.is_anonymous and not instance.is_bot: |
1331 | 1385 | create_default_notifications(instance) |
| 1386 | + |
| 1387 | + |
| 1388 | +def create_default_notifications(user: User) -> None: |
| 1389 | + if settings.DEFAULT_NOTIFICATIONS: |
| 1390 | + for scope, frequency, notification in settings.DEFAULT_NOTIFICATIONS: |
| 1391 | + user.subscription_set.get_or_create( |
| 1392 | + scope=scope, |
| 1393 | + notification=notification, |
| 1394 | + defaults={"frequency": frequency}, |
| 1395 | + ) |
0 commit comments