codex ticket rework
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Enums\Permission;
|
||||
use App\Http\Requests\StoreProjectTicketRequest;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
@@ -43,6 +44,9 @@ class ProjectBacklogController extends Controller
|
||||
->whereNull('board_column_id')
|
||||
->orderByDesc('sequence_number')
|
||||
->get(),
|
||||
'users' => User::query()
|
||||
->orderBy('name')
|
||||
->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,28 @@ class ProjectTicketController extends Controller
|
||||
403,
|
||||
);
|
||||
|
||||
$canEditTicket = $this->permissionService->allows($user, Permission::ProjectWrite, $project);
|
||||
$canManageProject = $this->permissionService->allows($user, Permission::ProjectAdmin, $project);
|
||||
$excludedParentIds = [$ticket->id, ...$this->descendantIds($ticket)];
|
||||
$displayTicket = $ticket->load([
|
||||
'assignee',
|
||||
'author',
|
||||
'fieldValues.ticketFieldDefinition',
|
||||
'fieldValues.userValue',
|
||||
'parentTicket',
|
||||
'ticketPriority',
|
||||
'ticketType',
|
||||
'worklogEntries.actor',
|
||||
]);
|
||||
|
||||
if (! $project->show_author && ! $canManageProject) {
|
||||
$displayTicket->setRelation('author', null);
|
||||
$displayTicket->author_user_id = null;
|
||||
}
|
||||
|
||||
return Inertia::render('projects/Ticket', [
|
||||
'canEditTicket' => $this->permissionService->allows($user, Permission::ProjectWrite, $project),
|
||||
'canEditTicket' => $canEditTicket,
|
||||
'canManageProject' => $canManageProject,
|
||||
'childTicketTree' => $this->buildChildTicketTree($ticket),
|
||||
'linkedTickets' => $this->linkedTickets($ticket),
|
||||
'parentTicketOptions' => Ticket::query()
|
||||
@@ -68,14 +86,7 @@ class ProjectTicketController extends Controller
|
||||
),
|
||||
'status' => session('status'),
|
||||
'suggestedBranchName' => $this->buildSuggestedTicketBranchName->handle($ticket),
|
||||
'ticket' => $ticket->load([
|
||||
'fieldValues.ticketFieldDefinition',
|
||||
'fieldValues.userValue',
|
||||
'parentTicket',
|
||||
'ticketPriority',
|
||||
'ticketType',
|
||||
'worklogEntries.actor',
|
||||
]),
|
||||
'ticket' => $displayTicket,
|
||||
'ticketFieldDefinitions' => $project->ticketFieldDefinitions()->get(),
|
||||
'ticketLinkOptions' => Ticket::query()
|
||||
->where('project_id', $project->id)
|
||||
@@ -109,17 +120,25 @@ class ProjectTicketController extends Controller
|
||||
);
|
||||
|
||||
$validated = $request->validated();
|
||||
$fieldValues = Arr::get($validated, 'field_values');
|
||||
$fieldValues = Arr::get($validated, 'field_values', []);
|
||||
$ticketAttributes = [
|
||||
'acceptance_criteria' => Arr::get($validated, 'acceptance_criteria'),
|
||||
'assignee_user_id' => Arr::exists($validated, 'assignee_user_id')
|
||||
? Arr::get($validated, 'assignee_user_id')
|
||||
: $ticket->assignee_user_id,
|
||||
'author_user_id' => Arr::exists($validated, 'author_user_id')
|
||||
? Arr::get($validated, 'author_user_id')
|
||||
: $ticket->author_user_id,
|
||||
'blocked_comment' => Arr::get($validated, 'blocked_comment'),
|
||||
'description' => Arr::get($validated, 'description'),
|
||||
'is_blocked' => Arr::get($validated, 'is_blocked', false),
|
||||
'parent_ticket_id' => Arr::get($validated, 'parent_ticket_id'),
|
||||
'story_points' => Arr::exists($validated, 'story_points')
|
||||
? Arr::get($validated, 'story_points')
|
||||
: $ticket->story_points,
|
||||
'ticket_priority_id' => Arr::get($validated, 'ticket_priority_id'),
|
||||
'ticket_type_id' => Arr::get($validated, 'ticket_type_id'),
|
||||
'title' => Arr::get($validated, 'title'),
|
||||
'story_points' => Arr::get($validated, 'story_points'),
|
||||
];
|
||||
|
||||
$wasUpdated = $this->updateProjectTicket->handle(
|
||||
|
||||
@@ -3,14 +3,18 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Permissions\PermissionService;
|
||||
use App\Actions\Tickets\CreateTicketWorklogEntry;
|
||||
use App\Enums\Permission;
|
||||
use App\Http\Requests\DestroyProjectTicketTypeRequest;
|
||||
use App\Http\Requests\StoreProjectNamedSettingRequest;
|
||||
use App\Http\Requests\StoreProjectTicketTypeRequest;
|
||||
use App\Http\Requests\StoreTicketFieldDefinitionRequest;
|
||||
use App\Http\Requests\UpdateProjectNamedSettingRequest;
|
||||
use App\Http\Requests\UpdateProjectTicketMetadataSettings;
|
||||
use App\Http\Requests\UpdateProjectTicketTypeRequest;
|
||||
use App\Http\Requests\UpdateTicketFieldDefinitionRequest;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketFieldDefinition;
|
||||
use App\Models\TicketLinkType;
|
||||
use App\Models\TicketPriority;
|
||||
@@ -27,6 +31,7 @@ use Inertia\Response;
|
||||
class ProjectTicketMetadataSettingsController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CreateTicketWorklogEntry $createTicketWorklogEntry,
|
||||
private readonly PermissionService $permissionService,
|
||||
) {}
|
||||
|
||||
@@ -47,15 +52,20 @@ class ProjectTicketMetadataSettingsController extends Controller
|
||||
'ticketFieldDefinitions' => $project->ticketFieldDefinitions()->get(),
|
||||
'ticketLinkTypes' => $project->ticketLinkTypes()->get(),
|
||||
'ticketPriorities' => $project->ticketPriorities()->get(),
|
||||
'ticketTypes' => $project->ticketTypes()->get(),
|
||||
'ticketTypes' => $project->ticketTypes()->withCount('tickets')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateProjectTicketMetadataSettings $request, Project $project): RedirectResponse
|
||||
{
|
||||
$this->abortUnlessCanManage($request, $project);
|
||||
|
||||
$validated = $request->validated();
|
||||
|
||||
$project->update(['show_story_points' => Arr::get($validated, 'show_story_points', false)]);
|
||||
$project->update([
|
||||
'show_author' => Arr::get($validated, 'show_author', false),
|
||||
'show_story_points' => Arr::get($validated, 'show_story_points', false),
|
||||
]);
|
||||
|
||||
return to_route('projects.settings.metadata', $project)
|
||||
->with('status', 'Settings have been updated.');
|
||||
@@ -88,7 +98,7 @@ class ProjectTicketMetadataSettingsController extends Controller
|
||||
}
|
||||
|
||||
public function updateType(
|
||||
UpdateProjectNamedSettingRequest $request,
|
||||
UpdateProjectTicketTypeRequest $request,
|
||||
Project $project,
|
||||
TicketType $ticketType,
|
||||
): RedirectResponse {
|
||||
@@ -99,7 +109,6 @@ class ProjectTicketMetadataSettingsController extends Controller
|
||||
DB::transaction(function () use ($project, $validated, $ticketType): void {
|
||||
$ticketType->update([
|
||||
'name' => Arr::get($validated, 'name'),
|
||||
'is_parent' => Arr::get($validated, 'is_parent', false),
|
||||
]);
|
||||
|
||||
$this->reorderModels(
|
||||
@@ -113,8 +122,11 @@ class ProjectTicketMetadataSettingsController extends Controller
|
||||
->with('status', "{$ticketType->fresh()->name} type was updated.");
|
||||
}
|
||||
|
||||
public function destroyType(Request $request, Project $project, TicketType $ticketType): RedirectResponse
|
||||
{
|
||||
public function destroyType(
|
||||
DestroyProjectTicketTypeRequest $request,
|
||||
Project $project,
|
||||
TicketType $ticketType,
|
||||
): RedirectResponse {
|
||||
$this->abortUnlessCanManage($request, $project);
|
||||
|
||||
if ($project->ticketTypes()->count() === 1) {
|
||||
@@ -124,8 +136,40 @@ class ProjectTicketMetadataSettingsController extends Controller
|
||||
}
|
||||
|
||||
$deletedName = $ticketType->name;
|
||||
$validated = $request->validated();
|
||||
|
||||
DB::transaction(function () use ($deletedName, $project, $request, $ticketType, $validated): void {
|
||||
$replacementTicketTypeId = Arr::get($validated, 'replacement_ticket_type_id');
|
||||
|
||||
if ($replacementTicketTypeId !== null) {
|
||||
$replacementTicketType = $project->ticketTypes()
|
||||
->findOrFail($replacementTicketTypeId);
|
||||
|
||||
Ticket::query()
|
||||
->where('project_id', $project->id)
|
||||
->where('ticket_type_id', $ticketType->id)
|
||||
->with(['ticketType'])
|
||||
->get()
|
||||
->each(function (Ticket $ticket) use ($deletedName, $replacementTicketType, $request): void {
|
||||
$ticket->update([
|
||||
'ticket_type_id' => $replacementTicketType->id,
|
||||
]);
|
||||
|
||||
$this->createTicketWorklogEntry->handle(
|
||||
$ticket->fresh(),
|
||||
$request->user(),
|
||||
'updated',
|
||||
"Updated type because {$deletedName} type was deleted.",
|
||||
[
|
||||
'ticket_type' => [
|
||||
'from' => $deletedName,
|
||||
'to' => $replacementTicketType->name,
|
||||
],
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($project, $ticketType): void {
|
||||
$ticketType->delete();
|
||||
|
||||
$this->persistOrderedModels($project->ticketTypes()->get()->values());
|
||||
|
||||
@@ -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