Show clients that are assigned to the employee, closes #893

This commit is contained in:
Alexander Groß
2025-10-17 00:55:41 +02:00
committed by Gregor Vostrak
parent 19a206d57c
commit 93d6a86f74
3 changed files with 54 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ use App\Http\Resources\V1\Client\ClientCollection;
use App\Http\Resources\V1\Client\ClientResource;
use App\Models\Client;
use App\Models\Organization;
use App\Models\Project;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Carbon;
@@ -38,11 +39,23 @@ class ClientController extends Controller
public function index(Organization $organization, ClientIndexRequest $request): ClientCollection
{
$this->checkPermission($organization, 'clients:view');
$canViewAllClients = $this->hasPermission($organization, 'clients:view:all');
$user = $this->user();
$clientsQuery = Client::query()
->whereBelongsTo($organization, 'organization')
->orderBy('created_at', 'desc');
if (! $canViewAllClients) {
$projectsQuery = Project::query()
->whereBelongsTo($organization, 'organization')
->visibleByEmployee($user)
->distinct()
->select('client_id');
$clientsQuery->whereIn('id', $projectsQuery);
}
$filterArchived = $request->getFilterArchived();
if ($filterArchived === 'true') {
$clientsQuery->whereNotNull('archived_at');