diff --git a/aleksis/apps/chronos/model_extensions.py b/aleksis/apps/chronos/model_extensions.py index d66a19d6cab1f46c60194a686189717fb84bee3d..b324c83f67c6e5a24e25feca17ed31b24690dbc9 100644 --- a/aleksis/apps/chronos/model_extensions.py +++ b/aleksis/apps/chronos/model_extensions.py @@ -171,6 +171,9 @@ Person.add_permission( @receiver(timetable_data_changed) def send_notifications(sender: Revision, **kwargs): """Send notifications to users about the changes.""" + if not get_site_preferences()["chronos__send_notifications"]: + return + for change in sender.changes.values(): if change.deleted: continue @@ -360,11 +363,12 @@ def send_notifications(sender: Revision, **kwargs): ) for recipient in recipients: - n = Notification( - recipient=recipient, - sender=_("Timetable"), - title=_("There are current changes to your timetable."), - description=description, - link=url, - ) - n.save() + if recipient.preferences["chronos__send_notifications"]: + n = Notification( + recipient=recipient, + sender=_("Timetable"), + title=_("There are current changes to your timetable."), + description=description, + link=url, + ) + n.save() diff --git a/aleksis/apps/chronos/preferences.py b/aleksis/apps/chronos/preferences.py index e25af094c0f47e85be46520ffdff93f9300c2e70..fff08ee1c17c883b96fee9d987ff854934b4d2c3 100644 --- a/aleksis/apps/chronos/preferences.py +++ b/aleksis/apps/chronos/preferences.py @@ -78,3 +78,19 @@ class TimeForSendingNotifications(TimePreference): default = time(17, 00) verbose_name = _("Time for sending notifications for the next day") required = True + + +@site_preferences_registry.register +class SendNotifications(BooleanPreference): + section = chronos + name = "send_notifications" + default = True + verbose_name = _("Send notifications for current timetable changes") + + +@person_preferences_registry.register +class SendNotificationsPerson(BooleanPreference): + section = chronos + name = "send_notifications" + default = True + verbose_name = _("Send notifications for current timetable changes")