Implement ticket details and worklog editing

This commit is contained in:
2026-03-25 08:23:08 +01:00
parent 7e767b0c6c
commit 1ff8f5d68f
25 changed files with 1585 additions and 11 deletions
@@ -50,7 +50,7 @@ class ProjectBacklogController extends Controller
403,
);
$ticket = $this->createProjectTicket->handle($project, $request->validated());
$ticket = $this->createProjectTicket->handle($project, $request->validated(), $request->user());
return to_route('projects.backlog.index', $project)
->with('status', "{$ticket->ticket_key} was added to the backlog.");
@@ -0,0 +1,74 @@
<?php
namespace App\Http\Controllers;
use App\Actions\ProjectPermissions\ProjectPermissionService;
use App\Actions\Tickets\UpdateProjectTicket;
use App\Http\Requests\UpdateProjectTicketRequest;
use App\Models\Project;
use App\Models\Ticket;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
class ProjectTicketController extends Controller
{
public function __construct(
private readonly ProjectPermissionService $projectPermissionService,
private readonly UpdateProjectTicket $updateProjectTicket,
) {}
public function show(Request $request, Project $project, Ticket $ticket): Response
{
abort_unless(
$this->projectPermissionService->userCanViewProject($request->user(), $project),
403,
);
return Inertia::render('projects/Ticket', [
'canEditTicket' => $this->projectPermissionService->userHasPermission($request->user(), $project, 'edit'),
'project' => $project,
'status' => session('status'),
'ticket' => $ticket->load([
'fieldValues.ticketFieldDefinition',
'fieldValues.userValue',
'ticketPriority',
'ticketType',
'worklogEntries.actor',
]),
'ticketFieldDefinitions' => $project->ticketFieldDefinitions()->get(),
'ticketPriorities' => $project->ticketPriorities()->get(),
'ticketTypes' => $project->ticketTypes()->get(),
'users' => User::query()
->orderBy('name')
->get(),
]);
}
public function update(
UpdateProjectTicketRequest $request,
Project $project,
Ticket $ticket,
): RedirectResponse {
abort_unless(
$this->projectPermissionService->userHasPermission($request->user(), $project, 'edit'),
403,
);
$wasUpdated = $this->updateProjectTicket->handle(
$ticket,
$request->user(),
$request->ticketAttributes(),
$request->fieldValues(),
);
$statusMessage = $wasUpdated
? "{$ticket->ticket_key} was updated."
: 'No ticket changes were detected.';
return to_route('projects.tickets.show', [$project, $ticket])
->with('status', $statusMessage);
}
}
@@ -0,0 +1,106 @@
<?php
namespace App\Http\Requests;
use App\Models\Project;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Arr;
use Illuminate\Validation\Rule;
class UpdateProjectTicketRequest 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 [
'acceptance_criteria' => ['nullable', 'string'],
'description' => ['nullable', 'string'],
'field_values' => ['array'],
'field_values.*' => ['array'],
'field_values.*.ticket_field_definition_id' => [
'required',
'integer',
Rule::exists('ticket_field_definitions', 'id')->where('project_id', $project->id),
],
'field_values.*.value_number' => ['nullable', 'numeric'],
'field_values.*.value_user_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
'ticket_priority_id' => [
'required',
'integer',
Rule::exists('ticket_priorities', 'id')->where('project_id', $project->id),
],
'ticket_type_id' => [
'required',
'integer',
Rule::exists('ticket_types', 'id')->where('project_id', $project->id),
],
'title' => ['required', 'string', 'max:255'],
];
}
/**
* @return array{
* acceptance_criteria: string|null,
* description: string|null,
* ticket_priority_id: int,
* ticket_type_id: int,
* title: string
* }
*/
public function ticketAttributes(): array
{
/** @var array{
* acceptance_criteria: string|null,
* description: string|null,
* ticket_priority_id: int,
* ticket_type_id: int,
* title: string
* } $attributes
*/
$attributes = Arr::only($this->validated(), [
'acceptance_criteria',
'description',
'ticket_priority_id',
'ticket_type_id',
'title',
]);
return $attributes;
}
/**
* @return array<int, array{
* ticket_field_definition_id: int,
* value_number?: float|int|string|null,
* value_user_id?: int|string|null
* }>
*/
public function fieldValues(): array
{
/** @var array<int, array{
* ticket_field_definition_id: int,
* value_number?: float|int|string|null,
* value_user_id?: int|string|null
* }> $fieldValues
*/
$fieldValues = $this->validated('field_values', []);
return $fieldValues;
}
}