Adds incident visibility. Closes #602
This commit is contained in:
committed by
James Brooks
parent
9257135641
commit
df2ae7726d
@@ -24,13 +24,16 @@ class IncidentController extends AbstractApiController
|
|||||||
* Get all incidents.
|
* Get all incidents.
|
||||||
*
|
*
|
||||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
* @param \Illuminate\Contracts\Auth\Guard $auth
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Database\Eloquent\Collection
|
* @return \Illuminate\Database\Eloquent\Collection
|
||||||
*/
|
*/
|
||||||
public function getIncidents(Request $request)
|
public function getIncidents(Request $request, Guard $auth)
|
||||||
{
|
{
|
||||||
$incidents = Incident::paginate(Binput::get('per_page', 20));
|
$incidentVisiblity = $auth->check() ? 0 : 1;
|
||||||
|
|
||||||
|
$incidents = Incident::where('visible', '>=', $incidentVisiblity)
|
||||||
|
->paginate(Binput::get('per_page', 20));
|
||||||
|
|
||||||
return $this->paginator($incidents, $request);
|
return $this->paginator($incidents, $request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use CachetHQ\Cachet\Models\Metric;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use GrahamCampbell\Binput\Facades\Binput;
|
use GrahamCampbell\Binput\Facades\Binput;
|
||||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\View;
|
use Illuminate\Support\Facades\View;
|
||||||
use Jenssegers\Date\Date;
|
use Jenssegers\Date\Date;
|
||||||
|
|
||||||
@@ -65,7 +66,9 @@ class HomeController extends AbstractController
|
|||||||
$incidentDays = range(0, $daysToShow - 1);
|
$incidentDays = range(0, $daysToShow - 1);
|
||||||
$dateTimeZone = Setting::get('app_timezone');
|
$dateTimeZone = Setting::get('app_timezone');
|
||||||
|
|
||||||
$allIncidents = Incident::notScheduled()->whereBetween('created_at', [
|
$incidentVisiblity = Auth::check() ? 0 : 1;
|
||||||
|
|
||||||
|
$allIncidents = Incident::notScheduled()->where('visible', '>=', $incidentVisiblity)->whereBetween('created_at', [
|
||||||
$startDate->copy()->subDays($daysToShow)->format('Y-m-d').' 00:00:00',
|
$startDate->copy()->subDays($daysToShow)->format('Y-m-d').' 00:00:00',
|
||||||
$startDate->format('Y-m-d').' 23:59:59',
|
$startDate->format('Y-m-d').' 23:59:59',
|
||||||
])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use ($dateTimeZone) {
|
])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use ($dateTimeZone) {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class Incident extends Model implements HasPresenter
|
|||||||
'component_id' => 'integer',
|
'component_id' => 'integer',
|
||||||
'name' => 'required',
|
'name' => 'required',
|
||||||
'status' => 'required|integer',
|
'status' => 'required|integer',
|
||||||
|
'visible' => 'required|boolean',
|
||||||
'message' => 'required',
|
'message' => 'required',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@ class Incident extends Model implements HasPresenter
|
|||||||
'component_id',
|
'component_id',
|
||||||
'name',
|
'name',
|
||||||
'status',
|
'status',
|
||||||
|
'visible',
|
||||||
'message',
|
'message',
|
||||||
'scheduled_at',
|
'scheduled_at',
|
||||||
'created_at',
|
'created_at',
|
||||||
@@ -74,6 +76,18 @@ class Incident extends Model implements HasPresenter
|
|||||||
*/
|
*/
|
||||||
protected $dates = ['scheduled_at', 'deleted_at'];
|
protected $dates = ['scheduled_at', 'deleted_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all visible incidents.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public function scopeVisible($query)
|
||||||
|
{
|
||||||
|
return $query->where('visible', 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds all scheduled incidents (maintenance).
|
* Finds all scheduled incidents (maintenance).
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ $factory->define('CachetHQ\Cachet\Models\Incident', function ($faker) {
|
|||||||
'name' => $faker->sentence(),
|
'name' => $faker->sentence(),
|
||||||
'message' => $faker->paragraph(),
|
'message' => $faker->paragraph(),
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
|
'visible' => 1,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Cachet.
|
||||||
|
*
|
||||||
|
* (c) James Brooks <james@cachethq.io>
|
||||||
|
* (c) Joseph Cohen <joseph.cohen@dinkbit.com>
|
||||||
|
* (c) Graham Campbell <graham@mineuk.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AlterTableIncidentsAddVisibileColumn extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('incidents', function (Blueprint $table) {
|
||||||
|
$table->boolean('visible')->after('status')->default(1);
|
||||||
|
|
||||||
|
$table->index('visible');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('incidents', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('visible');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,8 +45,10 @@ return [
|
|||||||
'scheduled_at' => 'When to schedule the maintenance for?',
|
'scheduled_at' => 'When to schedule the maintenance for?',
|
||||||
'incident_time' => 'When did this incident occur?',
|
'incident_time' => 'When did this incident occur?',
|
||||||
'notify_subscribers' => 'Notify subscribers',
|
'notify_subscribers' => 'Notify subscribers',
|
||||||
|
'visibility' => 'Incident Visibility',
|
||||||
'templates' => [
|
'public' => 'Viewable by public',
|
||||||
|
'logged_in_only' => 'Only visible logged in users',
|
||||||
|
'templates' => [
|
||||||
'name' => 'Name',
|
'name' => 'Name',
|
||||||
'template' => 'Template',
|
'template' => 'Template',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -55,6 +55,13 @@
|
|||||||
{{ trans('cachet.incidents.status')[4] }}
|
{{ trans('cachet.incidents.status')[4] }}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="incident-name">{{ trans('forms.incidents.visibility') }}</label>
|
||||||
|
<select name='incident[visible]' class="form-control">
|
||||||
|
<option value='1' selected>{{ trans('forms.incidents.public') }}</option>
|
||||||
|
<option value='0'>{{ trans('forms.incidents.logged_in_only') }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
@if(!$componentsInGroups->isEmpty() || !$componentsOutGroups->isEmpty())
|
@if(!$componentsInGroups->isEmpty() || !$componentsOutGroups->isEmpty())
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>{{ trans('forms.incidents.component') }}</label>
|
<label>{{ trans('forms.incidents.component') }}</label>
|
||||||
|
|||||||
@@ -44,6 +44,13 @@
|
|||||||
{{ trans('cachet.incidents.status')[4] }}
|
{{ trans('cachet.incidents.status')[4] }}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="incident-visibility">{{ trans('forms.incidents.visibility') }}</label>
|
||||||
|
<select name='incident[visible]' id="incident-visibility" class="form-control">
|
||||||
|
<option value='1' {{ $incident->visible === 1 ? 'selected' : null }}>{{ trans('forms.incidents.public') }}</option>
|
||||||
|
<option value='0' {{ $incident->visible === 0 ? 'selected' : null }}>{{ trans('forms.incidents.logged_in_only') }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>{{ trans('forms.incidents.message') }}</label>
|
<label>{{ trans('forms.incidents.message') }}</label>
|
||||||
<div class='markdown-control'>
|
<div class='markdown-control'>
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class IncidentTest extends AbstractTestCase
|
|||||||
'name' => 'Foo',
|
'name' => 'Foo',
|
||||||
'message' => 'Lorem ipsum dolor sit amet',
|
'message' => 'Lorem ipsum dolor sit amet',
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
|
'visible' => 1,
|
||||||
]);
|
]);
|
||||||
$this->seeJson(['name' => 'Foo']);
|
$this->seeJson(['name' => 'Foo']);
|
||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
|
|||||||
Reference in New Issue
Block a user