Make maintenance also optional to notify subscribers
This commit is contained in:
@@ -60,6 +60,13 @@ final class CreateScheduleCommand
|
|||||||
*/
|
*/
|
||||||
public $components;
|
public $components;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to notify that the incident was reported.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $notify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The validation rules.
|
* The validation rules.
|
||||||
*
|
*
|
||||||
@@ -72,6 +79,7 @@ final class CreateScheduleCommand
|
|||||||
'scheduled_at' => 'required|string',
|
'scheduled_at' => 'required|string',
|
||||||
'completed_at' => 'nullable|string',
|
'completed_at' => 'nullable|string',
|
||||||
'components' => 'nullable|array',
|
'components' => 'nullable|array',
|
||||||
|
'notify' => 'nullable|bool'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,10 +91,11 @@ final class CreateScheduleCommand
|
|||||||
* @param string $scheduled_at
|
* @param string $scheduled_at
|
||||||
* @param string $completed_at
|
* @param string $completed_at
|
||||||
* @param array $components
|
* @param array $components
|
||||||
|
* @param notify $notify
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($name, $message, $status, $scheduled_at, $completed_at, array $components = [])
|
public function __construct($name, $message, $status, $scheduled_at, $completed_at, array $components = [], $notify)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
@@ -94,5 +103,6 @@ final class CreateScheduleCommand
|
|||||||
$this->scheduled_at = $scheduled_at;
|
$this->scheduled_at = $scheduled_at;
|
||||||
$this->completed_at = $completed_at;
|
$this->completed_at = $completed_at;
|
||||||
$this->components = $components;
|
$this->components = $components;
|
||||||
|
$this->notify = $notify;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,18 +36,27 @@ final class ScheduleWasCreatedEvent implements ActionInterface, ScheduleEventInt
|
|||||||
*/
|
*/
|
||||||
public $schedule;
|
public $schedule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to notify that the incident was reported.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $notify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new schedule was created event instance.
|
* Create a new schedule was created event instance.
|
||||||
*
|
*
|
||||||
* @param \CachetHQ\Cachet\Models\User $user
|
* @param \CachetHQ\Cachet\Models\User $user
|
||||||
* @param \CachetHQ\Cachet\Models\Schedule $schedule
|
* @param \CachetHQ\Cachet\Models\Schedule $schedule
|
||||||
|
* @param bool notify
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(User $user, Schedule $schedule)
|
public function __construct(User $user, Schedule $schedule, $notify = false)
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->schedule = $schedule;
|
$this->schedule = $schedule;
|
||||||
|
$this->notify = $notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ class CreateScheduleCommandHandler
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$schedule = Schedule::create($this->filter($command));
|
$schedule = Schedule::create($this->filter($command));
|
||||||
|
event(new ScheduleWasCreatedEvent($this->auth->user(), $schedule, (bool) $command->notify));
|
||||||
event(new ScheduleWasCreatedEvent($this->auth->user(), $schedule));
|
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
throw new ValidationException(new MessageBag([$e->getMessage()]));
|
throw new ValidationException(new MessageBag([$e->getMessage()]));
|
||||||
}
|
}
|
||||||
@@ -96,6 +95,7 @@ class CreateScheduleCommandHandler
|
|||||||
'status' => $command->status,
|
'status' => $command->status,
|
||||||
'scheduled_at' => $scheduledAt,
|
'scheduled_at' => $scheduledAt,
|
||||||
'completed_at' => $completedAt,
|
'completed_at' => $completedAt,
|
||||||
|
'notify' => $command->notify,
|
||||||
];
|
];
|
||||||
|
|
||||||
$availableParams = array_filter($params, function ($val) {
|
$availableParams = array_filter($params, function ($val) {
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ class SendScheduleEmailNotificationHandler
|
|||||||
public function handle(ScheduleEventInterface $event)
|
public function handle(ScheduleEventInterface $event)
|
||||||
{
|
{
|
||||||
$schedule = $event->schedule;
|
$schedule = $event->schedule;
|
||||||
|
if (!$event->notify) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// First notify all global subscribers.
|
// First notify all global subscribers.
|
||||||
$globalSubscribers = $this->subscriber->isVerified()->isGlobal()->get()->each(function ($subscriber) use ($schedule) {
|
$globalSubscribers = $this->subscriber->isVerified()->isGlobal()->get()->each(function ($subscriber) use ($schedule) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use AltThree\Validator\ValidationException;
|
|||||||
use CachetHQ\Cachet\Bus\Commands\Schedule\CreateScheduleCommand;
|
use CachetHQ\Cachet\Bus\Commands\Schedule\CreateScheduleCommand;
|
||||||
use CachetHQ\Cachet\Bus\Commands\Schedule\DeleteScheduleCommand;
|
use CachetHQ\Cachet\Bus\Commands\Schedule\DeleteScheduleCommand;
|
||||||
use CachetHQ\Cachet\Bus\Commands\Schedule\UpdateScheduleCommand;
|
use CachetHQ\Cachet\Bus\Commands\Schedule\UpdateScheduleCommand;
|
||||||
|
use CachetHQ\Cachet\Integrations\Contracts\System;
|
||||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||||
use CachetHQ\Cachet\Models\Schedule;
|
use CachetHQ\Cachet\Models\Schedule;
|
||||||
use GrahamCampbell\Binput\Facades\Binput;
|
use GrahamCampbell\Binput\Facades\Binput;
|
||||||
@@ -35,13 +36,22 @@ class ScheduleController extends Controller
|
|||||||
*/
|
*/
|
||||||
protected $subMenu = [];
|
protected $subMenu = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The system instance.
|
||||||
|
*
|
||||||
|
* @var \CachetHQ\Cachet\Integrations\Contracts\System
|
||||||
|
*/
|
||||||
|
protected $system;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new schedule controller instance.
|
* Creates a new schedule controller instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct(System $system)
|
||||||
{
|
{
|
||||||
|
$this->system = $system;
|
||||||
View::share('subTitle', trans('dashboard.schedule.title'));
|
View::share('subTitle', trans('dashboard.schedule.title'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +80,8 @@ class ScheduleController extends Controller
|
|||||||
|
|
||||||
return View::make('dashboard.maintenance.add')
|
return View::make('dashboard.maintenance.add')
|
||||||
->withPageTitle(trans('dashboard.schedule.add.title').' - '.trans('dashboard.dashboard'))
|
->withPageTitle(trans('dashboard.schedule.add.title').' - '.trans('dashboard.dashboard'))
|
||||||
->withIncidentTemplates($incidentTemplates);
|
->withIncidentTemplates($incidentTemplates)
|
||||||
|
->withNotificationsEnabled($this->system->canNotifySubscribers());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +98,8 @@ class ScheduleController extends Controller
|
|||||||
Binput::get('status', Schedule::UPCOMING),
|
Binput::get('status', Schedule::UPCOMING),
|
||||||
Binput::get('scheduled_at'),
|
Binput::get('scheduled_at'),
|
||||||
Binput::get('completed_at'),
|
Binput::get('completed_at'),
|
||||||
Binput::get('components', [])
|
Binput::get('components', []),
|
||||||
|
Binput::get('notify', false)
|
||||||
));
|
));
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return cachet_redirect('dashboard.schedule.create')
|
return cachet_redirect('dashboard.schedule.create')
|
||||||
|
|||||||
@@ -57,7 +57,15 @@
|
|||||||
<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') }}">
|
<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>
|
</div>
|
||||||
</fieldset>
|
</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="form-group">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button type="submit" class="btn btn-success">{{ trans('forms.add') }}</button>
|
<button type="submit" class="btn btn-success">{{ trans('forms.add') }}</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user