From d0b7fcaa43508481ef7143cc776d3fd5d206fea0 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Thu, 17 Feb 2022 14:37:50 +0100 Subject: [PATCH] Add preferences for timetable change notifications --- aleksis/apps/chronos/model_extensions.py | 20 ++++++++++++-------- aleksis/apps/chronos/preferences.py | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/aleksis/apps/chronos/model_extensions.py b/aleksis/apps/chronos/model_extensions.py index d66a19d6..b324c83f 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 e25af094..fff08ee1 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") -- GitLab