Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more control over when to notify subscribers #63

Open
wants to merge 1 commit into
base: 2.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/Bus/Commands/IncidentUpdate/CreateIncidentUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ final class CreateIncidentUpdateCommand
* @var int
*/
public $component_status;

/**
* Whether to notify about the update or not.
*
* @var bool
*/
public $notify;

/**
* The user.
*
Expand All @@ -72,6 +80,7 @@ final class CreateIncidentUpdateCommand
'message' => 'required|string',
'component_id' => 'nullable|required_with:component_status|int',
'component_status' => 'nullable|required_with:component_id|int|min:0|max:4',
'notify' => 'nullable|bool',
'user' => 'required',
];

Expand All @@ -85,13 +94,14 @@ final class CreateIncidentUpdateCommand
*
* @return void
*/
public function __construct(Incident $incident, $status, $message, $component_id, $component_status, User $user)
public function __construct(Incident $incident, $status, $message, $component_id, $component_status, $notify, User $user)
{
$this->incident = $incident;
$this->status = $status;
$this->message = $message;
$this->component_id = $component_id;
$this->component_status = $component_status;
$this->notify = $notify;
$this->user = $user;
}
}
11 changes: 10 additions & 1 deletion app/Bus/Events/IncidentUpdate/IncidentUpdateWasReportedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,27 @@ final class IncidentUpdateWasReportedEvent implements ActionInterface, IncidentU
*/
public $update;

/**
* Whether to notify about the incident update or not.
*
* @var bool
*/
public $notify;

/**
* Create a new incident update was reported event instance.
*
* @param \CachetHQ\Cachet\Models\User $user
* @param \CachetHQ\Cachet\Models\IncidentUpdate $update
* @param bool $notify
*
* @return void
*/
public function __construct(User $user, IncidentUpdate $update)
public function __construct(User $user, IncidentUpdate $update, $notify = false)
{
$this->user = $user;
$this->update = $update;
$this->notify = $notify;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function handle(CreateIncidentUpdateCommand $command)
[]
));

event(new IncidentUpdateWasReportedEvent($this->auth->user(), $update));
event(new IncidentUpdateWasReportedEvent($this->auth->user(), $update, $command->notify));

return $update;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle(ComponentStatusWasChangedEvent $event)
$component = $event->component;

// If we're silent or the notifications are suppressed don't send this.
if ($event->silent || !$this->system->canNotifySubscribers()) {
if ($event->silent || !$this->system->canNotifySubscribers() || $this->system->shouldDisableNotifications()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle(IncidentWasCreatedEvent $event)
$incident = $event->incident;

if (!$event->notify || !$this->system->canNotifySubscribers()) {
return false;
return;
}

// Only send emails for public incidents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function __construct(System $system, Subscriber $subscriber)
*/
public function handle(IncidentUpdateWasReportedEvent $event)
{
if (!$event->notify || !$this->system->canNotifySubscribers()) {
return;
}

$update = $event->update;
$incident = $update->incident;

Expand Down
17 changes: 14 additions & 3 deletions app/Http/Controllers/Dashboard/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;

use CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand;
use CachetHQ\Cachet\Integrations\Contracts\System;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident;
Expand Down Expand Up @@ -51,18 +52,27 @@ class DashboardController extends Controller
*/
protected $guard;

/**
* The system instance.
*
* @var \CachetHQ\Cachet\Integrations\Contracts\System
*/
protected $system;

/**
* Creates a new dashboard controller instance.
*
* @param \Illuminate\Contracts\Auth\Guard $guard
* @param \Illuminate\Contracts\Auth\Guard $guard
* @param \CachetHQ\Cachet\Integrations\Contracts\System $system
*
* @return void
*/
public function __construct(Guard $guard)
public function __construct(Guard $guard, System $system)
{
$this->guard = $guard;
$this->startDate = new Date();
$this->dateTimeZone = Config::get('cachet.timezone');
$this->system = $system;
}

/**
Expand Down Expand Up @@ -101,7 +111,8 @@ public function showDashboard()
->withSubscribers($subscribers)
->withComponentGroups($componentGroups)
->withUngroupedComponents($ungroupedComponents)
->withWelcomeUser($welcomeUser);
->withWelcomeUser($welcomeUser)
->withNoNotifications($this->system->shouldDisableNotifications());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Dashboard/IncidentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function showAddIncident()
->withComponentsInGroups(ComponentGroup::with('components')->get())
->withComponentsOutGroups(Component::where('group_id', '=', 0)->get())
->withNotificationsEnabled($this->system->canNotifySubscribers())
->withNoNotifications($this->system->shouldDisableNotifications())
->withIncidentTemplates(IncidentTemplate::all());
}

Expand Down Expand Up @@ -233,8 +234,7 @@ public function showEditIncidentAction(Incident $incident)
->withPageTitle(trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'))
->withIncident($incident)
->withComponentsInGroups(ComponentGroup::with('components')->get())
->withComponentsOutGroups(Component::where('group_id', '=', 0)->get())
->withNotificationsEnabled($this->system->canNotifySubscribers());
->withComponentsOutGroups(Component::where('group_id', '=', 0)->get());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function createIncidentUpdateAction(Incident $incident)
Binput::get('message'),
Binput::get('component_id'),
Binput::get('component_status'),
Binput::get('notify'),
$this->auth->user()
));
} catch (ValidationException $e) {
Expand Down
7 changes: 7 additions & 0 deletions app/Integrations/Contracts/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public function getStatus();
*/
public function canNotifySubscribers();

/**
* Determine if Cachet should disable by default the checkbox to notify subscribers.
*
* @return bool
*/
public function shouldDisableNotifications();

/**
* Get the cachet version.
*
Expand Down
14 changes: 12 additions & 2 deletions app/Integrations/Core/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,23 @@ public function getStatus()
* @return bool
*/
public function canNotifySubscribers()
{
return $this->config->get('setting.enable_notifications');
}

/**
* Determine if Cachet should disable by default the checkbox to notify subscribers.
*
* @return bool
*/
public function shouldDisableNotifications()
{
$maintenancePeriods = Schedule::inProgress()->count();
if ($maintenancePeriods === 0) {
return true;
return false;
}

return !$this->config->get('setting.suppress_notifications_in_maintenance');
return $this->config->get('setting.disable_notifications_in_maintenance');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions config/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
| Suppress notifications while in maintenance
|--------------------------------------------------------------------------
|
| Whether to suppress notification channels if an issue is created during
| Whether to disable by default notifications if an issue is created during
| planned or in-progress maintenance periods.
|
*/

'suppress_notifications_in_maintenance' => true,
'disable_notifications_in_maintenance' => true,

/*
|--------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

'dashboard' => 'Dashboard',
'writeable_settings' => 'The Cachet settings directory is not writeable. Please make sure that <code>./bootstrap/cachet</code> is writeable by the web server.',
'notify_disabled' => 'Due to scheduled maintenance, notifications about status updates of components are disabled.',

// Incidents
'incidents' => [
Expand Down
35 changes: 18 additions & 17 deletions resources/lang/en/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
'message-help' => 'You may also use Markdown.',
'occurred_at' => 'When did this incident occur?',
'notify_subscribers' => 'Notify subscribers?',
'notify_disabled' => 'Due to scheduled maintenance, notifications about this incident or its components will be suppressed.',
'notify_disabled' => 'Due to scheduled maintenance, notifications about this incident or its components are disabled by default.',
'visibility' => 'Incident Visibility',
'stick_status' => 'Stick Incident',
'stickied' => 'Stickied',
Expand Down Expand Up @@ -148,22 +148,23 @@
'settings' => [
// Application setup
'app-setup' => [
'site-name' => 'Site Name',
'site-url' => 'Site URL',
'display-graphs' => 'Display graphs on status page?',
'about-this-page' => 'About this page',
'days-of-incidents' => 'How many days of incidents to show?',
'time_before_refresh' => 'Status page refresh rate (in seconds)',
'major_outage_rate' => 'Major outage threshold (in %)',
'banner' => 'Banner Image',
'banner-help' => "It's recommended that you upload files no bigger than 930px wide",
'subscribers' => 'Allow people to signup to email notifications?',
'suppress_notifications_in_maintenance' => 'Suppress notifications when incident occurs during maintenance period?',
'skip_subscriber_verification' => 'Skip verifying of users? (Be warned, you could be spammed)',
'automatic_localization' => 'Automatically localise your status page to your visitor\'s language?',
'enable_external_dependencies' => 'Enable Third Party Dependencies (Google Fonts, Trackers, etc...)',
'show_timezone' => 'Show the timezone the status page is running in',
'only_disrupted_days' => 'Only show days containing incidents in the timeline?',
'site-name' => 'Site Name',
'site-url' => 'Site URL',
'display-graphs' => 'Display graphs on status page?',
'about-this-page' => 'About this page',
'days-of-incidents' => 'How many days of incidents to show?',
'time_before_refresh' => 'Status page refresh rate (in seconds)',
'major_outage_rate' => 'Major outage threshold (in %)',
'banner' => 'Banner Image',
'banner-help' => "It's recommended that you upload files no bigger than 930px wide",
'subscribers' => 'Allow people to signup to email notifications?',
'enable_notifications' => 'Enable notifications?',
'disable_notifications_in_maintenance' => 'Disable notifications by default when incident occurs during maintenance period?',
'skip_subscriber_verification' => 'Skip verifying of users? (Be warned, you could be spammed)',
'automatic_localization' => 'Automatically localise your status page to your visitor\'s language?',
'enable_external_dependencies' => 'Enable Third Party Dependencies (Google Fonts, Trackers, etc...)',
'show_timezone' => 'Show the timezone the status page is running in',
'only_disrupted_days' => 'Only show days containing incidents in the timeline?',
],
'analytics' => [
'analytics_google' => 'Google Analytics code',
Expand Down
4 changes: 2 additions & 2 deletions resources/views/dashboard/incidents/add.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="content-wrapper">
<div class="row">
<div class="col-md-12">
@if(!$notificationsEnabled)
@if($noNotifications)
<div class="alert alert-info" role="alert">
{{ trans('forms.incidents.notify_disabled') }}
</div>
Expand Down Expand Up @@ -124,7 +124,7 @@
<input type="hidden" name="notify" value="0">
<div class="checkbox">
<label>
<input type="checkbox" name="notify" value="1" checked="{{ Binput::old('notify', 'checked') }}">
<input type="checkbox" name="notify" value="1" @if(!$noNotifications) checked @endif>
{{ trans('forms.incidents.notify_subscribers') }}
</label>
</div>
Expand Down
5 changes: 0 additions & 5 deletions resources/views/dashboard/incidents/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
<div class="content-wrapper">
<div class="row">
<div class="col-md-12">
@if(!$notificationsEnabled)
<div class="alert alert-info" role="alert">
{{ trans('forms.incidents.notify_disabled') }}
</div>
@endif
@include('partials.errors')
<form class="form-vertical" name="IncidentForm" role="form" method="POST" autocomplete="off">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
Expand Down
9 changes: 9 additions & 0 deletions resources/views/dashboard/incidents/updates/add.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@
<textarea name="message" class="form-control autosize" rows="5" required>{{ Binput::old('message') }}</textarea>
</div>
</div>
@if($notificationsEnabled)
<input type="hidden" name="notify" value="0">
<div class="checkbox">
<label>
<input type="checkbox" name="notify" value="1" checked="{{ Binput::old('notify', 'checked') }}">
{{ trans('forms.incidents.notify_subscribers') }}
</label>
</div>
@endif
</fieldset>

<input type="hidden" name="incident_id" value="{{ $incident->id }}">
Expand Down
6 changes: 6 additions & 0 deletions resources/views/dashboard/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
</div>
</div>

@if($noNotifications)
<div class="alert alert-info" role="alert">
{{ trans('dashboard.notify_disabled') }}
</div>
@endif

<div class="row">
<div class="col-md-12">
<div class="section-components no-select">
Expand Down
18 changes: 9 additions & 9 deletions resources/views/dashboard/maintenance/add.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@
<label>{{ trans('forms.schedules.completed_at') }}</label>
<input type="text" name="completed_at" class="form-control flatpickr-time" data-date-format="Y-m-d H:i" placeholder="{{ trans('forms.schedules.completed_at') }}">
</div>
@if($notificationsEnabled)
<input type="hidden" name="notify" value="0">
<div class="checkbox">
<label>
<input type="checkbox" name="notify" value="1" checked>
{{ trans('forms.incidents.notify_subscribers') }}
</label>
</div>
@endif
</fieldset>
@if($notificationsEnabled)
<input type="hidden" name="notify" value="0">
<div class="checkbox">
<label>
<input type="checkbox" name="notify" value="1" checked="{{ Binput::old('notify', 'checked') }}">
{{ trans('forms.incidents.notify_subscribers') }}
</label>
</div>
@endif
<div class="form-group">
<div class="btn-group">
<button type="submit" class="btn btn-success">{{ trans('forms.add') }}</button>
Expand Down
Loading