Merge pull request #2877 from nstapelbroek/feature/2720-suppress-notifications-in-maintenance

Suppress notifications while in maintenance mode
This commit is contained in:
James Brooks
2018-01-21 20:59:21 +00:00
committed by GitHub
14 changed files with 156 additions and 28 deletions
@@ -12,12 +12,20 @@
namespace CachetHQ\Cachet\Bus\Handlers\Events\Component; namespace CachetHQ\Cachet\Bus\Handlers\Events\Component;
use CachetHQ\Cachet\Bus\Events\Component\ComponentStatusWasChangedEvent; use CachetHQ\Cachet\Bus\Events\Component\ComponentStatusWasChangedEvent;
use CachetHQ\Cachet\Integrations\Contracts\System;
use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Subscriber; use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Notifications\Component\ComponentStatusChangedNotification; use CachetHQ\Cachet\Notifications\Component\ComponentStatusChangedNotification;
class SendComponentUpdateEmailNotificationHandler class SendComponentUpdateEmailNotificationHandler
{ {
/**
* The system instance.
*
* @var \CachetHQ\Cachet\Integrations\Contracts\System
*/
protected $system;
/** /**
* The subscriber instance. * The subscriber instance.
* *
@@ -32,8 +40,9 @@ class SendComponentUpdateEmailNotificationHandler
* *
* @return void * @return void
*/ */
public function __construct(Subscriber $subscriber) public function __construct(System $system, Subscriber $subscriber)
{ {
$this->system = $system;
$this->subscriber = $subscriber; $this->subscriber = $subscriber;
} }
@@ -48,8 +57,8 @@ class SendComponentUpdateEmailNotificationHandler
{ {
$component = $event->component; $component = $event->component;
// If we're silent, then don't send this. // If we're silent or the notifications are suppressed don't send this.
if ($event->silent) { if ($event->silent || !$this->system->canNotifySubscribers()) {
return; return;
} }
@@ -12,11 +12,19 @@
namespace CachetHQ\Cachet\Bus\Handlers\Events\Incident; namespace CachetHQ\Cachet\Bus\Handlers\Events\Incident;
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasCreatedEvent; use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasCreatedEvent;
use CachetHQ\Cachet\Integrations\Contracts\System;
use CachetHQ\Cachet\Models\Subscriber; use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Notifications\Incident\NewIncidentNotification; use CachetHQ\Cachet\Notifications\Incident\NewIncidentNotification;
class SendIncidentEmailNotificationHandler class SendIncidentEmailNotificationHandler
{ {
/**
* The system instance.
*
* @var \CachetHQ\Cachet\Integrations\Contracts\System
*/
protected $system;
/** /**
* The subscriber instance. * The subscriber instance.
* *
@@ -27,12 +35,14 @@ class SendIncidentEmailNotificationHandler
/** /**
* Create a new send incident email notification handler. * Create a new send incident email notification handler.
* *
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber * @param \CachetHQ\Cachet\Integrations\Contracts\System $system
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
* *
* @return void * @return void
*/ */
public function __construct(Subscriber $subscriber) public function __construct(System $system, Subscriber $subscriber)
{ {
$this->system = $system;
$this->subscriber = $subscriber; $this->subscriber = $subscriber;
} }
@@ -47,7 +57,7 @@ class SendIncidentEmailNotificationHandler
{ {
$incident = $event->incident; $incident = $event->incident;
if (!$event->notify) { if (!$event->notify || !$this->system->canNotifySubscribers()) {
return false; return false;
} }
@@ -12,11 +12,19 @@
namespace CachetHQ\Cachet\Bus\Handlers\Events\IncidentUpdate; namespace CachetHQ\Cachet\Bus\Handlers\Events\IncidentUpdate;
use CachetHQ\Cachet\Bus\Events\IncidentUpdate\IncidentUpdateWasReportedEvent; use CachetHQ\Cachet\Bus\Events\IncidentUpdate\IncidentUpdateWasReportedEvent;
use CachetHQ\Cachet\Integrations\Contracts\System;
use CachetHQ\Cachet\Models\Subscriber; use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Notifications\IncidentUpdate\IncidentUpdatedNotification; use CachetHQ\Cachet\Notifications\IncidentUpdate\IncidentUpdatedNotification;
class SendIncidentUpdateEmailNotificationHandler class SendIncidentUpdateEmailNotificationHandler
{ {
/**
* The system instance.
*
* @var \CachetHQ\Cachet\Integrations\Contracts\System
*/
protected $system;
/** /**
* The subscriber instance. * The subscriber instance.
* *
@@ -27,12 +35,14 @@ class SendIncidentUpdateEmailNotificationHandler
/** /**
* Create a new send incident email notification handler. * Create a new send incident email notification handler.
* *
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber * @param \CachetHQ\Cachet\Integrations\Contracts\System $system
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
* *
* @return void * @return void
*/ */
public function __construct(Subscriber $subscriber) public function __construct(System $system, Subscriber $subscriber)
{ {
$this->system = $system;
$this->subscriber = $subscriber; $this->subscriber = $subscriber;
} }
@@ -48,8 +58,8 @@ class SendIncidentUpdateEmailNotificationHandler
$update = $event->update; $update = $event->update;
$incident = $update->incident; $incident = $update->incident;
// Only send emails for public incidents. // Only send emails for public incidents while the system is not under scheduled maintenance.
if (!$incident->visible) { if (!$incident->visible || !$this->system->canNotifySubscribers()) {
return; return;
} }
@@ -17,6 +17,7 @@ use CachetHQ\Cachet\Bus\Commands\Incident\RemoveIncidentCommand;
use CachetHQ\Cachet\Bus\Commands\Incident\UpdateIncidentCommand; use CachetHQ\Cachet\Bus\Commands\Incident\UpdateIncidentCommand;
use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\CreateIncidentUpdateCommand; use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\CreateIncidentUpdateCommand;
use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\UpdateIncidentUpdateCommand; use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\UpdateIncidentUpdateCommand;
use CachetHQ\Cachet\Integrations\Contracts\System;
use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup; use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\Incident;
@@ -48,6 +49,13 @@ class IncidentController extends Controller
*/ */
protected $auth; protected $auth;
/**
* The system instance.
*
* @var \CachetHQ\Cachet\Integrations\Contracts\System
*/
protected $system;
/** /**
* Creates a new incident controller instance. * Creates a new incident controller instance.
* *
@@ -55,9 +63,10 @@ class IncidentController extends Controller
* *
* @return void * @return void
*/ */
public function __construct(Guard $auth) public function __construct(Guard $auth, System $system)
{ {
$this->auth = $auth; $this->auth = $auth;
$this->system = $system;
View::share('sub_title', trans('dashboard.incidents.title')); View::share('sub_title', trans('dashboard.incidents.title'));
} }
@@ -87,6 +96,7 @@ class IncidentController extends Controller
->withPageTitle(trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard')) ->withPageTitle(trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'))
->withComponentsInGroups(ComponentGroup::with('components')->get()) ->withComponentsInGroups(ComponentGroup::with('components')->get())
->withComponentsOutGroups(Component::where('group_id', '=', 0)->get()) ->withComponentsOutGroups(Component::where('group_id', '=', 0)->get())
->withNotificationsEnabled($this->system->canNotifySubscribers())
->withIncidentTemplates(IncidentTemplate::all()); ->withIncidentTemplates(IncidentTemplate::all());
} }
@@ -225,7 +235,8 @@ class IncidentController extends Controller
->withPageTitle(trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard')) ->withPageTitle(trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'))
->withIncident($incident) ->withIncident($incident)
->withComponentsInGroups(ComponentGroup::with('components')->get()) ->withComponentsInGroups(ComponentGroup::with('components')->get())
->withComponentsOutGroups(Component::where('group_id', '=', 0)->get()); ->withComponentsOutGroups(Component::where('group_id', '=', 0)->get())
->withNotificationsEnabled($this->system->canNotifySubscribers());
} }
/** /**
@@ -309,7 +320,9 @@ class IncidentController extends Controller
*/ */
public function showCreateIncidentUpdateAction(Incident $incident) public function showCreateIncidentUpdateAction(Incident $incident)
{ {
return View::make('dashboard.incidents.updates.add')->withIncident($incident); return View::make('dashboard.incidents.updates.add')
->withIncident($incident)
->withNotificationsEnabled($this->system->canNotifySubscribers());
} }
/** /**
@@ -351,7 +364,8 @@ class IncidentController extends Controller
{ {
return View::make('dashboard.incidents.updates.edit') return View::make('dashboard.incidents.updates.edit')
->withIncident($incident) ->withIncident($incident)
->withUpdate($incidentUpdate); ->withUpdate($incidentUpdate)
->withNotificationsEnabled($this->system->canNotifySubscribers());
} }
/** /**
+7
View File
@@ -25,6 +25,13 @@ interface System
*/ */
public function getStatus(); public function getStatus();
/**
* Determine if Cachet is allowed to send notifications to users, subscribers or third party tools.
*
* @return bool
*/
public function canNotifySubscribers();
/** /**
* Get the cachet version. * Get the cachet version.
* *
+16
View File
@@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Integrations\Core;
use CachetHQ\Cachet\Integrations\Contracts\System as SystemContract; use CachetHQ\Cachet\Integrations\Contracts\System as SystemContract;
use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\Schedule;
use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Config\Repository;
@@ -102,6 +103,21 @@ class System implements SystemContract
return $status; return $status;
} }
/**
* Determine if Cachet is allowed to send notifications to users, subscribers or third party tools.
*
* @return bool
*/
public function canNotifySubscribers()
{
$maintenancePeriods = Schedule::inProgress()->count();
if ($maintenancePeriods === 0) {
return true;
}
return !$this->config->get('setting.suppress_notifications_in_maintenance');
}
/** /**
* Get the cachet version. * Get the cachet version.
* *
+15
View File
@@ -16,6 +16,7 @@ use CachetHQ\Cachet\Models\Traits\SearchableTrait;
use CachetHQ\Cachet\Models\Traits\SortableTrait; use CachetHQ\Cachet\Models\Traits\SortableTrait;
use CachetHQ\Cachet\Presenters\SchedulePresenter; use CachetHQ\Cachet\Presenters\SchedulePresenter;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use McCool\LaravelAutoPresenter\HasPresenter; use McCool\LaravelAutoPresenter\HasPresenter;
@@ -151,6 +152,20 @@ class Schedule extends Model implements HasPresenter
return $this->morphMany(Meta::class, 'meta'); return $this->morphMany(Meta::class, 'meta');
} }
/**
* Scope schedules that are in progress.
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeInProgress(Builder $query)
{
return $query->where('scheduled_at', '<=', Carbon::now())->where('status', '!=', self::COMPLETE)->where(function ($query) {
$query->whereNull('completed_at')->orWhere('completed_at', '>', Carbon::now());
});
}
/** /**
* Scopes schedules to those in the future. * Scopes schedules to those in the future.
* *
+12
View File
@@ -33,6 +33,18 @@ return [
'enable_subscribers' => true, 'enable_subscribers' => true,
/*
|--------------------------------------------------------------------------
| Suppress notifications while in maintenance
|--------------------------------------------------------------------------
|
| Whether to suppress notification channels if an issue is created during
| planned or in-progress maintenance periods.
|
*/
'suppress_notifications_in_maintenance' => true,
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Automatic Localization | Automatic Localization
+16 -14
View File
@@ -54,6 +54,7 @@ return [
'message-help' => 'You may also use Markdown.', 'message-help' => 'You may also use Markdown.',
'occurred_at' => 'When did this incident occur?', 'occurred_at' => 'When did this incident occur?',
'notify_subscribers' => 'Notify subscribers?', 'notify_subscribers' => 'Notify subscribers?',
'notify_disabled' => 'Due to scheduled maintenance, notifications about this incident or its components will be suppressed.',
'visibility' => 'Incident Visibility', 'visibility' => 'Incident Visibility',
'stick_status' => 'Stick Incident', 'stick_status' => 'Stick Incident',
'stickied' => 'Stickied', 'stickied' => 'Stickied',
@@ -147,20 +148,21 @@ return [
'settings' => [ 'settings' => [
// Application setup // Application setup
'app-setup' => [ 'app-setup' => [
'site-name' => 'Site Name', 'site-name' => 'Site Name',
'site-url' => 'Site URL', 'site-url' => 'Site URL',
'display-graphs' => 'Display graphs on status page?', 'display-graphs' => 'Display graphs on status page?',
'about-this-page' => 'About this page', 'about-this-page' => 'About this page',
'days-of-incidents' => 'How many days of incidents to show?', 'days-of-incidents' => 'How many days of incidents to show?',
'time_before_refresh' => 'Status page refresh rate (in seconds).', 'time_before_refresh' => 'Status page refresh rate (in seconds).',
'banner' => 'Banner Image', 'banner' => 'Banner Image',
'banner-help' => "It's recommended that you upload files no bigger than 930px wide .", 'banner-help' => "It's recommended that you upload files no bigger than 930px wide .",
'subscribers' => 'Allow people to signup to email notifications?', 'subscribers' => 'Allow people to signup to email notifications?',
'skip_subscriber_verification' => 'Skip verifying of users? (Be warned, you could be spammed)', 'suppress_notifications_in_maintenance' => 'Suppress notifications when incident occurs during maintenance period?',
'automatic_localization' => 'Automatically localise your status page to your visitor\'s language?', 'skip_subscriber_verification' => 'Skip verifying of users? (Be warned, you could be spammed)',
'enable_external_dependencies' => 'Enable Third Party Dependencies (Google Fonts, Trackers, etc...)', 'automatic_localization' => 'Automatically localise your status page to your visitor\'s language?',
'show_timezone' => 'Show the timezone the status page is running in.', 'enable_external_dependencies' => 'Enable Third Party Dependencies (Google Fonts, Trackers, etc...)',
'only_disrupted_days' => 'Only show days containing incidents in the timeline?', 'show_timezone' => 'Show the timezone the status page is running in.',
'only_disrupted_days' => 'Only show days containing incidents in the timeline?',
], ],
'analytics' => [ 'analytics' => [
'analytics_google' => 'Google Analytics code', 'analytics_google' => 'Google Analytics code',
@@ -13,6 +13,11 @@
<div class="content-wrapper"> <div class="content-wrapper">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
@if(!$notifications_enabled)
<div class="alert alert-info" role="alert">
{{ trans('forms.incidents.notify_disabled') }}
</div>
@endif
@include('dashboard.partials.errors') @include('dashboard.partials.errors')
<report-incident inline-template> <report-incident inline-template>
<form class="form-vertical" name="IncidentForm" role="form" method="POST" autocomplete="off"> <form class="form-vertical" name="IncidentForm" role="form" method="POST" autocomplete="off">
@@ -115,6 +120,7 @@
<label>{{ trans('forms.incidents.occurred_at') }}</label> <small class="text-muted">{{ trans('forms.optional') }}</small> <label>{{ trans('forms.incidents.occurred_at') }}</label> <small class="text-muted">{{ trans('forms.optional') }}</small>
<input type="text" name="occurred_at" class="form-control" rel="datepicker-custom" data-date-format="YYYY-MM-DD HH:mm" placeholder="{{ trans('forms.optional') }}"> <input type="text" name="occurred_at" class="form-control" rel="datepicker-custom" data-date-format="YYYY-MM-DD HH:mm" placeholder="{{ trans('forms.optional') }}">
</div> </div>
@if($notifications_enabled)
<input type="hidden" name="notify" value="0"> <input type="hidden" name="notify" value="0">
<div class="checkbox"> <div class="checkbox">
<label> <label>
@@ -122,6 +128,7 @@
{{ trans('forms.incidents.notify_subscribers') }} {{ trans('forms.incidents.notify_subscribers') }}
</label> </label>
</div> </div>
@endif
</fieldset> </fieldset>
<div class="form-group"> <div class="form-group">
@@ -13,6 +13,11 @@
<div class="content-wrapper"> <div class="content-wrapper">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
@if(!$notifications_enabled)
<div class="alert alert-info" role="alert">
{{ trans('forms.incidents.notify_disabled') }}
</div>
@endif
@include('dashboard.partials.errors') @include('dashboard.partials.errors')
<form class="form-vertical" name="IncidentForm" role="form" method="POST" autocomplete="off"> <form class="form-vertical" name="IncidentForm" role="form" method="POST" autocomplete="off">
<input type="hidden" name="_token" value="{{ csrf_token() }}"> <input type="hidden" name="_token" value="{{ csrf_token() }}">
@@ -13,6 +13,11 @@
<div class="content-wrapper"> <div class="content-wrapper">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
@if(!$notifications_enabled)
<div class="alert alert-info" role="alert">
{{ trans('forms.incidents.notify_disabled') }}
</div>
@endif
@include('dashboard.partials.errors') @include('dashboard.partials.errors')
<form class="form-vertical" name="IncidentUpdateForm" role="form" method="POST" autocomplete="off"> <form class="form-vertical" name="IncidentUpdateForm" role="form" method="POST" autocomplete="off">
<input type="hidden" name="_token" value="{{ csrf_token() }}"> <input type="hidden" name="_token" value="{{ csrf_token() }}">
@@ -13,6 +13,11 @@
<div class="content-wrapper"> <div class="content-wrapper">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
@if(!$notifications_enabled)
<div class="alert alert-info" role="alert">
{{ trans('forms.incidents.notify_disabled') }}
</div>
@endif
@include('dashboard.partials.errors') @include('dashboard.partials.errors')
<form class="form-vertical" name="IncidentUpdateForm" role="form" method="POST" autocomplete="off"> <form class="form-vertical" name="IncidentUpdateForm" role="form" method="POST" autocomplete="off">
<input type="hidden" name="_token" value="{{ csrf_token() }}"> <input type="hidden" name="_token" value="{{ csrf_token() }}">
@@ -68,6 +68,17 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col-xs-12">
<div class="checkbox">
<label>
<input type="hidden" value="0" name="suppress_notifications_in_maintenance">
<input type="checkbox" value="1" name="suppress_notifications_in_maintenance" {{ Config::get('setting.suppress_notifications_in_maintenance') ? 'checked' : null }}>
{{ trans('forms.settings.app-setup.suppress_notifications_in_maintenance') }}
</label>
</div>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<div class="checkbox"> <div class="checkbox">