Add application API and OpenAPI docs
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Projects;
|
||||
|
||||
use App\Actions\Permissions\PermissionService;
|
||||
use App\Enums\Permission;
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ListVisibleProjects
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PermissionService $permissionService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Project>
|
||||
*/
|
||||
public function handle(User $user): Collection
|
||||
{
|
||||
$projectQuery = Project::query()
|
||||
->orderByDesc('id');
|
||||
|
||||
if ($this->permissionService->allows($user, Permission::GlobalAdmin)) {
|
||||
return $projectQuery->get();
|
||||
}
|
||||
|
||||
$viewableProjectIds = $this->permissionService->viewableProjectIds($user);
|
||||
|
||||
if ($viewableProjectIds === []) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
return $projectQuery
|
||||
->whereIn('id', $viewableProjectIds)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user