TenantAtlas/app/Policies/FindingPolicy.php
2026-01-28 22:04:45 +01:00

61 lines
1.3 KiB
PHP

<?php
namespace App\Policies;
use App\Models\Finding;
use App\Models\Tenant;
use App\Models\User;
use App\Support\Auth\Capabilities;
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Support\Facades\Gate;
class FindingPolicy
{
use HandlesAuthorization;
public function viewAny(User $user): bool
{
$tenant = Tenant::current();
if (! $tenant) {
return false;
}
return $user->canAccessTenant($tenant);
}
public function view(User $user, Finding $finding): bool
{
$tenant = Tenant::current();
if (! $tenant) {
return false;
}
if (! $user->canAccessTenant($tenant)) {
return false;
}
return (int) $finding->tenant_id === (int) $tenant->getKey();
}
public function update(User $user, Finding $finding): bool
{
$tenant = Tenant::current();
if (! $tenant instanceof Tenant) {
return false;
}
if (! $user->canAccessTenant($tenant)) {
return false;
}
if ((int) $finding->tenant_id !== (int) $tenant->getKey()) {
return false;
}
return Gate::forUser($user)->allows(Capabilities::TENANT_SYNC, $tenant);
}
}