Fix parent ticket assignment and display
linter / quality (pull_request) Successful in 1m15s
tests / ci (8.4) (pull_request) Successful in 1m35s

This commit is contained in:
2026-05-24 15:24:29 +00:00
parent ffe5939628
commit ce260bfd46
9 changed files with 227 additions and 1 deletions
@@ -4,9 +4,12 @@ namespace App\Http\Requests;
use App\Actions\Tickets\Support\AcceptanceCriteriaChecklistMapper;
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 StoreProjectTicketRequest extends FormRequest
{
@@ -55,6 +58,11 @@ class StoreProjectTicketRequest extends FormRequest
'acceptance_criteria.*.indent' => ['required', 'integer', 'min:0', 'max:'.AcceptanceCriteriaChecklistMapper::MAX_INDENT_LEVEL],
'assignee_user_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
'description' => ['nullable', 'string'],
'parent_ticket_id' => [
'nullable',
'integer',
Rule::exists('tickets', 'id')->where('project_id', $project->id),
],
'ticket_priority_id' => [
'required',
'integer',
@@ -74,4 +82,35 @@ class StoreProjectTicketRequest extends FormRequest
'title' => ['required', 'string', 'max:255'],
];
}
/**
* @return array<int, callable(Validator): void>
*/
public function after(): array
{
return [
function (Validator $validator): void {
/** @var array<string, mixed> $validated */
$validated = $this->safe()->all();
/** @var Project $project */
$project = $this->route('project');
$parentTicketId = Arr::get($validated, 'parent_ticket_id');
if ($parentTicketId === null) {
return;
}
$parentTicket = Ticket::query()
->where('project_id', $project->id)
->with('ticketType')
->find($parentTicketId);
if ($parentTicket !== null && ! $parentTicket->ticketType?->is_parent) {
$validator->errors()->add('parent_ticket_id', 'Only tickets with a parent-enabled type can be selected as a parent.');
}
},
];
}
}