codex ticket rework
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\TicketType;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class DestroyProjectTicketTypeRequest 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 [
|
||||
'replacement_ticket_type_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('ticket_types', 'id')->where('project_id', $project->id),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, callable(Validator): void>
|
||||
*/
|
||||
public function after(): array
|
||||
{
|
||||
return [
|
||||
function (Validator $validator): void {
|
||||
/** @var Project $project */
|
||||
$project = $this->route('project');
|
||||
|
||||
/** @var TicketType $ticketType */
|
||||
$ticketType = $this->route('ticketType');
|
||||
|
||||
$hasReplacementOptions = $project->ticketTypes()
|
||||
->whereKeyNot($ticketType->id)
|
||||
->exists();
|
||||
|
||||
if (! $hasReplacementOptions || ! $ticketType->tickets()->exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var array<string, mixed> $validated */
|
||||
$validated = $this->safe()->all();
|
||||
$replacementTicketTypeId = Arr::get($validated, 'replacement_ticket_type_id');
|
||||
|
||||
if ($replacementTicketTypeId === null) {
|
||||
$validator->errors()->add(
|
||||
'replacement_ticket_type_id',
|
||||
'Choose a replacement type before deleting a type that is assigned to tickets.',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ((int) $replacementTicketTypeId === $ticketType->id) {
|
||||
$validator->errors()->add(
|
||||
'replacement_ticket_type_id',
|
||||
'The replacement type must be different from the deleted type.',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$replacementTicketType = $project->ticketTypes()
|
||||
->find($replacementTicketTypeId);
|
||||
|
||||
if (
|
||||
$replacementTicketType !== null
|
||||
&& ! $replacementTicketType->is_parent
|
||||
&& $ticketType->tickets()->has('childTickets')->exists()
|
||||
) {
|
||||
$validator->errors()->add(
|
||||
'replacement_ticket_type_id',
|
||||
'Choose a parent-enabled replacement type because affected tickets already have child tickets.',
|
||||
);
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ class StoreProjectTicketRequest extends FormRequest
|
||||
|
||||
return [
|
||||
'acceptance_criteria' => ['nullable', 'string'],
|
||||
'assignee_user_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
|
||||
'description' => ['nullable', 'string'],
|
||||
'ticket_priority_id' => [
|
||||
'required',
|
||||
|
||||
@@ -25,7 +25,6 @@ class UpdateProjectNamedSettingRequest extends FormRequest
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'position' => ['required', 'integer', 'min:1'],
|
||||
'is_parent' => ['nullable', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ class UpdateProjectTicketMetadataSettings extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'show_story_points' => 'nullable|boolean',
|
||||
'show_author' => ['nullable', 'boolean'],
|
||||
'show_story_points' => ['nullable', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Actions\Permissions\PermissionService;
|
||||
use App\Enums\Permission;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketType;
|
||||
@@ -33,6 +35,8 @@ class UpdateProjectTicketRequest extends FormRequest
|
||||
|
||||
return [
|
||||
'acceptance_criteria' => ['nullable', 'string'],
|
||||
'assignee_user_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
|
||||
'author_user_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
|
||||
'blocked_comment' => ['nullable', 'string'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'field_values' => ['array'],
|
||||
@@ -61,7 +65,7 @@ class UpdateProjectTicketRequest extends FormRequest
|
||||
Rule::exists('ticket_types', 'id')->where('project_id', $project->id),
|
||||
],
|
||||
'title' => ['required', 'string', 'max:255'],
|
||||
'story_points' => ['nullable', 'integer', 'gt:0'],
|
||||
'story_points' => ['nullable', 'integer', 'min:0'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -73,7 +77,7 @@ class UpdateProjectTicketRequest extends FormRequest
|
||||
return [
|
||||
function (Validator $validator): void {
|
||||
/** @var array<string, mixed> $validated */
|
||||
$validated = $this->validated();
|
||||
$validated = $this->safe()->all();
|
||||
|
||||
/** @var Project $project */
|
||||
$project = $this->route('project');
|
||||
@@ -81,6 +85,9 @@ class UpdateProjectTicketRequest extends FormRequest
|
||||
/** @var Ticket $ticket */
|
||||
$ticket = $this->route('ticket');
|
||||
|
||||
$canManageProject = app(PermissionService::class)
|
||||
->allows($this->user(), Permission::ProjectAdmin, $project);
|
||||
|
||||
$parentTicketId = Arr::get($validated, 'parent_ticket_id');
|
||||
|
||||
if ($parentTicketId !== null) {
|
||||
@@ -95,8 +102,8 @@ class UpdateProjectTicketRequest extends FormRequest
|
||||
->with('ticketType')
|
||||
->find($parentTicketId);
|
||||
|
||||
if ($parentTicket !== null && $parentTicket->ticketType?->system_key !== 'parent') {
|
||||
$validator->errors()->add('parent_ticket_id', 'Only tickets of type Parent can be selected as a parent.');
|
||||
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.');
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -114,15 +121,23 @@ class UpdateProjectTicketRequest extends FormRequest
|
||||
->find($requestedTicketTypeId);
|
||||
|
||||
if (
|
||||
$requestedTicketType?->system_key !== 'parent'
|
||||
! $requestedTicketType?->is_parent
|
||||
&& $ticket->childTickets()->exists()
|
||||
) {
|
||||
$validator->errors()->add('ticket_type_id', 'Tickets with child tickets must keep a Parent type.');
|
||||
$validator->errors()->add('ticket_type_id', 'Tickets with child tickets must keep a parent-enabled type.');
|
||||
}
|
||||
|
||||
if (Arr::get($validated, 'is_blocked', false) && blank(Arr::get($validated, 'blocked_comment'))) {
|
||||
$validator->errors()->add('blocked_comment', 'Blocked tickets require a blocker comment.');
|
||||
}
|
||||
|
||||
if (
|
||||
Arr::exists($validated, 'author_user_id')
|
||||
&& (int) Arr::get($validated, 'author_user_id') !== (int) $ticket->author_user_id
|
||||
&& ! $canManageProject
|
||||
) {
|
||||
$validator->errors()->add('author_user_id', 'Only project admins can change the author.');
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateProjectTicketTypeRequest 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'],
|
||||
'position' => ['required', 'integer', 'min:1'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user