Merge pull request 'Add application API keys' (#55) from codex/application-api-keys into main
Reviewed-on: OpenSource/KanbanGit#55
This commit was merged in pull request #55.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Tickets;
|
||||
|
||||
use App\Actions\Projects\ListVisibleProjects;
|
||||
use App\Http\Resources\ProjectResource;
|
||||
use App\Http\Resources\TicketResource;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class ListAssignedTicketsByVisibleProject
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ListVisibleProjects $listVisibleProjects,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<int, array{project: array<string, mixed>, tickets: array<int, array<string, mixed>>}>
|
||||
*/
|
||||
public function handle(User $viewer, User $assignee): array
|
||||
{
|
||||
/** @var EloquentCollection<int, Project> $visibleProjects */
|
||||
$visibleProjects = $this->listVisibleProjects->handle($viewer);
|
||||
$visibleProjectIds = $visibleProjects->pluck('id')->all();
|
||||
|
||||
if ($visibleProjectIds === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/** @var Collection<int, Collection<int, Ticket>> $ticketsByProject */
|
||||
$ticketsByProject = Ticket::query()
|
||||
->where('assignee_user_id', $assignee->id)
|
||||
->whereIn('project_id', $visibleProjectIds)
|
||||
->with([
|
||||
'assignee',
|
||||
'project',
|
||||
'ticketPriority',
|
||||
'ticketStatus.boardColumn',
|
||||
'ticketType',
|
||||
])
|
||||
->orderByDesc('sequence_number')
|
||||
->get()
|
||||
->groupBy('project_id');
|
||||
|
||||
return $visibleProjects
|
||||
->filter(fn (Project $project): bool => $ticketsByProject->has($project->id))
|
||||
->map(fn (Project $project): array => [
|
||||
'project' => ProjectResource::make($project)->resolve(),
|
||||
'tickets' => TicketResource::collection($ticketsByProject->get($project->id))->resolve(),
|
||||
])
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\UserApplications;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\UserApplication;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class CreateUserApplication
|
||||
{
|
||||
/**
|
||||
* @param array{name: string} $validated
|
||||
* @return array{application: UserApplication, plain_text_key: string}
|
||||
*/
|
||||
public function handle(User $user, array $validated): array
|
||||
{
|
||||
$plainTextKey = UserApplication::generatePlainTextKey();
|
||||
|
||||
$application = UserApplication::query()->create([
|
||||
'key_hash' => UserApplication::hashKey($plainTextKey),
|
||||
'name' => Arr::get($validated, 'name'),
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
return [
|
||||
'application' => $application,
|
||||
'plain_text_key' => $plainTextKey,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\UserApplications;
|
||||
|
||||
use App\Models\UserApplication;
|
||||
|
||||
class DeleteUserApplication
|
||||
{
|
||||
public function handle(UserApplication $application): string
|
||||
{
|
||||
$name = $application->name;
|
||||
|
||||
$application->delete();
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user