refactor(arch): enforce gateway compliance and remove service-wrapping gateways
This commit is contained in:
@@ -8,6 +8,7 @@ use MintyPHP\Repository\User\UserListQueryRepositoryInterface;
|
||||
use MintyPHP\Repository\User\UserReadRepositoryInterface;
|
||||
use MintyPHP\Repository\User\UserWriteRepositoryInterface;
|
||||
use MintyPHP\Service\Audit\SystemAuditService;
|
||||
use MintyPHP\Service\Tenant\TenantScopeService;
|
||||
|
||||
class UserAccountService
|
||||
{
|
||||
@@ -18,7 +19,7 @@ class UserAccountService
|
||||
private readonly UserAssignmentService $userAssignmentService,
|
||||
private readonly UserPasswordService $userPasswordService,
|
||||
private readonly UserSettingsGateway $settingsGateway,
|
||||
private readonly UserScopeGateway $scopeGateway,
|
||||
private readonly TenantScopeService $scopeGateway,
|
||||
private readonly UserDirectoryGateway $directoryGateway,
|
||||
private readonly SystemAuditService $systemAuditService,
|
||||
private readonly DatabaseSessionRepository $databaseSessionRepository
|
||||
|
||||
@@ -7,6 +7,7 @@ use MintyPHP\Repository\Org\UserDepartmentRepositoryInterface;
|
||||
use MintyPHP\Repository\Support\DatabaseSessionRepository;
|
||||
use MintyPHP\Repository\Tenant\UserTenantRepositoryInterface;
|
||||
use MintyPHP\Repository\User\UserWriteRepositoryInterface;
|
||||
use MintyPHP\Service\Access\PermissionService;
|
||||
|
||||
class UserAssignmentService
|
||||
{
|
||||
@@ -16,7 +17,7 @@ class UserAssignmentService
|
||||
private readonly UserRoleRepositoryInterface $userRoleRepository,
|
||||
private readonly UserDepartmentRepositoryInterface $userDepartmentRepository,
|
||||
private readonly UserDirectoryGateway $directoryGateway,
|
||||
private readonly UserPermissionGateway $permissionGateway,
|
||||
private readonly PermissionService $permissionService,
|
||||
private readonly DatabaseSessionRepository $databaseSessionRepository
|
||||
) {
|
||||
}
|
||||
@@ -181,7 +182,7 @@ class UserAssignmentService
|
||||
$ids = array_values(array_filter($ids, static fn ($id) => isset($validMap[$id])));
|
||||
}
|
||||
$result = $this->userRoleRepository->replaceForUser($userId, $ids);
|
||||
$this->permissionGateway->clearUserCache($userId);
|
||||
$this->permissionService->clearUserCache($userId);
|
||||
if ($result && $bumpAuthz) {
|
||||
$this->bumpAuthzVersion($userId);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace MintyPHP\Service\User;
|
||||
|
||||
use MintyPHP\Service\Access\AccessServicesFactory;
|
||||
use MintyPHP\Service\Access\PermissionGateway;
|
||||
use MintyPHP\Service\Access\PermissionService;
|
||||
use MintyPHP\Service\Directory\DirectoryRepositoryFactory;
|
||||
use MintyPHP\Service\Settings\SettingsAppGateway;
|
||||
use MintyPHP\Service\Settings\SettingsDefaultsGateway;
|
||||
@@ -16,12 +16,9 @@ class UserGatewayFactory
|
||||
private ?SettingsDefaultsGateway $settingsDefaultsGateway = null;
|
||||
private ?SettingsAppGateway $settingsAppGateway = null;
|
||||
private ?SettingsUserLifecycleGateway $settingsUserLifecycleGateway = null;
|
||||
private ?PermissionGateway $permissionGateway = null;
|
||||
private ?PermissionService $permissionService = null;
|
||||
private ?UserSettingsGateway $userSettingsGateway = null;
|
||||
private ?UserScopeGateway $userScopeGateway = null;
|
||||
private ?UserDirectoryGateway $userDirectoryGateway = null;
|
||||
private ?UserPermissionGateway $userPermissionGateway = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly AccessServicesFactory $accessServicesFactory,
|
||||
private readonly SettingServicesFactory $settingServicesFactory,
|
||||
@@ -39,9 +36,9 @@ class UserGatewayFactory
|
||||
);
|
||||
}
|
||||
|
||||
public function createUserScopeGateway(): UserScopeGateway
|
||||
public function getTenantScopeService(): TenantScopeService
|
||||
{
|
||||
return $this->userScopeGateway ??= new UserScopeGateway($this->tenantScopeService);
|
||||
return $this->tenantScopeService;
|
||||
}
|
||||
|
||||
public function createUserDirectoryGateway(): UserDirectoryGateway
|
||||
@@ -53,14 +50,9 @@ class UserGatewayFactory
|
||||
);
|
||||
}
|
||||
|
||||
public function createUserPermissionGateway(): UserPermissionGateway
|
||||
public function createPermissionService(): PermissionService
|
||||
{
|
||||
return $this->userPermissionGateway ??= new UserPermissionGateway($this->createPermissionGateway());
|
||||
}
|
||||
|
||||
private function createPermissionGateway(): PermissionGateway
|
||||
{
|
||||
return $this->permissionGateway ??= $this->accessServicesFactory->createPermissionGateway();
|
||||
return $this->permissionService ??= $this->accessServicesFactory->createPermissionService();
|
||||
}
|
||||
|
||||
private function createSettingsDefaultsGateway(): SettingsDefaultsGateway
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Service\User;
|
||||
|
||||
use MintyPHP\Service\Access\PermissionGateway;
|
||||
|
||||
class UserPermissionGateway
|
||||
{
|
||||
public function __construct(private readonly PermissionGateway $permissionGateway)
|
||||
{
|
||||
}
|
||||
|
||||
public function clearUserCache(int $userId): void
|
||||
{
|
||||
$this->permissionGateway->clearUserCache($userId);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Service\User;
|
||||
|
||||
use MintyPHP\Service\Tenant\TenantScopeService;
|
||||
|
||||
class UserScopeGateway
|
||||
{
|
||||
public function __construct(
|
||||
private readonly TenantScopeService $tenantScopeService
|
||||
) {
|
||||
}
|
||||
|
||||
public function hasGlobalAccess(int $userId): bool
|
||||
{
|
||||
return $this->tenantScopeService->hasGlobalAccess($userId);
|
||||
}
|
||||
|
||||
public function canAccess(string $resourceType, int $resourceId, int $userId): bool
|
||||
{
|
||||
return $this->tenantScopeService->canAccess($resourceType, $resourceId, $userId);
|
||||
}
|
||||
|
||||
public function getUserTenantIds(int $userId): array
|
||||
{
|
||||
return $this->tenantScopeService->getUserTenantIds($userId);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class UserServicesFactory
|
||||
$this->createUserAssignmentService(),
|
||||
$this->createUserPasswordService(),
|
||||
$this->createUserSettingsGateway(),
|
||||
$this->createUserScopeGateway(),
|
||||
$this->userGatewayFactory->getTenantScopeService(),
|
||||
$this->createUserDirectoryGateway(),
|
||||
$this->auditServicesFactory->createSystemAuditService(),
|
||||
$this->databaseSessionRepository
|
||||
@@ -58,7 +58,7 @@ class UserServicesFactory
|
||||
$this->createUserRoleRepository(),
|
||||
$this->createUserDepartmentRepository(),
|
||||
$this->createUserDirectoryGateway(),
|
||||
$this->createUserPermissionGateway(),
|
||||
$this->userGatewayFactory->createPermissionService(),
|
||||
$this->databaseSessionRepository
|
||||
);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class UserServicesFactory
|
||||
$this->createUserReadRepository(),
|
||||
$this->createUserWriteRepository(),
|
||||
$this->createUserTenantRepository(),
|
||||
$this->createUserScopeGateway(),
|
||||
$this->userGatewayFactory->getTenantScopeService(),
|
||||
$this->createUserDirectoryGateway()
|
||||
);
|
||||
}
|
||||
@@ -139,21 +139,11 @@ class UserServicesFactory
|
||||
return $this->userGatewayFactory->createUserSettingsGateway();
|
||||
}
|
||||
|
||||
public function createUserScopeGateway(): UserScopeGateway
|
||||
{
|
||||
return $this->userGatewayFactory->createUserScopeGateway();
|
||||
}
|
||||
|
||||
public function createUserDirectoryGateway(): UserDirectoryGateway
|
||||
{
|
||||
return $this->userGatewayFactory->createUserDirectoryGateway();
|
||||
}
|
||||
|
||||
public function createUserPermissionGateway(): UserPermissionGateway
|
||||
{
|
||||
return $this->userGatewayFactory->createUserPermissionGateway();
|
||||
}
|
||||
|
||||
public function createUserLifecycleService(): UserLifecycleService
|
||||
{
|
||||
return $this->userLifecycleService ??= new UserLifecycleService(
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace MintyPHP\Service\User;
|
||||
use MintyPHP\Repository\Tenant\UserTenantRepositoryInterface;
|
||||
use MintyPHP\Repository\User\UserReadRepositoryInterface;
|
||||
use MintyPHP\Repository\User\UserWriteRepositoryInterface;
|
||||
use MintyPHP\Service\Tenant\TenantScopeService;
|
||||
|
||||
class UserTenantContextService
|
||||
{
|
||||
@@ -12,7 +13,7 @@ class UserTenantContextService
|
||||
private readonly UserReadRepositoryInterface $userReadRepository,
|
||||
private readonly UserWriteRepositoryInterface $userWriteRepository,
|
||||
private readonly UserTenantRepositoryInterface $userTenantRepository,
|
||||
private readonly UserScopeGateway $scopeGateway,
|
||||
private readonly TenantScopeService $scopeGateway,
|
||||
private readonly UserDirectoryGateway $directoryGateway
|
||||
) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user