forked from fa/breadcrumb-the-shire
59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Service\Directory;
|
|
|
|
use MintyPHP\Service\Tenant\TenantScopeService;
|
|
|
|
class DirectoryScopeGateway
|
|
{
|
|
public function __construct(
|
|
private readonly TenantScopeService $tenantScopeService
|
|
) {
|
|
}
|
|
|
|
public function hasGlobalAccess(int $userId): bool
|
|
{
|
|
return $this->tenantScopeService->hasGlobalAccess($userId);
|
|
}
|
|
|
|
public function getUserTenantIds(int $userId): array
|
|
{
|
|
return $this->tenantScopeService->getUserTenantIds($userId);
|
|
}
|
|
|
|
public function isStrict(): bool
|
|
{
|
|
return $this->tenantScopeService->isStrict();
|
|
}
|
|
|
|
public function canAccess(string $resourceType, int $resourceId, int $userId): bool
|
|
{
|
|
return $this->tenantScopeService->canAccess($resourceType, $resourceId, $userId);
|
|
}
|
|
|
|
public function resourceBelongsToTenant(string $resourceType, int $resourceId, int $tenantId): bool
|
|
{
|
|
return $this->tenantScopeService->resourceBelongsToTenant($resourceType, $resourceId, $tenantId);
|
|
}
|
|
|
|
public function filterTenantIdsForUser(array $tenantIds, int $userId): array
|
|
{
|
|
return $this->tenantScopeService->filterTenantIdsForUser($tenantIds, $userId);
|
|
}
|
|
|
|
// When a scoped admin updates tenant assignments, they can't see tenants outside their scope.
|
|
// This merges the requested IDs with any out-of-scope IDs from existing assignments so those
|
|
// aren't silently dropped when the admin saves.
|
|
public function mergeTenantIdsPreservingOutOfScope(
|
|
array $requestedTenantIds,
|
|
array $existingTenantIds,
|
|
array $allowedTenantIds
|
|
): array {
|
|
return $this->tenantScopeService->mergeTenantIdsPreservingOutOfScope(
|
|
$requestedTenantIds,
|
|
$existingTenantIds,
|
|
$allowedTenantIds
|
|
);
|
|
}
|
|
}
|