TenantAtlas/apps/platform/app/Support/Rbac/TenantAccessContext.php
Ahmed Darrazi 9e435ea91f
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 1m2s
feat: implement explicit UiActionContext contract
2026-06-07 13:12:02 +02:00

60 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Support\Rbac;
use App\Models\ManagedEnvironment;
use App\Models\User;
/**
* DTO representing the access context for a tenant-scoped UI action.
*
* Captures the current user, tenant, membership status, and capability check result
* for use by the UiEnforcement helper.
*/
final readonly class TenantAccessContext
{
public function __construct(
public ?User $user,
public ?ManagedEnvironment $tenant,
public bool $isMember,
public bool $hasCapability,
public ?string $denialReason = null,
) {}
/**
* Non-members should receive 404 (deny-as-not-found).
*/
public function shouldDenyAsNotFound(): bool
{
return ! $this->isMember;
}
public function isContextMissing(): bool
{
return in_array($this->denialReason, [
'context_missing',
'workspace_missing',
'environment_missing',
'tenant_missing',
], true);
}
/**
* Members without capability should receive 403 (forbidden).
*/
public function shouldDenyAsForbidden(): bool
{
return $this->isMember && ! $this->hasCapability;
}
/**
* User is authorized to perform the action.
*/
public function isAuthorized(): bool
{
return $this->isMember && $this->hasCapability;
}
}