Merge pull request #2877 from nstapelbroek/feature/2720-suppress-notifications-in-maintenance
Suppress notifications while in maintenance mode
This commit is contained in:
@@ -12,12 +12,20 @@
|
||||
namespace CachetHQ\Cachet\Bus\Handlers\Events\Component;
|
||||
|
||||
use CachetHQ\Cachet\Bus\Events\Component\ComponentStatusWasChangedEvent;
|
||||
use CachetHQ\Cachet\Integrations\Contracts\System;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Subscriber;
|
||||
use CachetHQ\Cachet\Notifications\Component\ComponentStatusChangedNotification;
|
||||
|
||||
class SendComponentUpdateEmailNotificationHandler
|
||||
{
|
||||
/**
|
||||
* The system instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Integrations\Contracts\System
|
||||
*/
|
||||
protected $system;
|
||||
|
||||
/**
|
||||
* The subscriber instance.
|
||||
*
|
||||
@@ -32,8 +40,9 @@ class SendComponentUpdateEmailNotificationHandler
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Subscriber $subscriber)
|
||||
public function __construct(System $system, Subscriber $subscriber)
|
||||
{
|
||||
$this->system = $system;
|
||||
$this->subscriber = $subscriber;
|
||||
}
|
||||
|
||||
@@ -48,8 +57,8 @@ class SendComponentUpdateEmailNotificationHandler
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,19 @@
|
||||
namespace CachetHQ\Cachet\Bus\Handlers\Events\Incident;
|
||||
|
||||
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasCreatedEvent;
|
||||
use CachetHQ\Cachet\Integrations\Contracts\System;
|
||||
use CachetHQ\Cachet\Models\Subscriber;
|
||||
use CachetHQ\Cachet\Notifications\Incident\NewIncidentNotification;
|
||||
|
||||
class SendIncidentEmailNotificationHandler
|
||||
{
|
||||
/**
|
||||
* The system instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Integrations\Contracts\System
|
||||
*/
|
||||
protected $system;
|
||||
|
||||
/**
|
||||
* The subscriber instance.
|
||||
*
|
||||
@@ -27,12 +35,14 @@ class SendIncidentEmailNotificationHandler
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function __construct(Subscriber $subscriber)
|
||||
public function __construct(System $system, Subscriber $subscriber)
|
||||
{
|
||||
$this->system = $system;
|
||||
$this->subscriber = $subscriber;
|
||||
}
|
||||
|
||||
@@ -47,7 +57,7 @@ class SendIncidentEmailNotificationHandler
|
||||
{
|
||||
$incident = $event->incident;
|
||||
|
||||
if (!$event->notify) {
|
||||
if (!$event->notify || !$this->system->canNotifySubscribers()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+14
-4
@@ -12,11 +12,19 @@
|
||||
namespace CachetHQ\Cachet\Bus\Handlers\Events\IncidentUpdate;
|
||||
|
||||
use CachetHQ\Cachet\Bus\Events\IncidentUpdate\IncidentUpdateWasReportedEvent;
|
||||
use CachetHQ\Cachet\Integrations\Contracts\System;
|
||||
use CachetHQ\Cachet\Models\Subscriber;
|
||||
use CachetHQ\Cachet\Notifications\IncidentUpdate\IncidentUpdatedNotification;
|
||||
|
||||
class SendIncidentUpdateEmailNotificationHandler
|
||||
{
|
||||
/**
|
||||
* The system instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Integrations\Contracts\System
|
||||
*/
|
||||
protected $system;
|
||||
|
||||
/**
|
||||
* The subscriber instance.
|
||||
*
|
||||
@@ -27,12 +35,14 @@ class SendIncidentUpdateEmailNotificationHandler
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function __construct(Subscriber $subscriber)
|
||||
public function __construct(System $system, Subscriber $subscriber)
|
||||
{
|
||||
$this->system = $system;
|
||||
$this->subscriber = $subscriber;
|
||||
}
|
||||
|
||||
@@ -48,8 +58,8 @@ class SendIncidentUpdateEmailNotificationHandler
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ use CachetHQ\Cachet\Bus\Commands\Incident\RemoveIncidentCommand;
|
||||
use CachetHQ\Cachet\Bus\Commands\Incident\UpdateIncidentCommand;
|
||||
use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\CreateIncidentUpdateCommand;
|
||||
use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\UpdateIncidentUpdateCommand;
|
||||
use CachetHQ\Cachet\Integrations\Contracts\System;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
@@ -48,6 +49,13 @@ class IncidentController extends Controller
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* The system instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Integrations\Contracts\System
|
||||
*/
|
||||
protected $system;
|
||||
|
||||
/**
|
||||
* Creates a new incident controller instance.
|
||||
*
|
||||
@@ -55,9 +63,10 @@ class IncidentController extends Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Guard $auth)
|
||||
public function __construct(Guard $auth, System $system)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->system = $system;
|
||||
|
||||
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'))
|
||||
->withComponentsInGroups(ComponentGroup::with('components')->get())
|
||||
->withComponentsOutGroups(Component::where('group_id', '=', 0)->get())
|
||||
->withNotificationsEnabled($this->system->canNotifySubscribers())
|
||||
->withIncidentTemplates(IncidentTemplate::all());
|
||||
}
|
||||
|
||||
@@ -225,7 +235,8 @@ class IncidentController extends Controller
|
||||
->withPageTitle(trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'))
|
||||
->withIncident($incident)
|
||||
->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)
|
||||
{
|
||||
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')
|
||||
->withIncident($incident)
|
||||
->withUpdate($incidentUpdate);
|
||||
->withUpdate($incidentUpdate)
|
||||
->withNotificationsEnabled($this->system->canNotifySubscribers());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,13 @@ interface System
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Integrations\Core;
|
||||
use CachetHQ\Cachet\Integrations\Contracts\System as SystemContract;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\Schedule;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
|
||||
@@ -102,6 +103,21 @@ class System implements SystemContract
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -16,6 +16,7 @@ use CachetHQ\Cachet\Models\Traits\SearchableTrait;
|
||||
use CachetHQ\Cachet\Models\Traits\SortableTrait;
|
||||
use CachetHQ\Cachet\Presenters\SchedulePresenter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use McCool\LaravelAutoPresenter\HasPresenter;
|
||||
|
||||
@@ -151,6 +152,20 @@ class Schedule extends Model implements HasPresenter
|
||||
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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user