Track who created incident. Closes #2717
This commit is contained in:
@@ -70,6 +70,7 @@ class CreateIncidentCommandHandler
|
|||||||
public function handle(CreateIncidentCommand $command)
|
public function handle(CreateIncidentCommand $command)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
'user_id' => $this->auth->user()->id,
|
||||||
'name' => $command->name,
|
'name' => $command->name,
|
||||||
'status' => $command->status,
|
'status' => $command->status,
|
||||||
'visible' => $command->visible,
|
'visible' => $command->visible,
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ class Incident extends Model implements HasPresenter
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
'user_id' => 'int',
|
||||||
'visible' => 'int',
|
'visible' => 'int',
|
||||||
'stickied' => 'bool',
|
'stickied' => 'bool',
|
||||||
'occurred_at' => 'datetime',
|
'occurred_at' => 'datetime',
|
||||||
@@ -86,6 +87,7 @@ class Incident extends Model implements HasPresenter
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
'user_id',
|
||||||
'component_id',
|
'component_id',
|
||||||
'name',
|
'name',
|
||||||
'status',
|
'status',
|
||||||
@@ -103,6 +105,7 @@ class Incident extends Model implements HasPresenter
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
public $rules = [
|
public $rules = [
|
||||||
|
'user_id' => 'required|int',
|
||||||
'component_id' => 'nullable|int',
|
'component_id' => 'nullable|int',
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'status' => 'required|int',
|
'status' => 'required|int',
|
||||||
@@ -118,6 +121,7 @@ class Incident extends Model implements HasPresenter
|
|||||||
*/
|
*/
|
||||||
protected $searchable = [
|
protected $searchable = [
|
||||||
'id',
|
'id',
|
||||||
|
'user_id',
|
||||||
'component_id',
|
'component_id',
|
||||||
'name',
|
'name',
|
||||||
'status',
|
'status',
|
||||||
@@ -132,6 +136,7 @@ class Incident extends Model implements HasPresenter
|
|||||||
*/
|
*/
|
||||||
protected $sortable = [
|
protected $sortable = [
|
||||||
'id',
|
'id',
|
||||||
|
'user_id',
|
||||||
'name',
|
'name',
|
||||||
'status',
|
'status',
|
||||||
'visible',
|
'visible',
|
||||||
@@ -180,6 +185,16 @@ class Incident extends Model implements HasPresenter
|
|||||||
return $this->hasMany(IncidentUpdate::class)->orderBy('created_at', 'desc');
|
return $this->hasMany(IncidentUpdate::class)->orderBy('created_at', 'desc');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user relation.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds all visible incidents.
|
* Finds all visible incidents.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -83,6 +83,16 @@ class IncidentUpdate extends Model implements HasPresenter
|
|||||||
return $this->belongsTo(Incident::class);
|
return $this->belongsTo(Incident::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user relation.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the presenter class.
|
* Get the presenter class.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Cachet.
|
||||||
|
*
|
||||||
|
* (c) Alt Three Services Limited
|
||||||
|
*
|
||||||
|
* 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 AlterIncidentsAddUserId extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('incidents', function (Blueprint $table) {
|
||||||
|
$table->integer('user_id')->unsigned()->nullable()->default(null)->index()->after('id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('incidents', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('user_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user