From e358332048119a749ffce5b57b2a051545b5e003 Mon Sep 17 00:00:00 2001 From: Nico Stapelbroek Date: Sun, 21 Jan 2018 13:05:46 +0100 Subject: [PATCH] Determine if notifications are suppressed when handeling events --- .../SendComponentUpdateEmailNotificationHandler.php | 9 ++------- .../Incident/SendIncidentEmailNotificationHandler.php | 7 +------ .../SendIncidentUpdateEmailNotificationHandler.php | 9 ++------- app/Integrations/Contracts/System.php | 4 ++-- app/Integrations/Core/System.php | 11 ++++++++--- 5 files changed, 15 insertions(+), 25 deletions(-) diff --git a/app/Bus/Handlers/Events/Component/SendComponentUpdateEmailNotificationHandler.php b/app/Bus/Handlers/Events/Component/SendComponentUpdateEmailNotificationHandler.php index 00435bb2..6ecdbfca 100644 --- a/app/Bus/Handlers/Events/Component/SendComponentUpdateEmailNotificationHandler.php +++ b/app/Bus/Handlers/Events/Component/SendComponentUpdateEmailNotificationHandler.php @@ -55,15 +55,10 @@ class SendComponentUpdateEmailNotificationHandler */ public function handle(ComponentStatusWasChangedEvent $event) { - // Don't send component status updates if we're under maintenance. - if ($this->system->underMaintenance()) { - return false; - } - $component = $event->component; - // If we're silent, then don't send this. - if ($event->silent) { + // If we're silent or the notifications are suppressed don't send this. + if ($event->silent || !$this->system->canNotifySubscribers()) { return; } diff --git a/app/Bus/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php b/app/Bus/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php index bd7f83ff..d30916d1 100644 --- a/app/Bus/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php +++ b/app/Bus/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php @@ -55,14 +55,9 @@ class SendIncidentEmailNotificationHandler */ public function handle(IncidentWasCreatedEvent $event) { - // Don't send incident updates if we're under maintenance. - if ($this->system->underMaintenance()) { - return false; - } - $incident = $event->incident; - if (!$event->notify) { + if (!$event->notify || !$this->system->canNotifySubscribers()) { return false; } diff --git a/app/Bus/Handlers/Events/IncidentUpdate/SendIncidentUpdateEmailNotificationHandler.php b/app/Bus/Handlers/Events/IncidentUpdate/SendIncidentUpdateEmailNotificationHandler.php index 0b8f9fa6..4fb98914 100644 --- a/app/Bus/Handlers/Events/IncidentUpdate/SendIncidentUpdateEmailNotificationHandler.php +++ b/app/Bus/Handlers/Events/IncidentUpdate/SendIncidentUpdateEmailNotificationHandler.php @@ -55,16 +55,11 @@ class SendIncidentUpdateEmailNotificationHandler */ public function handle(IncidentUpdateWasReportedEvent $event) { - // Don't send incident updates if we're under maintenance. - if ($this->system->underMaintenance()) { - return false; - } - $update = $event->update; $incident = $update->incident; - // Only send emails for public incidents. - if (!$incident->visible) { + // Only send emails for public incidents while the system is not under scheduled maintenance. + if (!$incident->visible || !$this->system->canNotifySubscribers()) { return; } diff --git a/app/Integrations/Contracts/System.php b/app/Integrations/Contracts/System.php index e023e4f4..a064e710 100644 --- a/app/Integrations/Contracts/System.php +++ b/app/Integrations/Contracts/System.php @@ -26,11 +26,11 @@ interface System public function getStatus(); /** - * Determine if Cachet has any open maintenance windows. + * Determine if Cachet is allowed to send notifications to users, subscribers or third party tools. * * @return bool */ - public function underMaintenance(); + public function canNotifySubscribers(); /** * Get the cachet version. diff --git a/app/Integrations/Core/System.php b/app/Integrations/Core/System.php index 9282a0bb..4fe0c455 100644 --- a/app/Integrations/Core/System.php +++ b/app/Integrations/Core/System.php @@ -104,13 +104,18 @@ class System implements SystemContract } /** - * Determine if Cachet has any open maintenance windows. + * Determine if Cachet is allowed to send notifications to users, subscribers or third party tools. * * @return bool */ - public function underMaintenance() + public function canNotifySubscribers() { - return Schedule::inProgress()->count() > 0; + $maintenancePeriods = Schedule::inProgress()->count(); + if ($maintenancePeriods === 0) { + return true; + } + + return !$this->config->get('suppress_notifications_in_maintenance'); } /**