Track who created incident. Closes #2717

This commit is contained in:
James Brooks
2017-09-14 19:13:00 +01:00
parent 0ebaa395c0
commit 1e3516d7b7
4 changed files with 67 additions and 0 deletions

View File

@@ -70,6 +70,7 @@ class CreateIncidentCommandHandler
public function handle(CreateIncidentCommand $command)
{
$data = [
'user_id' => $this->auth->user()->id,
'name' => $command->name,
'status' => $command->status,
'visible' => $command->visible,

View File

@@ -74,6 +74,7 @@ class Incident extends Model implements HasPresenter
* @var string[]
*/
protected $casts = [
'user_id' => 'int',
'visible' => 'int',
'stickied' => 'bool',
'occurred_at' => 'datetime',
@@ -86,6 +87,7 @@ class Incident extends Model implements HasPresenter
* @var string[]
*/
protected $fillable = [
'user_id',
'component_id',
'name',
'status',
@@ -103,6 +105,7 @@ class Incident extends Model implements HasPresenter
* @var string[]
*/
public $rules = [
'user_id' => 'required|int',
'component_id' => 'nullable|int',
'name' => 'required|string',
'status' => 'required|int',
@@ -118,6 +121,7 @@ class Incident extends Model implements HasPresenter
*/
protected $searchable = [
'id',
'user_id',
'component_id',
'name',
'status',
@@ -132,6 +136,7 @@ class Incident extends Model implements HasPresenter
*/
protected $sortable = [
'id',
'user_id',
'name',
'status',
'visible',
@@ -180,6 +185,16 @@ class Incident extends Model implements HasPresenter
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.
*

View File

@@ -83,6 +83,16 @@ class IncidentUpdate extends Model implements HasPresenter
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.
*

View File

@@ -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');
});
}
}