Implement ticket statuses

This commit is contained in:
2026-04-14 03:09:12 +02:00
parent 2dc12c5d60
commit 8f4a8276ac
40 changed files with 1602 additions and 100 deletions
+42 -3
View File
@@ -3,9 +3,12 @@
namespace App\Http\Requests;
use App\Models\Project;
use App\Models\Ticket;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Arr;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
class MoveProjectTicketRequest extends FormRequest
{
@@ -28,12 +31,48 @@ class MoveProjectTicketRequest extends FormRequest
$project = $this->route('project');
return [
'board_column_id' => [
'nullable',
'ticket_status_id' => [
'required',
'integer',
Rule::exists('board_columns', 'id')->where('project_id', $project->id),
Rule::exists('ticket_statuses', 'id')->where('project_id', $project->id),
],
'redirect_to' => ['required', 'string', Rule::in(['backlog', 'board'])],
];
}
/**
* @return array<int, callable(Validator): void>
*/
public function after(): array
{
return [
function (Validator $validator): void {
if ($validator->errors()->isNotEmpty()) {
return;
}
/** @var Ticket $ticket */
$ticket = $this->route('ticket');
$validated = $validator->validated();
$ticketStatusId = (int) Arr::get($validated, 'ticket_status_id');
if ($ticket->ticket_status_id === $ticketStatusId) {
return;
}
$ticket->loadMissing('ticketStatus');
$isAllowed = $ticket->ticketStatus?->allowedTargetStatuses()
->whereKey($ticketStatusId)
->exists() ?? false;
if (! $isAllowed) {
$validator->errors()->add(
'ticket_status_id',
'Choose a status this ticket is allowed to move to.',
);
}
},
];
}
}
@@ -36,6 +36,14 @@ class StoreProjectTicketRequest extends FormRequest
'integer',
Rule::exists('ticket_priorities', 'id')->where('project_id', $project->id),
],
'ticket_status_id' => [
'required',
'integer',
Rule::exists('ticket_statuses', 'id')
->where(fn ($query) => $query
->where('project_id', $project->id)
->whereNull('board_column_id')),
],
'ticket_type_id' => [
'required',
'integer',
@@ -0,0 +1,39 @@
<?php
namespace App\Http\Requests;
use App\Models\Project;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreTicketStatusRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return $this->user() !== null;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
/** @var Project $project */
$project = $this->route('project');
return [
'board_column_id' => [
'nullable',
'integer',
Rule::exists('board_columns', 'id')->where('project_id', $project->id),
],
'name' => ['required', 'string', 'max:255'],
];
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class UpdateTicketStatusRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return $this->user() !== null;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
];
}
}