instances added god may help
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Http\ApiAuth;
|
||||
use MintyPHP\Http\ApiBootstrap;
|
||||
use MintyPHP\Http\ApiResponse;
|
||||
use MintyPHP\Http\ApiAuth;
|
||||
use MintyPHP\Service\User\UserService;
|
||||
use MintyPHP\Service\Access\PermissionService;
|
||||
use MintyPHP\Service\Tenant\TenantService;
|
||||
use MintyPHP\Service\User\UserServicesFactory;
|
||||
|
||||
ApiBootstrap::init();
|
||||
$userServicesFactory = new UserServicesFactory();
|
||||
$userAccountService = $userServicesFactory->createUserAccountService();
|
||||
|
||||
$method = strtoupper($_SERVER['REQUEST_METHOD'] ?? 'GET');
|
||||
|
||||
@@ -34,14 +35,14 @@ if ($method === 'GET') {
|
||||
];
|
||||
$scopedTenantId = ApiAuth::scopedTenantId();
|
||||
if ($scopedTenantId) {
|
||||
$tenant = TenantService::findById($scopedTenantId);
|
||||
$tenant = directoryServicesFactory()->createTenantService()->findById($scopedTenantId);
|
||||
$tenantUuid = trim((string) ($tenant['uuid'] ?? ''));
|
||||
if ($tenantUuid === '') {
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
$options['tenant'] = $tenantUuid;
|
||||
}
|
||||
$result = UserService::listPaged($options);
|
||||
$result = $userAccountService->listPaged($options);
|
||||
|
||||
$rows = [];
|
||||
foreach ($result['rows'] as $row) {
|
||||
@@ -96,7 +97,7 @@ if ($method === 'POST') {
|
||||
$input['tenant_ids'] = [$scopedTenantId];
|
||||
$input['primary_tenant_id'] = $scopedTenantId;
|
||||
}
|
||||
$result = UserService::createFromAdmin($input, ApiAuth::userId());
|
||||
$result = $userAccountService->createFromAdmin($input, ApiAuth::userId());
|
||||
ApiResponse::fromServiceResult($result, 201);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Http\ApiAuth;
|
||||
use MintyPHP\Http\ApiBootstrap;
|
||||
use MintyPHP\Http\ApiResponse;
|
||||
use MintyPHP\Http\ApiAuth;
|
||||
use MintyPHP\Repository\Access\RolePermissionRepository;
|
||||
use MintyPHP\Repository\Access\UserRoleRepository;
|
||||
use MintyPHP\Service\CustomField\UserCustomFieldValueService;
|
||||
use MintyPHP\Service\User\UserService;
|
||||
use MintyPHP\Service\Access\AccessServicesFactory;
|
||||
use MintyPHP\Service\Access\PermissionService;
|
||||
use MintyPHP\Service\CustomField\UserCustomFieldValueService;
|
||||
use MintyPHP\Service\User\UserServicesFactory;
|
||||
|
||||
ApiBootstrap::init();
|
||||
$userServicesFactory = new UserServicesFactory();
|
||||
$userAccountService = $userServicesFactory->createUserAccountService();
|
||||
$userAssignmentService = $userServicesFactory->createUserAssignmentService();
|
||||
$userRoleRepository = $userServicesFactory->createUserRoleRepository();
|
||||
$rolePermissionRepository = (new AccessServicesFactory())->createRolePermissionRepository();
|
||||
|
||||
$uuid = trim((string) ($id ?? ''));
|
||||
if ($uuid === '') {
|
||||
@@ -21,17 +25,17 @@ $method = strtoupper($_SERVER['REQUEST_METHOD'] ?? 'GET');
|
||||
if ($method === 'GET') {
|
||||
ApiResponse::requirePermission(PermissionService::USERS_VIEW);
|
||||
|
||||
$user = UserService::findByUuid($uuid);
|
||||
$user = $userAccountService->findByUuid($uuid);
|
||||
if (!$user) {
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$userId = (int) ($user['id'] ?? 0);
|
||||
ApiAuth::requireResourceAccess('users', $userId);
|
||||
$assignments = UserService::buildAssignmentsForUser($userId);
|
||||
$assignments = $userAssignmentService->buildAssignmentsForUser($userId);
|
||||
$primaryTenantId = (int) ($user['primary_tenant_id'] ?? 0);
|
||||
$primaryTenant = UserService::findTenantSummaryInAssignments($assignments, $primaryTenantId);
|
||||
$publicAssignments = UserService::mapAssignmentsToPublic($assignments);
|
||||
$primaryTenant = $userAssignmentService->findTenantSummaryInAssignments($assignments, $primaryTenantId);
|
||||
$publicAssignments = $userAssignmentService->mapAssignmentsToPublic($assignments);
|
||||
$publicCustomFields = UserCustomFieldValueService::buildPublicValuesByTenant(
|
||||
$userId,
|
||||
$assignments['tenants'] ?? [],
|
||||
@@ -39,8 +43,8 @@ if ($method === 'GET') {
|
||||
);
|
||||
$publicPermissions = [];
|
||||
if (ApiAuth::hasPermission(PermissionService::PERMISSIONS_VIEW)) {
|
||||
$roleIds = UserRoleRepository::listRoleIdsByUserId($userId);
|
||||
$publicPermissions = RolePermissionRepository::listPermissionKeysByRoleIds($roleIds);
|
||||
$roleIds = $userRoleRepository->listRoleIdsByUserId($userId);
|
||||
$publicPermissions = $rolePermissionRepository->listPermissionKeysByRoleIds($roleIds);
|
||||
}
|
||||
|
||||
ApiResponse::success([
|
||||
@@ -72,7 +76,7 @@ if ($method === 'GET') {
|
||||
if ($method === 'PUT' || $method === 'PATCH') {
|
||||
ApiResponse::requirePermission(PermissionService::USERS_UPDATE);
|
||||
|
||||
$user = UserService::findByUuid($uuid);
|
||||
$user = $userAccountService->findByUuid($uuid);
|
||||
if (!$user) {
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
@@ -103,14 +107,14 @@ if ($method === 'PUT' || $method === 'PATCH') {
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = UserService::updateFromAdmin($userId, $input, ApiAuth::userId());
|
||||
$result = $userAccountService->updateFromAdmin($userId, $input, ApiAuth::userId());
|
||||
ApiResponse::fromServiceResult($result);
|
||||
}
|
||||
|
||||
if ($method === 'DELETE') {
|
||||
ApiResponse::requirePermission(PermissionService::USERS_DELETE);
|
||||
|
||||
$user = UserService::findByUuid($uuid);
|
||||
$user = $userAccountService->findByUuid($uuid);
|
||||
if (!$user) {
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
@@ -118,7 +122,7 @@ if ($method === 'DELETE') {
|
||||
$userId = (int) ($user['id'] ?? 0);
|
||||
ApiAuth::requireResourceAccess('users', $userId);
|
||||
|
||||
$result = UserService::deleteByUuid($uuid, ApiAuth::userId());
|
||||
$result = $userAccountService->deleteByUuid($uuid, ApiAuth::userId());
|
||||
ApiResponse::fromServiceResult($result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user