refactor(arch): enforce gateway compliance and remove service-wrapping gateways
This commit is contained in:
@@ -8,8 +8,6 @@ use MintyPHP\Service\Tenant\TenantScopeService;
|
||||
class DirectoryGatewayFactory
|
||||
{
|
||||
private ?DirectorySettingsGateway $directorySettingsGateway = null;
|
||||
private ?DirectoryScopeGateway $directoryScopeGateway = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly SettingServicesFactory $settingServicesFactory,
|
||||
private readonly TenantScopeService $tenantScopeService
|
||||
@@ -23,8 +21,8 @@ class DirectoryGatewayFactory
|
||||
);
|
||||
}
|
||||
|
||||
public function createDirectoryScopeGateway(): DirectoryScopeGateway
|
||||
public function getTenantScopeService(): TenantScopeService
|
||||
{
|
||||
return $this->directoryScopeGateway ??= new DirectoryScopeGateway($this->tenantScopeService);
|
||||
return $this->tenantScopeService;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<?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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use MintyPHP\Repository\Tenant\TenantRepositoryInterface;
|
||||
use MintyPHP\Service\Access\RoleService;
|
||||
use MintyPHP\Service\Audit\AuditServicesFactory;
|
||||
use MintyPHP\Service\Org\DepartmentService;
|
||||
use MintyPHP\Service\Tenant\TenantScopeService;
|
||||
use MintyPHP\Service\Tenant\TenantService;
|
||||
use MintyPHP\Service\User\UserServicesFactory;
|
||||
|
||||
@@ -41,7 +42,7 @@ class DirectoryServicesFactory
|
||||
$this->userServicesFactory,
|
||||
$this->createDepartmentRepository(),
|
||||
$this->createDirectorySettingsGateway(),
|
||||
$this->createDirectoryScopeGateway(),
|
||||
$this->directoryGatewayFactory->getTenantScopeService(),
|
||||
$this->auditServicesFactory->createSystemAuditService()
|
||||
);
|
||||
}
|
||||
@@ -76,8 +77,8 @@ class DirectoryServicesFactory
|
||||
return $this->directoryGatewayFactory->createDirectorySettingsGateway();
|
||||
}
|
||||
|
||||
public function createDirectoryScopeGateway(): DirectoryScopeGateway
|
||||
public function getTenantScopeService(): TenantScopeService
|
||||
{
|
||||
return $this->directoryGatewayFactory->createDirectoryScopeGateway();
|
||||
return $this->directoryGatewayFactory->getTenantScopeService();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user