fixed missing features
This commit is contained in:
@@ -6,8 +6,11 @@ use App\Actions\Git\BuildSuggestedTicketBranchName;
|
||||
use App\Actions\Git\ResolveTicketBranchMatches;
|
||||
use App\Actions\Git\ResolveTicketPullRequestMatches;
|
||||
use App\Actions\Permissions\PermissionService;
|
||||
use App\Actions\Tickets\BuildProjectTicketUpdateAttributes;
|
||||
use App\Actions\Tickets\CreateProjectTicket;
|
||||
use App\Actions\Tickets\UpdateProjectTicket;
|
||||
use App\Enums\Permission;
|
||||
use App\Http\Requests\StoreProjectTicketRequest;
|
||||
use App\Http\Requests\UpdateProjectTicketRequest;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
@@ -22,13 +25,68 @@ use Inertia\Response;
|
||||
class ProjectTicketController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BuildProjectTicketUpdateAttributes $buildProjectTicketUpdateAttributes,
|
||||
private readonly BuildSuggestedTicketBranchName $buildSuggestedTicketBranchName,
|
||||
private readonly CreateProjectTicket $createProjectTicket,
|
||||
private readonly PermissionService $permissionService,
|
||||
private readonly ResolveTicketBranchMatches $resolveTicketBranchMatches,
|
||||
private readonly ResolveTicketPullRequestMatches $resolveTicketPullRequestMatches,
|
||||
private readonly UpdateProjectTicket $updateProjectTicket,
|
||||
) {}
|
||||
|
||||
public function create(Request $request, Project $project): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
abort_unless(
|
||||
$this->permissionService->allows($user, Permission::ProjectWrite, $project),
|
||||
403,
|
||||
);
|
||||
|
||||
$source = Arr::get($request->query(), 'source') === 'board'
|
||||
? 'board'
|
||||
: 'backlog';
|
||||
$defaultTicketStatus = $source === 'board'
|
||||
? $project->ticketStatuses()->whereNotNull('board_column_id')->first()
|
||||
: $project->ticketStatuses()->whereNull('board_column_id')->first();
|
||||
|
||||
$defaultTicketStatus ??= $project->ticketStatuses()->first();
|
||||
|
||||
return Inertia::render('projects/TicketCreate', [
|
||||
'defaultTicketStatusId' => $defaultTicketStatus?->id,
|
||||
'project' => $project,
|
||||
'source' => $source,
|
||||
'status' => session('status'),
|
||||
'ticketPriorities' => $project->ticketPriorities()->get(),
|
||||
'ticketStatusOptions' => $project->ticketStatuses()
|
||||
->with('boardColumn')
|
||||
->get(),
|
||||
'ticketTypes' => $project->ticketTypes()->get(),
|
||||
'users' => User::query()
|
||||
->orderBy('name')
|
||||
->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreProjectTicketRequest $request, Project $project): RedirectResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
abort_unless(
|
||||
$this->permissionService->allows($user, Permission::ProjectWrite, $project),
|
||||
403,
|
||||
);
|
||||
|
||||
$ticket = $this->createProjectTicket->handle(
|
||||
$project,
|
||||
$request->validated(),
|
||||
$user,
|
||||
);
|
||||
|
||||
return to_route('projects.tickets.show', [$project, $ticket])
|
||||
->with('status', "{$ticket->ticket_key} was created.");
|
||||
}
|
||||
|
||||
public function show(Request $request, Project $project, Ticket $ticket): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
@@ -40,7 +98,6 @@ class ProjectTicketController extends Controller
|
||||
|
||||
$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',
|
||||
@@ -65,7 +122,7 @@ class ProjectTicketController extends Controller
|
||||
'linkedTickets' => $this->linkedTickets($ticket),
|
||||
'parentTicketOptions' => Ticket::query()
|
||||
->where('project_id', $project->id)
|
||||
->whereNotIn('id', $excludedParentIds)
|
||||
->whereKeyNot($ticket->id)
|
||||
->whereHas('ticketType', fn ($query) => $query->where('is_parent', true))
|
||||
->orderByDesc('sequence_number')
|
||||
->get()
|
||||
@@ -122,25 +179,7 @@ class ProjectTicketController extends Controller
|
||||
|
||||
$validated = $request->validated();
|
||||
$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'),
|
||||
];
|
||||
$ticketAttributes = $this->buildProjectTicketUpdateAttributes->handle($ticket, $validated);
|
||||
|
||||
$wasUpdated = $this->updateProjectTicket->handle(
|
||||
$ticket,
|
||||
@@ -181,20 +220,6 @@ class ProjectTicketController extends Controller
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, int>
|
||||
*/
|
||||
private function descendantIds(Ticket $ticket): array
|
||||
{
|
||||
return $ticket->childTickets()
|
||||
->get()
|
||||
->flatMap(function (Ticket $childTicket): array {
|
||||
return [$childTicket->id, ...$this->descendantIds($childTicket)];
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{
|
||||
* created_at: string|null,
|
||||
|
||||
Reference in New Issue
Block a user