Implement ticket details and worklog editing
This commit is contained in:
@@ -4,10 +4,15 @@ namespace App\Actions\Tickets;
|
|||||||
|
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\Ticket;
|
use App\Models\Ticket;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class CreateProjectTicket
|
class CreateProjectTicket
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly CreateTicketWorklogEntry $createTicketWorklogEntry,
|
||||||
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array{
|
* @param array{
|
||||||
* acceptance_criteria: string|null,
|
* acceptance_criteria: string|null,
|
||||||
@@ -17,14 +22,14 @@ class CreateProjectTicket
|
|||||||
* title: string
|
* title: string
|
||||||
* } $attributes
|
* } $attributes
|
||||||
*/
|
*/
|
||||||
public function handle(Project $project, array $attributes): Ticket
|
public function handle(Project $project, array $attributes, ?User $actor = null): Ticket
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($attributes, $project): Ticket {
|
return DB::transaction(function () use ($actor, $attributes, $project): Ticket {
|
||||||
$nextSequenceNumber = (int) Ticket::query()
|
$nextSequenceNumber = (int) Ticket::query()
|
||||||
->where('project_id', $project->id)
|
->where('project_id', $project->id)
|
||||||
->max('sequence_number') + 1;
|
->max('sequence_number') + 1;
|
||||||
|
|
||||||
return Ticket::query()->create([
|
$ticket = Ticket::query()->create([
|
||||||
'acceptance_criteria' => $attributes['acceptance_criteria'],
|
'acceptance_criteria' => $attributes['acceptance_criteria'],
|
||||||
'board_column_id' => null,
|
'board_column_id' => null,
|
||||||
'description' => $attributes['description'],
|
'description' => $attributes['description'],
|
||||||
@@ -35,6 +40,23 @@ class CreateProjectTicket
|
|||||||
'ticket_type_id' => $attributes['ticket_type_id'],
|
'ticket_type_id' => $attributes['ticket_type_id'],
|
||||||
'title' => $attributes['title'],
|
'title' => $attributes['title'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($actor !== null) {
|
||||||
|
$this->createTicketWorklogEntry->handle(
|
||||||
|
$ticket,
|
||||||
|
$actor,
|
||||||
|
'created',
|
||||||
|
'Ticket was created in Backlog.',
|
||||||
|
[
|
||||||
|
'from' => null,
|
||||||
|
'to' => [
|
||||||
|
'label' => 'Backlog',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ticket;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,306 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Tickets;
|
||||||
|
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Models\TicketFieldDefinition;
|
||||||
|
use App\Models\TicketFieldValue;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class UpdateProjectTicket
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly CreateTicketWorklogEntry $createTicketWorklogEntry,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array{
|
||||||
|
* acceptance_criteria: string|null,
|
||||||
|
* description: string|null,
|
||||||
|
* ticket_priority_id: int,
|
||||||
|
* ticket_type_id: int,
|
||||||
|
* title: string
|
||||||
|
* } $ticketAttributes
|
||||||
|
* @param array<int, array{
|
||||||
|
* ticket_field_definition_id: int,
|
||||||
|
* value_number?: float|int|string|null,
|
||||||
|
* value_user_id?: int|string|null
|
||||||
|
* }> $fieldValueAttributes
|
||||||
|
*/
|
||||||
|
public function handle(
|
||||||
|
Ticket $ticket,
|
||||||
|
User $actor,
|
||||||
|
array $ticketAttributes,
|
||||||
|
array $fieldValueAttributes,
|
||||||
|
): bool {
|
||||||
|
return DB::transaction(function () use ($actor, $fieldValueAttributes, $ticket, $ticketAttributes): bool {
|
||||||
|
$ticket->loadMissing([
|
||||||
|
'fieldValues.ticketFieldDefinition',
|
||||||
|
'fieldValues.userValue',
|
||||||
|
'project',
|
||||||
|
'ticketPriority',
|
||||||
|
'ticketType',
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** @var Collection<int, TicketFieldDefinition> $fieldDefinitions */
|
||||||
|
$fieldDefinitions = $ticket->project->ticketFieldDefinitions()
|
||||||
|
->get()
|
||||||
|
->keyBy('id');
|
||||||
|
|
||||||
|
$ticketTypeOptions = $ticket->project->ticketTypes()
|
||||||
|
->get()
|
||||||
|
->keyBy('id');
|
||||||
|
$ticketPriorityOptions = $ticket->project->ticketPriorities()
|
||||||
|
->get()
|
||||||
|
->keyBy('id');
|
||||||
|
|
||||||
|
/** @var Collection<int, TicketFieldValue> $existingFieldValues */
|
||||||
|
$existingFieldValues = $ticket->fieldValues
|
||||||
|
->keyBy('ticket_field_definition_id');
|
||||||
|
|
||||||
|
$changes = [];
|
||||||
|
$summaryLabels = [];
|
||||||
|
|
||||||
|
$this->trackScalarChange(
|
||||||
|
$changes,
|
||||||
|
$summaryLabels,
|
||||||
|
'title',
|
||||||
|
'title',
|
||||||
|
$ticket->title,
|
||||||
|
$ticketAttributes['title'],
|
||||||
|
);
|
||||||
|
$this->trackScalarChange(
|
||||||
|
$changes,
|
||||||
|
$summaryLabels,
|
||||||
|
'description',
|
||||||
|
'description',
|
||||||
|
$ticket->description,
|
||||||
|
$ticketAttributes['description'],
|
||||||
|
);
|
||||||
|
$this->trackScalarChange(
|
||||||
|
$changes,
|
||||||
|
$summaryLabels,
|
||||||
|
'acceptance_criteria',
|
||||||
|
'acceptance criteria',
|
||||||
|
$ticket->acceptance_criteria,
|
||||||
|
$ticketAttributes['acceptance_criteria'],
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($ticket->ticket_type_id !== $ticketAttributes['ticket_type_id']) {
|
||||||
|
$changes['ticket_type'] = [
|
||||||
|
'from' => $ticket->ticketType?->name,
|
||||||
|
'to' => $ticketTypeOptions->get($ticketAttributes['ticket_type_id'])?->name,
|
||||||
|
];
|
||||||
|
$summaryLabels[] = 'type';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ticket->ticket_priority_id !== $ticketAttributes['ticket_priority_id']) {
|
||||||
|
$changes['ticket_priority'] = [
|
||||||
|
'from' => $ticket->ticketPriority?->name,
|
||||||
|
'to' => $ticketPriorityOptions->get($ticketAttributes['ticket_priority_id'])?->name,
|
||||||
|
];
|
||||||
|
$summaryLabels[] = 'priority';
|
||||||
|
}
|
||||||
|
|
||||||
|
$ticket->fill($ticketAttributes);
|
||||||
|
|
||||||
|
if ($ticket->isDirty()) {
|
||||||
|
$ticket->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($fieldValueAttributes as $fieldValueAttribute) {
|
||||||
|
$fieldDefinition = $fieldDefinitions->get((int) $fieldValueAttribute['ticket_field_definition_id']);
|
||||||
|
|
||||||
|
if ($fieldDefinition === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$existingFieldValue = $existingFieldValues->get($fieldDefinition->id);
|
||||||
|
|
||||||
|
if ($fieldDefinition->field_type === 'user') {
|
||||||
|
$this->syncUserFieldValue(
|
||||||
|
$changes,
|
||||||
|
$existingFieldValue,
|
||||||
|
$fieldDefinition,
|
||||||
|
$fieldValueAttribute,
|
||||||
|
$summaryLabels,
|
||||||
|
$ticket,
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->syncNumberFieldValue(
|
||||||
|
$changes,
|
||||||
|
$existingFieldValue,
|
||||||
|
$fieldDefinition,
|
||||||
|
$fieldValueAttribute,
|
||||||
|
$summaryLabels,
|
||||||
|
$ticket,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($summaryLabels === []) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->createTicketWorklogEntry->handle(
|
||||||
|
$ticket->fresh(),
|
||||||
|
$actor,
|
||||||
|
'updated',
|
||||||
|
$this->buildSummary($summaryLabels),
|
||||||
|
$changes,
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $changes
|
||||||
|
* @param array<int, string> $summaryLabels
|
||||||
|
*/
|
||||||
|
private function trackScalarChange(
|
||||||
|
array &$changes,
|
||||||
|
array &$summaryLabels,
|
||||||
|
string $changeKey,
|
||||||
|
string $summaryLabel,
|
||||||
|
?string $currentValue,
|
||||||
|
?string $newValue,
|
||||||
|
): void {
|
||||||
|
if ($currentValue === $newValue) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$changes[$changeKey] = [
|
||||||
|
'from' => $currentValue,
|
||||||
|
'to' => $newValue,
|
||||||
|
];
|
||||||
|
$summaryLabels[] = $summaryLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $changes
|
||||||
|
* @param array{value_user_id?: int|string|null} $fieldValueAttribute
|
||||||
|
* @param array<int, string> $summaryLabels
|
||||||
|
*/
|
||||||
|
private function syncUserFieldValue(
|
||||||
|
array &$changes,
|
||||||
|
?TicketFieldValue $existingFieldValue,
|
||||||
|
TicketFieldDefinition $fieldDefinition,
|
||||||
|
array $fieldValueAttribute,
|
||||||
|
array &$summaryLabels,
|
||||||
|
Ticket $ticket,
|
||||||
|
): void {
|
||||||
|
$newUserId = $fieldValueAttribute['value_user_id'] ?? null;
|
||||||
|
$newUserId = $newUserId === null || $newUserId === '' ? null : (int) $newUserId;
|
||||||
|
|
||||||
|
if ($existingFieldValue?->value_user_id === $newUserId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$oldUserName = $existingFieldValue?->userValue?->name;
|
||||||
|
$newUserName = $newUserId === null ? null : User::query()->find($newUserId)?->name;
|
||||||
|
|
||||||
|
$changes['field_values'][$fieldDefinition->id] = [
|
||||||
|
'field' => $fieldDefinition->label,
|
||||||
|
'from' => $oldUserName,
|
||||||
|
'to' => $newUserName,
|
||||||
|
];
|
||||||
|
$summaryLabels[] = "{$fieldDefinition->label} field";
|
||||||
|
|
||||||
|
if ($newUserId === null) {
|
||||||
|
$existingFieldValue?->delete();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ticket->fieldValues()->updateOrCreate(
|
||||||
|
[
|
||||||
|
'ticket_field_definition_id' => $fieldDefinition->id,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value_number' => null,
|
||||||
|
'value_user_id' => $newUserId,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $changes
|
||||||
|
* @param array{value_number?: float|int|string|null} $fieldValueAttribute
|
||||||
|
* @param array<int, string> $summaryLabels
|
||||||
|
*/
|
||||||
|
private function syncNumberFieldValue(
|
||||||
|
array &$changes,
|
||||||
|
?TicketFieldValue $existingFieldValue,
|
||||||
|
TicketFieldDefinition $fieldDefinition,
|
||||||
|
array $fieldValueAttribute,
|
||||||
|
array &$summaryLabels,
|
||||||
|
Ticket $ticket,
|
||||||
|
): void {
|
||||||
|
$newNumber = $fieldValueAttribute['value_number'] ?? null;
|
||||||
|
$newNumber = $newNumber === null || $newNumber === '' ? null : (float) $newNumber;
|
||||||
|
$oldNumber = $existingFieldValue?->value_number;
|
||||||
|
|
||||||
|
if ($oldNumber === $newNumber) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$changes['field_values'][$fieldDefinition->id] = [
|
||||||
|
'field' => $fieldDefinition->label,
|
||||||
|
'from' => $this->formatNumber($oldNumber),
|
||||||
|
'to' => $this->formatNumber($newNumber),
|
||||||
|
];
|
||||||
|
$summaryLabels[] = "{$fieldDefinition->label} field";
|
||||||
|
|
||||||
|
if ($newNumber === null) {
|
||||||
|
$existingFieldValue?->delete();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ticket->fieldValues()->updateOrCreate(
|
||||||
|
[
|
||||||
|
'ticket_field_definition_id' => $fieldDefinition->id,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value_number' => $newNumber,
|
||||||
|
'value_user_id' => null,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, string> $summaryLabels
|
||||||
|
*/
|
||||||
|
private function buildSummary(array $summaryLabels): string
|
||||||
|
{
|
||||||
|
$uniqueLabels = collect($summaryLabels)
|
||||||
|
->unique()
|
||||||
|
->values();
|
||||||
|
|
||||||
|
if ($uniqueLabels->count() === 1) {
|
||||||
|
return 'Updated '.$uniqueLabels->first().'.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($uniqueLabels->count() === 2) {
|
||||||
|
return 'Updated '.$uniqueLabels->first().' and '.$uniqueLabels->last().'.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$lastLabel = $uniqueLabels->pop();
|
||||||
|
|
||||||
|
return 'Updated '.$uniqueLabels->implode(', ').', and '.$lastLabel.'.';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function formatNumber(?float $value): ?string
|
||||||
|
{
|
||||||
|
if ($value === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rtrim(rtrim(number_format($value, 2, '.', ''), '0'), '.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@ class ProjectBacklogController extends Controller
|
|||||||
403,
|
403,
|
||||||
);
|
);
|
||||||
|
|
||||||
$ticket = $this->createProjectTicket->handle($project, $request->validated());
|
$ticket = $this->createProjectTicket->handle($project, $request->validated(), $request->user());
|
||||||
|
|
||||||
return to_route('projects.backlog.index', $project)
|
return to_route('projects.backlog.index', $project)
|
||||||
->with('status', "{$ticket->ticket_key} was added to the backlog.");
|
->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,12 @@ class Ticket extends Model
|
|||||||
return $this->belongsTo(BoardColumn::class);
|
return $this->belongsTo(BoardColumn::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function fieldValues(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(TicketFieldValue::class)
|
||||||
|
->orderBy('ticket_field_definition_id');
|
||||||
|
}
|
||||||
|
|
||||||
public function project(): BelongsTo
|
public function project(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Project::class);
|
return $this->belongsTo(Project::class);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
#[Fillable(['field_type', 'label', 'position', 'project_id'])]
|
#[Fillable(['field_type', 'label', 'position', 'project_id'])]
|
||||||
class TicketFieldDefinition extends Model
|
class TicketFieldDefinition extends Model
|
||||||
@@ -26,4 +27,10 @@ class TicketFieldDefinition extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Project::class);
|
return $this->belongsTo(Project::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ticketFieldValues(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(TicketFieldValue::class)
|
||||||
|
->orderBy('ticket_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Database\Factories\TicketFieldValueFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
#[Fillable([
|
||||||
|
'ticket_field_definition_id',
|
||||||
|
'ticket_id',
|
||||||
|
'value_number',
|
||||||
|
'value_user_id',
|
||||||
|
])]
|
||||||
|
class TicketFieldValue extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<TicketFieldValueFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'value_number' => 'float',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ticket(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Ticket::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ticketFieldDefinition(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(TicketFieldDefinition::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function userValue(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'value_user_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Models\TicketFieldDefinition;
|
||||||
|
use App\Models\TicketFieldValue;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<TicketFieldValue>
|
||||||
|
*/
|
||||||
|
class TicketFieldValueFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'value_number' => fake()->randomFloat(1, 1, 13),
|
||||||
|
'value_user_id' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configure(): static
|
||||||
|
{
|
||||||
|
return $this->afterMaking(function (TicketFieldValue $ticketFieldValue): void {
|
||||||
|
$ticket = $ticketFieldValue->ticket_id === null
|
||||||
|
? Ticket::factory()->create()
|
||||||
|
: Ticket::query()->findOrFail($ticketFieldValue->ticket_id);
|
||||||
|
|
||||||
|
app(InitializeProjectTicketMetadata::class)->handle($ticket->project);
|
||||||
|
|
||||||
|
$ticketFieldDefinition = $ticketFieldValue->ticket_field_definition_id === null
|
||||||
|
? TicketFieldDefinition::factory()->for($ticket->project)->create([
|
||||||
|
'field_type' => 'number',
|
||||||
|
'label' => 'Story Points',
|
||||||
|
'position' => $ticket->project->ticketFieldDefinitions()->count() + 1,
|
||||||
|
])
|
||||||
|
: TicketFieldDefinition::query()->findOrFail($ticketFieldValue->ticket_field_definition_id);
|
||||||
|
|
||||||
|
$ticketFieldValue->ticket_id = $ticket->id;
|
||||||
|
$ticketFieldValue->ticket_field_definition_id = $ticketFieldDefinition->id;
|
||||||
|
|
||||||
|
if ($ticketFieldDefinition->field_type === 'user') {
|
||||||
|
$ticketFieldValue->value_number = null;
|
||||||
|
$ticketFieldValue->value_user_id ??= User::factory()->create()->id;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ticketFieldValue->value_user_id = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('ticket_field_values', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('ticket_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('ticket_field_definition_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('value_user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||||
|
$table->decimal('value_number', 10, 2)->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unique(['ticket_id', 'ticket_field_definition_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('ticket_field_values');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -18,6 +18,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
BoardColumnSeeder::class,
|
BoardColumnSeeder::class,
|
||||||
ProjectTicketMetadataSeeder::class,
|
ProjectTicketMetadataSeeder::class,
|
||||||
TicketSeeder::class,
|
TicketSeeder::class,
|
||||||
|
TicketFieldValueSeeder::class,
|
||||||
TicketWorklogEntrySeeder::class,
|
TicketWorklogEntrySeeder::class,
|
||||||
TeamSeeder::class,
|
TeamSeeder::class,
|
||||||
ProjectAccessSeeder::class,
|
ProjectAccessSeeder::class,
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Project;
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Models\TicketFieldDefinition;
|
||||||
|
use App\Models\TicketFieldValue;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class TicketFieldValueSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
$defaultUser = User::query()
|
||||||
|
->orderBy('id')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
Project::query()
|
||||||
|
->with(['ticketFieldDefinitions', 'tickets'])
|
||||||
|
->orderBy('id')
|
||||||
|
->get()
|
||||||
|
->each(function (Project $project) use ($defaultUser): void {
|
||||||
|
/** @var TicketFieldDefinition $fieldDefinition */
|
||||||
|
foreach ($project->ticketFieldDefinitions as $fieldDefinition) {
|
||||||
|
/** @var Ticket $ticket */
|
||||||
|
foreach ($project->tickets as $ticket) {
|
||||||
|
TicketFieldValue::factory()->create([
|
||||||
|
'ticket_field_definition_id' => $fieldDefinition->id,
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'value_number' => $fieldDefinition->field_type === 'number'
|
||||||
|
? (float) ($ticket->sequence_number + 2)
|
||||||
|
: null,
|
||||||
|
'value_user_id' => $fieldDefinition->field_type === 'user'
|
||||||
|
? $defaultUser?->id
|
||||||
|
: null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ import AppLayout from '@/layouts/AppLayout.vue';
|
|||||||
import { index as boardIndex } from '@/routes/projects/board';
|
import { index as boardIndex } from '@/routes/projects/board';
|
||||||
import { index as backlogIndex } from '@/routes/projects/backlog';
|
import { index as backlogIndex } from '@/routes/projects/backlog';
|
||||||
import { index, show } from '@/routes/projects';
|
import { index, show } from '@/routes/projects';
|
||||||
|
import { show as showTicket } from '@/routes/projects/tickets';
|
||||||
import { metadata as metadataSettings } from '@/routes/projects/settings';
|
import { metadata as metadataSettings } from '@/routes/projects/settings';
|
||||||
import type { BreadcrumbItem, ProjectBacklogPageProps } from '@/types';
|
import type { BreadcrumbItem, ProjectBacklogPageProps } from '@/types';
|
||||||
|
|
||||||
@@ -245,16 +246,31 @@ const hasTicketMetadata =
|
|||||||
class="bg-background"
|
class="bg-background"
|
||||||
>
|
>
|
||||||
<td class="px-4 py-4">
|
<td class="px-4 py-4">
|
||||||
<Badge variant="outline">
|
<Link
|
||||||
{{ ticket.ticket_key }}
|
:href="
|
||||||
</Badge>
|
showTicket({
|
||||||
|
project: project.id,
|
||||||
|
ticket: ticket.id,
|
||||||
|
})
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<Badge variant="outline">
|
||||||
|
{{ ticket.ticket_key }}
|
||||||
|
</Badge>
|
||||||
|
</Link>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-4 py-4">
|
<td class="px-4 py-4">
|
||||||
<div
|
<Link
|
||||||
class="font-medium text-foreground"
|
:href="
|
||||||
|
showTicket({
|
||||||
|
project: project.id,
|
||||||
|
ticket: ticket.id,
|
||||||
|
})
|
||||||
|
"
|
||||||
|
class="font-medium text-foreground transition hover:text-primary"
|
||||||
>
|
>
|
||||||
{{ ticket.title }}
|
{{ ticket.title }}
|
||||||
</div>
|
</Link>
|
||||||
<div
|
<div
|
||||||
v-if="ticket.description"
|
v-if="ticket.description"
|
||||||
class="mt-1 line-clamp-2 text-muted-foreground"
|
class="mt-1 line-clamp-2 text-muted-foreground"
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { index as backlogIndex } from '@/routes/projects/backlog';
|
|||||||
import { index as projectIndex, show } from '@/routes/projects';
|
import { index as projectIndex, show } from '@/routes/projects';
|
||||||
import { board as boardSettings } from '@/routes/projects/settings';
|
import { board as boardSettings } from '@/routes/projects/settings';
|
||||||
import { index as boardIndex } from '@/routes/projects/board';
|
import { index as boardIndex } from '@/routes/projects/board';
|
||||||
|
import { show as showTicket } from '@/routes/projects/tickets';
|
||||||
import type { BreadcrumbItem, ProjectBoardPageProps } from '@/types';
|
import type { BreadcrumbItem, ProjectBoardPageProps } from '@/types';
|
||||||
|
|
||||||
const props = defineProps<ProjectBoardPageProps>();
|
const props = defineProps<ProjectBoardPageProps>();
|
||||||
@@ -150,7 +151,17 @@ const statusOptions = [
|
|||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<CardTitle class="text-base">
|
<CardTitle class="text-base">
|
||||||
{{ ticket.title }}
|
<Link
|
||||||
|
:href="
|
||||||
|
showTicket({
|
||||||
|
project: project.id,
|
||||||
|
ticket: ticket.id,
|
||||||
|
})
|
||||||
|
"
|
||||||
|
class="transition hover:text-primary"
|
||||||
|
>
|
||||||
|
{{ ticket.title }}
|
||||||
|
</Link>
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription
|
<CardDescription
|
||||||
v-if="ticket.description"
|
v-if="ticket.description"
|
||||||
|
|||||||
@@ -0,0 +1,410 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useForm, Head, Link } from '@inertiajs/vue3';
|
||||||
|
import ProjectTicketController from '@/actions/App/Http/Controllers/ProjectTicketController';
|
||||||
|
import Heading from '@/components/Heading.vue';
|
||||||
|
import InputError from '@/components/InputError.vue';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from '@/components/ui/card';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Label } from '@/components/ui/label';
|
||||||
|
import AppLayout from '@/layouts/AppLayout.vue';
|
||||||
|
import { index as backlogIndex } from '@/routes/projects/backlog';
|
||||||
|
import { index as boardIndex } from '@/routes/projects/board';
|
||||||
|
import { index as projectIndex, show } from '@/routes/projects';
|
||||||
|
import { show as showTicket } from '@/routes/projects/tickets';
|
||||||
|
import type { BreadcrumbItem, ProjectTicketPageProps } from '@/types';
|
||||||
|
|
||||||
|
const props = defineProps<ProjectTicketPageProps>();
|
||||||
|
|
||||||
|
const breadcrumbs: BreadcrumbItem[] = [
|
||||||
|
{
|
||||||
|
title: 'Projects',
|
||||||
|
href: projectIndex(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.project.name,
|
||||||
|
href: show(props.project.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.ticket.ticket_key,
|
||||||
|
href: showTicket({
|
||||||
|
project: props.project.id,
|
||||||
|
ticket: props.ticket.id,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
acceptance_criteria: props.ticket.acceptance_criteria ?? '',
|
||||||
|
description: props.ticket.description ?? '',
|
||||||
|
field_values: props.ticketFieldDefinitions.map((ticketFieldDefinition) => {
|
||||||
|
const currentFieldValue = props.ticket.field_values?.find(
|
||||||
|
(fieldValue) =>
|
||||||
|
fieldValue.ticket_field_definition_id ===
|
||||||
|
ticketFieldDefinition.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
ticket_field_definition_id: ticketFieldDefinition.id,
|
||||||
|
value_number: currentFieldValue?.value_number ?? '',
|
||||||
|
value_user_id: currentFieldValue?.value_user_id ?? '',
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
ticket_priority_id: props.ticket.ticket_priority_id,
|
||||||
|
ticket_type_id: props.ticket.ticket_type_id,
|
||||||
|
title: props.ticket.title,
|
||||||
|
});
|
||||||
|
|
||||||
|
const submit = (): void => {
|
||||||
|
if (!props.canEditTicket) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
form.submit(
|
||||||
|
ProjectTicketController.update({
|
||||||
|
project: props.project.id,
|
||||||
|
ticket: props.ticket.id,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
preserveScroll: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDateTime = (value: string): string => {
|
||||||
|
return new Intl.DateTimeFormat(undefined, {
|
||||||
|
dateStyle: 'medium',
|
||||||
|
timeStyle: 'short',
|
||||||
|
}).format(new Date(value));
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<AppLayout :breadcrumbs="breadcrumbs">
|
||||||
|
<Head :title="ticket.ticket_key" />
|
||||||
|
|
||||||
|
<div class="flex flex-1 flex-col gap-6 p-4">
|
||||||
|
<div
|
||||||
|
class="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between"
|
||||||
|
>
|
||||||
|
<div class="space-y-3">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<Badge variant="outline" class="px-3 py-1">
|
||||||
|
{{ ticket.ticket_key }}
|
||||||
|
</Badge>
|
||||||
|
<Badge variant="secondary">
|
||||||
|
{{ ticket.ticket_type.name }}
|
||||||
|
</Badge>
|
||||||
|
<Badge variant="secondary">
|
||||||
|
{{ ticket.ticket_priority.name }}
|
||||||
|
</Badge>
|
||||||
|
<Badge v-if="!canEditTicket" variant="outline">
|
||||||
|
Read only
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
<Heading
|
||||||
|
:title="ticket.title"
|
||||||
|
description="Review ticket details, update tracked fields, and inspect the change timeline."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap gap-3">
|
||||||
|
<Button as-child variant="outline">
|
||||||
|
<Link :href="backlogIndex(project.id)"
|
||||||
|
>Open backlog</Link
|
||||||
|
>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button as-child variant="outline">
|
||||||
|
<Link :href="boardIndex(project.id)">Open board</Link>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button as-child variant="outline">
|
||||||
|
<Link :href="show(project.id)">Back to project</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="status"
|
||||||
|
class="rounded-xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-900 dark:border-emerald-900/70 dark:bg-emerald-950/40 dark:text-emerald-100"
|
||||||
|
>
|
||||||
|
{{ status }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="grid gap-6 xl:grid-cols-[minmax(0,2fr)_minmax(320px,1fr)]"
|
||||||
|
>
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Ticket details</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
{{
|
||||||
|
canEditTicket
|
||||||
|
? 'Tracked ticket changes create worklog entries automatically.'
|
||||||
|
: 'You can review the tracked fields, but editing requires project edit permission.'
|
||||||
|
}}
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
<CardContent>
|
||||||
|
<form class="grid gap-6" @submit.prevent="submit">
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<Label for="title">Title</Label>
|
||||||
|
<Input
|
||||||
|
id="title"
|
||||||
|
v-model="form.title"
|
||||||
|
:disabled="
|
||||||
|
!canEditTicket || form.processing
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
<InputError :message="form.errors.title" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-2 md:grid-cols-2 md:gap-6">
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<Label for="ticket_type_id">Type</Label>
|
||||||
|
<select
|
||||||
|
id="ticket_type_id"
|
||||||
|
v-model="form.ticket_type_id"
|
||||||
|
:disabled="
|
||||||
|
!canEditTicket || form.processing
|
||||||
|
"
|
||||||
|
class="rounded-md border border-input bg-background px-3 py-2 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
v-for="ticketType in ticketTypes"
|
||||||
|
:key="ticketType.id"
|
||||||
|
:value="ticketType.id"
|
||||||
|
>
|
||||||
|
{{ ticketType.name }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<InputError
|
||||||
|
:message="form.errors.ticket_type_id"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<Label for="ticket_priority_id">
|
||||||
|
Priority
|
||||||
|
</Label>
|
||||||
|
<select
|
||||||
|
id="ticket_priority_id"
|
||||||
|
v-model="form.ticket_priority_id"
|
||||||
|
:disabled="
|
||||||
|
!canEditTicket || form.processing
|
||||||
|
"
|
||||||
|
class="rounded-md border border-input bg-background px-3 py-2 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
v-for="ticketPriority in ticketPriorities"
|
||||||
|
:key="ticketPriority.id"
|
||||||
|
:value="ticketPriority.id"
|
||||||
|
>
|
||||||
|
{{ ticketPriority.name }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<InputError
|
||||||
|
:message="
|
||||||
|
form.errors.ticket_priority_id
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<Label for="description">Description</Label>
|
||||||
|
<textarea
|
||||||
|
id="description"
|
||||||
|
v-model="form.description"
|
||||||
|
rows="5"
|
||||||
|
:disabled="
|
||||||
|
!canEditTicket || form.processing
|
||||||
|
"
|
||||||
|
class="rounded-md border border-input bg-background px-3 py-2 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
/>
|
||||||
|
<InputError
|
||||||
|
:message="form.errors.description"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<Label for="acceptance_criteria">
|
||||||
|
Acceptance criteria
|
||||||
|
</Label>
|
||||||
|
<textarea
|
||||||
|
id="acceptance_criteria"
|
||||||
|
v-model="form.acceptance_criteria"
|
||||||
|
rows="5"
|
||||||
|
:disabled="
|
||||||
|
!canEditTicket || form.processing
|
||||||
|
"
|
||||||
|
class="rounded-md border border-input bg-background px-3 py-2 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
/>
|
||||||
|
<InputError
|
||||||
|
:message="form.errors.acceptance_criteria"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-4">
|
||||||
|
<div class="space-y-1">
|
||||||
|
<h3 class="text-sm font-semibold">
|
||||||
|
Custom fields
|
||||||
|
</h3>
|
||||||
|
<p class="text-sm text-muted-foreground">
|
||||||
|
Project-configured fields can be tracked
|
||||||
|
directly on the ticket.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="ticketFieldDefinitions.length === 0"
|
||||||
|
class="rounded-xl border border-dashed border-border px-4 py-6 text-sm text-muted-foreground"
|
||||||
|
>
|
||||||
|
No custom fields are configured for this
|
||||||
|
project yet.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="grid gap-4 md:grid-cols-2">
|
||||||
|
<div
|
||||||
|
v-for="(
|
||||||
|
ticketFieldDefinition, index
|
||||||
|
) in ticketFieldDefinitions"
|
||||||
|
:key="ticketFieldDefinition.id"
|
||||||
|
class="grid gap-2"
|
||||||
|
>
|
||||||
|
<Label
|
||||||
|
:for="`field-${ticketFieldDefinition.id}`"
|
||||||
|
>
|
||||||
|
{{ ticketFieldDefinition.label }}
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<select
|
||||||
|
v-if="
|
||||||
|
ticketFieldDefinition.field_type ===
|
||||||
|
'user'
|
||||||
|
"
|
||||||
|
:id="`field-${ticketFieldDefinition.id}`"
|
||||||
|
v-model="
|
||||||
|
form.field_values[index]
|
||||||
|
.value_user_id
|
||||||
|
"
|
||||||
|
:disabled="
|
||||||
|
!canEditTicket ||
|
||||||
|
form.processing
|
||||||
|
"
|
||||||
|
class="rounded-md border border-input bg-background px-3 py-2 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
>
|
||||||
|
<option value="">Unassigned</option>
|
||||||
|
<option
|
||||||
|
v-for="user in users"
|
||||||
|
:key="user.id"
|
||||||
|
:value="user.id"
|
||||||
|
>
|
||||||
|
{{ user.name }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<Input
|
||||||
|
v-else
|
||||||
|
:id="`field-${ticketFieldDefinition.id}`"
|
||||||
|
v-model="
|
||||||
|
form.field_values[index]
|
||||||
|
.value_number
|
||||||
|
"
|
||||||
|
type="number"
|
||||||
|
step="0.1"
|
||||||
|
:disabled="
|
||||||
|
!canEditTicket ||
|
||||||
|
form.processing
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<InputError
|
||||||
|
:message="
|
||||||
|
form.errors[
|
||||||
|
`field_values.${index}.value_user_id`
|
||||||
|
] ??
|
||||||
|
form.errors[
|
||||||
|
`field_values.${index}.value_number`
|
||||||
|
]
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="canEditTicket"
|
||||||
|
class="flex items-center gap-3"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
:disabled="form.processing"
|
||||||
|
>
|
||||||
|
Save changes
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card class="h-fit">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Worklog</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Every tracked ticket change is recorded with actor
|
||||||
|
and timestamp.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
<CardContent class="space-y-4">
|
||||||
|
<div
|
||||||
|
v-if="(ticket.worklog_entries?.length ?? 0) === 0"
|
||||||
|
class="rounded-xl border border-dashed border-border px-4 py-6 text-sm text-muted-foreground"
|
||||||
|
>
|
||||||
|
No worklog entries exist for this ticket yet.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="flex flex-col gap-4">
|
||||||
|
<div
|
||||||
|
v-for="worklogEntry in ticket.worklog_entries"
|
||||||
|
:key="worklogEntry.id"
|
||||||
|
class="rounded-xl border border-border px-4 py-4"
|
||||||
|
>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<Badge variant="outline">
|
||||||
|
{{ worklogEntry.entry_type }}
|
||||||
|
</Badge>
|
||||||
|
<span
|
||||||
|
class="text-sm font-medium text-foreground"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
worklogEntry.actor?.name ?? 'System'
|
||||||
|
}}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p class="mt-3 text-sm text-foreground">
|
||||||
|
{{ worklogEntry.summary }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-2 text-xs text-muted-foreground">
|
||||||
|
{{
|
||||||
|
formatDateTime(worklogEntry.created_at)
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</AppLayout>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import type { TicketFieldDefinitionModel } from '@/types/models/ticket-field-definition-model';
|
||||||
|
import type { UserModel } from '@/types/models/user-model';
|
||||||
|
|
||||||
|
export type TicketFieldValueModel = {
|
||||||
|
id: number;
|
||||||
|
ticket_field_definition_id: number;
|
||||||
|
ticket_field_definition: TicketFieldDefinitionModel;
|
||||||
|
ticket_id: number;
|
||||||
|
user_value: UserModel | null;
|
||||||
|
value_number: number | null;
|
||||||
|
value_user_id: number | null;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
[key: string]: unknown;
|
||||||
|
};
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
|
import type { TicketFieldValueModel } from '@/types/models/ticket-field-value-model';
|
||||||
import type { TicketPriorityModel } from '@/types/models/ticket-priority-model';
|
import type { TicketPriorityModel } from '@/types/models/ticket-priority-model';
|
||||||
import type { TicketTypeModel } from '@/types/models/ticket-type-model';
|
import type { TicketTypeModel } from '@/types/models/ticket-type-model';
|
||||||
|
import type { TicketWorklogEntryModel } from '@/types/models/ticket-worklog-entry-model';
|
||||||
|
|
||||||
export type TicketModel = {
|
export type TicketModel = {
|
||||||
id: number;
|
id: number;
|
||||||
acceptance_criteria: string | null;
|
acceptance_criteria: string | null;
|
||||||
board_column_id: number | null;
|
board_column_id: number | null;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
|
field_values?: TicketFieldValueModel[];
|
||||||
project_id: number;
|
project_id: number;
|
||||||
sequence_number: number;
|
sequence_number: number;
|
||||||
ticket_key: string;
|
ticket_key: string;
|
||||||
@@ -14,6 +17,7 @@ export type TicketModel = {
|
|||||||
ticket_type: TicketTypeModel;
|
ticket_type: TicketTypeModel;
|
||||||
ticket_type_id: number;
|
ticket_type_id: number;
|
||||||
title: string;
|
title: string;
|
||||||
|
worklog_entries?: TicketWorklogEntryModel[];
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import type { UserModel } from '@/types/models/user-model';
|
||||||
|
|
||||||
|
export type TicketWorklogEntryModel = {
|
||||||
|
id: number;
|
||||||
|
actor: UserModel | null;
|
||||||
|
actor_id: number | null;
|
||||||
|
changes: Record<string, unknown> | null;
|
||||||
|
created_at: string;
|
||||||
|
entry_type: string;
|
||||||
|
summary: string;
|
||||||
|
ticket_id: number;
|
||||||
|
updated_at: string;
|
||||||
|
[key: string]: unknown;
|
||||||
|
};
|
||||||
@@ -79,3 +79,14 @@ export type ProjectBacklogPageProps = {
|
|||||||
tickets: TicketModel[];
|
tickets: TicketModel[];
|
||||||
ticketTypes: TicketTypeModel[];
|
ticketTypes: TicketTypeModel[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ProjectTicketPageProps = {
|
||||||
|
canEditTicket: boolean;
|
||||||
|
project: ProjectModel;
|
||||||
|
status?: string | null;
|
||||||
|
ticket: TicketModel;
|
||||||
|
ticketFieldDefinitions: TicketFieldDefinitionModel[];
|
||||||
|
ticketPriorities: TicketPriorityModel[];
|
||||||
|
ticketTypes: TicketTypeModel[];
|
||||||
|
users: UserModel[];
|
||||||
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use App\Http\Controllers\ProjectBacklogController;
|
|||||||
use App\Http\Controllers\ProjectBoardController;
|
use App\Http\Controllers\ProjectBoardController;
|
||||||
use App\Http\Controllers\ProjectBoardSettingsController;
|
use App\Http\Controllers\ProjectBoardSettingsController;
|
||||||
use App\Http\Controllers\ProjectController;
|
use App\Http\Controllers\ProjectController;
|
||||||
|
use App\Http\Controllers\ProjectTicketController;
|
||||||
use App\Http\Controllers\ProjectTicketMetadataSettingsController;
|
use App\Http\Controllers\ProjectTicketMetadataSettingsController;
|
||||||
use App\Http\Controllers\TeamController;
|
use App\Http\Controllers\TeamController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
@@ -34,6 +35,10 @@ Route::middleware(['auth', 'verified'])->group(function () {
|
|||||||
Route::scopeBindings()->group(function (): void {
|
Route::scopeBindings()->group(function (): void {
|
||||||
Route::get('projects/{project}/board', [ProjectBoardController::class, 'index'])
|
Route::get('projects/{project}/board', [ProjectBoardController::class, 'index'])
|
||||||
->name('projects.board.index');
|
->name('projects.board.index');
|
||||||
|
Route::get('projects/{project}/tickets/{ticket}', [ProjectTicketController::class, 'show'])
|
||||||
|
->name('projects.tickets.show');
|
||||||
|
Route::patch('projects/{project}/tickets/{ticket}', [ProjectTicketController::class, 'update'])
|
||||||
|
->name('projects.tickets.update');
|
||||||
Route::patch('projects/{project}/tickets/{ticket}/status', [ProjectBoardController::class, 'move'])
|
Route::patch('projects/{project}/tickets/{ticket}/status', [ProjectBoardController::class, 'move'])
|
||||||
->name('projects.tickets.status.update');
|
->name('projects.tickets.status.update');
|
||||||
Route::get('projects/{project}/settings/board', [ProjectBoardSettingsController::class, 'show'])
|
Route::get('projects/{project}/settings/board', [ProjectBoardSettingsController::class, 'show'])
|
||||||
|
|||||||
@@ -2,8 +2,12 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Models;
|
namespace Tests\Feature\Models;
|
||||||
|
|
||||||
|
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
|
use App\Models\Ticket;
|
||||||
use App\Models\TicketFieldDefinition;
|
use App\Models\TicketFieldDefinition;
|
||||||
|
use App\Models\TicketFieldValue;
|
||||||
|
use App\Models\TicketPriority;
|
||||||
use Database\Seeders\ProjectSeeder;
|
use Database\Seeders\ProjectSeeder;
|
||||||
use Database\Seeders\ProjectTicketMetadataSeeder;
|
use Database\Seeders\ProjectTicketMetadataSeeder;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
@@ -52,4 +56,45 @@ class TicketFieldDefinitionTest extends TestCase
|
|||||||
'position' => 2,
|
'position' => 2,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure ticket field definitions expose their related ticket values.
|
||||||
|
*/
|
||||||
|
public function test_ticket_field_definition_exposes_related_ticket_values(): void
|
||||||
|
{
|
||||||
|
$project = Project::factory()->create([
|
||||||
|
'key' => 'CORE',
|
||||||
|
]);
|
||||||
|
|
||||||
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||||
|
|
||||||
|
$priority = TicketPriority::factory()->for($project)->create([
|
||||||
|
'name' => 'Medium',
|
||||||
|
'position' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$ticket = Ticket::factory()->create([
|
||||||
|
'project_id' => $project->id,
|
||||||
|
'ticket_priority_id' => $priority->id,
|
||||||
|
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fieldDefinition = TicketFieldDefinition::factory()->for($project)->create([
|
||||||
|
'field_type' => 'number',
|
||||||
|
'label' => 'Story Points',
|
||||||
|
'position' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fieldValue = TicketFieldValue::factory()->create([
|
||||||
|
'ticket_field_definition_id' => $fieldDefinition->id,
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'value_number' => 5,
|
||||||
|
'value_user_id' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
[$fieldValue->id],
|
||||||
|
$fieldDefinition->fresh()->ticketFieldValues->modelKeys(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Models;
|
||||||
|
|
||||||
|
use App\Models\TicketFieldValue;
|
||||||
|
use Database\Seeders\BoardColumnSeeder;
|
||||||
|
use Database\Seeders\ProjectSeeder;
|
||||||
|
use Database\Seeders\ProjectTicketMetadataSeeder;
|
||||||
|
use Database\Seeders\TicketFieldValueSeeder;
|
||||||
|
use Database\Seeders\TicketSeeder;
|
||||||
|
use Database\Seeders\UserSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class TicketFieldValueTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure the field value factory creates a ticket and a compatible field definition.
|
||||||
|
*/
|
||||||
|
public function test_ticket_field_value_factory_creates_related_records(): void
|
||||||
|
{
|
||||||
|
$fieldValue = TicketFieldValue::factory()->create();
|
||||||
|
|
||||||
|
$this->assertNotNull($fieldValue->ticket);
|
||||||
|
$this->assertNotNull($fieldValue->ticketFieldDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure the field value seeder generates values for seeded tickets and fields.
|
||||||
|
*/
|
||||||
|
public function test_ticket_field_value_seeder_creates_values_for_seeded_tickets(): void
|
||||||
|
{
|
||||||
|
$this->seed([
|
||||||
|
UserSeeder::class,
|
||||||
|
ProjectSeeder::class,
|
||||||
|
BoardColumnSeeder::class,
|
||||||
|
ProjectTicketMetadataSeeder::class,
|
||||||
|
TicketSeeder::class,
|
||||||
|
TicketFieldValueSeeder::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('ticket_field_values', [
|
||||||
|
'value_number' => 3.0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(12, TicketFieldValue::query()->count());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,12 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Models;
|
namespace Tests\Feature\Models;
|
||||||
|
|
||||||
|
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\Ticket;
|
use App\Models\Ticket;
|
||||||
|
use App\Models\TicketFieldDefinition;
|
||||||
|
use App\Models\TicketFieldValue;
|
||||||
|
use App\Models\TicketPriority;
|
||||||
use App\Models\TicketWorklogEntry;
|
use App\Models\TicketWorklogEntry;
|
||||||
use Database\Seeders\BoardColumnSeeder;
|
use Database\Seeders\BoardColumnSeeder;
|
||||||
use Database\Seeders\ProjectSeeder;
|
use Database\Seeders\ProjectSeeder;
|
||||||
@@ -78,4 +82,47 @@ class TicketTest extends TestCase
|
|||||||
$ticket->fresh()->worklogEntries->modelKeys(),
|
$ticket->fresh()->worklogEntries->modelKeys(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure ticket field values are available through the ticket relation.
|
||||||
|
*/
|
||||||
|
public function test_ticket_field_values_are_available_through_the_ticket_relation(): void
|
||||||
|
{
|
||||||
|
$project = Project::factory()->create([
|
||||||
|
'key' => 'CORE',
|
||||||
|
]);
|
||||||
|
|
||||||
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||||
|
|
||||||
|
$priority = TicketPriority::factory()->for($project)->create([
|
||||||
|
'name' => 'Medium',
|
||||||
|
'position' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$ticket = Ticket::factory()->create([
|
||||||
|
'project_id' => $project->id,
|
||||||
|
'sequence_number' => 1,
|
||||||
|
'ticket_key' => 'CORE-1',
|
||||||
|
'ticket_priority_id' => $priority->id,
|
||||||
|
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fieldDefinition = TicketFieldDefinition::factory()->for($project)->create([
|
||||||
|
'field_type' => 'number',
|
||||||
|
'label' => 'Story Points',
|
||||||
|
'position' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fieldValue = TicketFieldValue::factory()->create([
|
||||||
|
'ticket_field_definition_id' => $fieldDefinition->id,
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'value_number' => 5,
|
||||||
|
'value_user_id' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
[$fieldValue->id],
|
||||||
|
$ticket->fresh()->fieldValues->modelKeys(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,5 +140,11 @@ class ProjectBacklogControllerTest extends TestCase
|
|||||||
'title' => 'Same title',
|
'title' => 'Same title',
|
||||||
'board_column_id' => null,
|
'board_column_id' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseCount('ticket_worklog_entries', 2);
|
||||||
|
$this->assertDatabaseHas('ticket_worklog_entries', [
|
||||||
|
'entry_type' => 'created',
|
||||||
|
'summary' => 'Ticket was created in Backlog.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,233 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Projects;
|
||||||
|
|
||||||
|
use App\Actions\ProjectPermissions\ProjectPermissionService;
|
||||||
|
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||||
|
use App\Models\Project;
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Models\TicketFieldDefinition;
|
||||||
|
use App\Models\TicketFieldValue;
|
||||||
|
use App\Models\TicketPriority;
|
||||||
|
use App\Models\TicketWorklogEntry;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Inertia\Testing\AssertableInertia as Assert;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class ProjectTicketControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure users with view permission can open ticket details and inspect worklog history.
|
||||||
|
*/
|
||||||
|
public function test_users_with_view_permission_can_view_ticket_details(): void
|
||||||
|
{
|
||||||
|
$viewer = User::factory()->create();
|
||||||
|
$project = Project::factory()->create([
|
||||||
|
'key' => 'CORE',
|
||||||
|
]);
|
||||||
|
|
||||||
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||||
|
|
||||||
|
$priority = TicketPriority::factory()->for($project)->create([
|
||||||
|
'name' => 'Medium',
|
||||||
|
'position' => 1,
|
||||||
|
]);
|
||||||
|
$fieldDefinition = TicketFieldDefinition::factory()->for($project)->create([
|
||||||
|
'field_type' => 'number',
|
||||||
|
'label' => 'Story Points',
|
||||||
|
'position' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$ticket = Ticket::factory()->create([
|
||||||
|
'project_id' => $project->id,
|
||||||
|
'sequence_number' => 1,
|
||||||
|
'ticket_key' => 'CORE-1',
|
||||||
|
'ticket_priority_id' => $priority->id,
|
||||||
|
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||||
|
'title' => 'Ticket detail test',
|
||||||
|
]);
|
||||||
|
|
||||||
|
TicketFieldValue::factory()->create([
|
||||||
|
'ticket_field_definition_id' => $fieldDefinition->id,
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'value_number' => 5,
|
||||||
|
'value_user_id' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
TicketWorklogEntry::factory()->create([
|
||||||
|
'actor_id' => $viewer->id,
|
||||||
|
'entry_type' => 'updated',
|
||||||
|
'summary' => 'Updated Story Points field.',
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
app(ProjectPermissionService::class)->syncUserPermissions($project, $viewer, ['view']);
|
||||||
|
|
||||||
|
$this->actingAs($viewer)
|
||||||
|
->get(route('projects.tickets.show', [$project, $ticket]))
|
||||||
|
->assertOk()
|
||||||
|
->assertInertia(fn (Assert $page) => $page
|
||||||
|
->component('projects/Ticket')
|
||||||
|
->where('project.id', $project->id)
|
||||||
|
->where('ticket.ticket_key', 'CORE-1')
|
||||||
|
->where('ticket.field_values.0.ticket_field_definition.label', 'Story Points')
|
||||||
|
->where('ticket.field_values.0.value_number', 5)
|
||||||
|
->where('ticket.worklog_entries.0.actor.name', $viewer->name)
|
||||||
|
->where('canEditTicket', false),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure updating ticket details requires the project edit permission.
|
||||||
|
*/
|
||||||
|
public function test_updating_ticket_details_requires_edit_permission(): void
|
||||||
|
{
|
||||||
|
$viewer = User::factory()->create();
|
||||||
|
$project = Project::factory()->create();
|
||||||
|
|
||||||
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||||
|
|
||||||
|
$priority = TicketPriority::factory()->for($project)->create([
|
||||||
|
'name' => 'Medium',
|
||||||
|
'position' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$ticket = Ticket::factory()->create([
|
||||||
|
'project_id' => $project->id,
|
||||||
|
'ticket_priority_id' => $priority->id,
|
||||||
|
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
app(ProjectPermissionService::class)->syncUserPermissions($project, $viewer, ['view']);
|
||||||
|
|
||||||
|
$this->actingAs($viewer)
|
||||||
|
->patch(route('projects.tickets.update', [$project, $ticket]), [
|
||||||
|
'title' => 'Updated title',
|
||||||
|
'description' => 'Updated description',
|
||||||
|
'acceptance_criteria' => 'Updated criteria',
|
||||||
|
'ticket_type_id' => $ticket->ticket_type_id,
|
||||||
|
'ticket_priority_id' => $ticket->ticket_priority_id,
|
||||||
|
'field_values' => [],
|
||||||
|
])
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure editing tracked ticket fields creates a worklog entry and persists field values.
|
||||||
|
*/
|
||||||
|
public function test_users_with_edit_permission_can_update_ticket_details_and_custom_fields(): void
|
||||||
|
{
|
||||||
|
$editor = User::factory()->create([
|
||||||
|
'name' => 'Editor User',
|
||||||
|
]);
|
||||||
|
$assignee = User::factory()->create([
|
||||||
|
'name' => 'Assigned User',
|
||||||
|
]);
|
||||||
|
$project = Project::factory()->create([
|
||||||
|
'key' => 'CORE',
|
||||||
|
]);
|
||||||
|
|
||||||
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||||
|
|
||||||
|
$lowPriority = TicketPriority::factory()->for($project)->create([
|
||||||
|
'name' => 'Low',
|
||||||
|
'position' => 1,
|
||||||
|
]);
|
||||||
|
$highPriority = TicketPriority::factory()->for($project)->create([
|
||||||
|
'name' => 'High',
|
||||||
|
'position' => 2,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$assigneeField = TicketFieldDefinition::factory()->for($project)->create([
|
||||||
|
'field_type' => 'user',
|
||||||
|
'label' => 'Assignee',
|
||||||
|
'position' => 1,
|
||||||
|
]);
|
||||||
|
$storyPointsField = TicketFieldDefinition::factory()->for($project)->create([
|
||||||
|
'field_type' => 'number',
|
||||||
|
'label' => 'Story Points',
|
||||||
|
'position' => 2,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$taskType = $project->ticketTypes()->where('system_key', 'task')->firstOrFail();
|
||||||
|
$parentType = $project->ticketTypes()->where('system_key', 'parent')->firstOrFail();
|
||||||
|
|
||||||
|
$ticket = Ticket::factory()->create([
|
||||||
|
'acceptance_criteria' => 'Old acceptance criteria',
|
||||||
|
'description' => 'Old description',
|
||||||
|
'project_id' => $project->id,
|
||||||
|
'sequence_number' => 1,
|
||||||
|
'ticket_key' => 'CORE-1',
|
||||||
|
'ticket_priority_id' => $lowPriority->id,
|
||||||
|
'ticket_type_id' => $taskType->id,
|
||||||
|
'title' => 'Old title',
|
||||||
|
]);
|
||||||
|
|
||||||
|
TicketFieldValue::factory()->create([
|
||||||
|
'ticket_field_definition_id' => $assigneeField->id,
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'value_number' => null,
|
||||||
|
'value_user_id' => $editor->id,
|
||||||
|
]);
|
||||||
|
TicketFieldValue::factory()->create([
|
||||||
|
'ticket_field_definition_id' => $storyPointsField->id,
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'value_number' => 3,
|
||||||
|
'value_user_id' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
app(ProjectPermissionService::class)->syncUserPermissions($project, $editor, ['edit', 'view']);
|
||||||
|
|
||||||
|
$this->actingAs($editor)
|
||||||
|
->patch(route('projects.tickets.update', [$project, $ticket]), [
|
||||||
|
'title' => 'Updated title',
|
||||||
|
'description' => 'Updated description',
|
||||||
|
'acceptance_criteria' => 'Updated acceptance criteria',
|
||||||
|
'ticket_type_id' => $parentType->id,
|
||||||
|
'ticket_priority_id' => $highPriority->id,
|
||||||
|
'field_values' => [
|
||||||
|
[
|
||||||
|
'ticket_field_definition_id' => $assigneeField->id,
|
||||||
|
'value_user_id' => $assignee->id,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ticket_field_definition_id' => $storyPointsField->id,
|
||||||
|
'value_number' => 8,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
||||||
|
->assertSessionHas('status', 'CORE-1 was updated.');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('tickets', [
|
||||||
|
'id' => $ticket->id,
|
||||||
|
'title' => 'Updated title',
|
||||||
|
'description' => 'Updated description',
|
||||||
|
'acceptance_criteria' => 'Updated acceptance criteria',
|
||||||
|
'ticket_type_id' => $parentType->id,
|
||||||
|
'ticket_priority_id' => $highPriority->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('ticket_field_values', [
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'ticket_field_definition_id' => $assigneeField->id,
|
||||||
|
'value_user_id' => $assignee->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('ticket_field_values', [
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'ticket_field_definition_id' => $storyPointsField->id,
|
||||||
|
'value_number' => 8.0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('ticket_worklog_entries', [
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'actor_id' => $editor->id,
|
||||||
|
'entry_type' => 'updated',
|
||||||
|
'summary' => 'Updated title, description, acceptance criteria, type, priority, Assignee field, and Story Points field.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user