instances added god may help
This commit is contained in:
@@ -1,40 +1,43 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Buffer;
|
||||
use MintyPHP\Support\Flash;
|
||||
use MintyPHP\Support\Guard;
|
||||
use MintyPHP\I18n;
|
||||
use MintyPHP\Router;
|
||||
use MintyPHP\Service\Access\PermissionService;
|
||||
use MintyPHP\Service\User\UserService;
|
||||
use MintyPHP\Service\Tenant\TenantScopeService;
|
||||
use MintyPHP\Service\Tenant\TenantService;
|
||||
use MintyPHP\Service\Access\RoleService;
|
||||
use MintyPHP\Service\Org\DepartmentService;
|
||||
use MintyPHP\Service\CustomField\UserCustomFieldValueService;
|
||||
use MintyPHP\Service\Settings\SettingService;
|
||||
use MintyPHP\Service\Settings\SettingServicesFactory;
|
||||
use MintyPHP\Service\User\UserServicesFactory;
|
||||
use MintyPHP\Support\Flash;
|
||||
use MintyPHP\Support\Guard;
|
||||
|
||||
Guard::requirePermissionOrForbidden(PermissionService::USERS_CREATE);
|
||||
$userServicesFactory = new UserServicesFactory();
|
||||
$userAccountService = $userServicesFactory->createUserAccountService();
|
||||
$userAssignmentService = $userServicesFactory->createUserAssignmentService();
|
||||
$userPasswordPolicyService = $userServicesFactory->createUserPasswordPolicyService();
|
||||
$passwordMinLength = $userPasswordPolicyService->minLength();
|
||||
$passwordHints = $userPasswordPolicyService->hints();
|
||||
$settingGateway = (new SettingServicesFactory())->createSettingGateway();
|
||||
|
||||
$currentUserId = (int) ($_SESSION['user']['id'] ?? 0);
|
||||
$allowedTenantIds = TenantScopeService::getUserTenantIds($currentUserId);
|
||||
$allowedTenantIds = directoryServicesFactory()->createDirectoryScopeGateway()->getUserTenantIds($currentUserId);
|
||||
|
||||
$tenants = TenantService::list();
|
||||
$tenants = directoryServicesFactory()->createTenantService()->list();
|
||||
if ($allowedTenantIds) {
|
||||
$tenants = array_values(array_filter($tenants, static function (array $tenant) use ($allowedTenantIds): bool {
|
||||
$tenantId = (int) ($tenant['id'] ?? 0);
|
||||
return $tenantId > 0 && in_array($tenantId, $allowedTenantIds, true);
|
||||
}));
|
||||
} elseif (TenantScopeService::isStrict()) {
|
||||
} elseif (directoryServicesFactory()->createDirectoryScopeGateway()->isStrict()) {
|
||||
$tenants = [];
|
||||
}
|
||||
$roles = RoleService::listActive();
|
||||
$roles = directoryServicesFactory()->createRoleService()->listActive();
|
||||
$selectedTenantIds = [];
|
||||
$selectedRoleIds = [];
|
||||
$selectedDepartmentIds = [];
|
||||
$departmentOptionsByTenant = [];
|
||||
$canEditCustomFieldValues = PermissionService::userHas($currentUserId, PermissionService::CUSTOM_FIELDS_EDIT_VALUES)
|
||||
&& PermissionService::userHas($currentUserId, PermissionService::USERS_UPDATE_ASSIGNMENTS);
|
||||
$canEditCustomFieldValues = permissionGateway()->userHas($currentUserId, PermissionService::CUSTOM_FIELDS_EDIT_VALUES)
|
||||
&& permissionGateway()->userHas($currentUserId, PermissionService::USERS_UPDATE_ASSIGNMENTS);
|
||||
$customFieldDefinitionsByTenant = [];
|
||||
$customFieldValueMap = [];
|
||||
$customFieldPostedValues = [
|
||||
@@ -65,20 +68,20 @@ $form = [
|
||||
|
||||
if (isset($_POST['email'])) {
|
||||
$input = $_POST;
|
||||
$tenantIds = UserService::normalizeIdInput($input['tenant_ids'] ?? []);
|
||||
$tenantIds = $userAssignmentService->normalizeIdInput($input['tenant_ids'] ?? []);
|
||||
if ($allowedTenantIds) {
|
||||
$tenantIds = array_values(array_intersect($tenantIds, $allowedTenantIds));
|
||||
} elseif (TenantScopeService::isStrict()) {
|
||||
} elseif (directoryServicesFactory()->createDirectoryScopeGateway()->isStrict()) {
|
||||
$tenantIds = [];
|
||||
}
|
||||
$defaultTenantId = SettingService::getDefaultTenantId();
|
||||
if (TenantScopeService::isStrict() && !$tenantIds && !$defaultTenantId) {
|
||||
$defaultTenantId = $settingGateway->getDefaultTenantId();
|
||||
if (directoryServicesFactory()->createDirectoryScopeGateway()->isStrict() && !$tenantIds && !$defaultTenantId) {
|
||||
$errors[] = t('Please select at least one tenant');
|
||||
}
|
||||
$selectedTenantIds = $tenantIds;
|
||||
$selectedRoleIds = UserService::normalizeIdInput($input['role_ids'] ?? []);
|
||||
$selectedDepartmentIds = UserService::normalizeIdInput($input['department_ids'] ?? []);
|
||||
$departmentOptionsByTenant = DepartmentService::groupActiveByTenantIds($selectedTenantIds);
|
||||
$selectedRoleIds = $userAssignmentService->normalizeIdInput($input['role_ids'] ?? []);
|
||||
$selectedDepartmentIds = $userAssignmentService->normalizeIdInput($input['department_ids'] ?? []);
|
||||
$departmentOptionsByTenant = directoryServicesFactory()->createDepartmentService()->groupActiveByTenantIds($selectedTenantIds);
|
||||
$customFieldDefinitionsByTenant = UserCustomFieldValueService::buildDefinitionsByTenant($selectedTenantIds);
|
||||
$customFieldPostedValues = [
|
||||
'custom_field_values' => is_array($_POST['custom_field_values'] ?? null) ? $_POST['custom_field_values'] : [],
|
||||
@@ -109,7 +112,7 @@ if (isset($_POST['email'])) {
|
||||
$input['department_ids'] = $selectedDepartmentIds;
|
||||
$result = ['ok' => false];
|
||||
if (!$errors) {
|
||||
$result = UserService::createFromAdmin($input, $currentUserId);
|
||||
$result = $userAccountService->createFromAdmin($input, $currentUserId);
|
||||
$form = $result['form'] ?? $form;
|
||||
$errors = array_merge($errors, $result['errors'] ?? []);
|
||||
}
|
||||
@@ -117,7 +120,7 @@ if (isset($_POST['email'])) {
|
||||
if (($result['ok'] ?? false) && !$errors) {
|
||||
$createdUuid = (string) ($result['uuid'] ?? '');
|
||||
if ($canEditCustomFieldValues && $createdUuid !== '') {
|
||||
$createdUser = UserService::findByUuid($createdUuid);
|
||||
$createdUser = $userAccountService->findByUuid($createdUuid);
|
||||
$createdUserId = (int) ($createdUser['id'] ?? 0);
|
||||
if ($createdUserId > 0) {
|
||||
$customFieldSyncResult = UserCustomFieldValueService::syncForUser(
|
||||
@@ -157,7 +160,7 @@ if (isset($_POST['email'])) {
|
||||
}
|
||||
|
||||
if (!$departmentOptionsByTenant && $selectedTenantIds) {
|
||||
$departmentOptionsByTenant = DepartmentService::groupActiveByTenantIds($selectedTenantIds);
|
||||
$departmentOptionsByTenant = directoryServicesFactory()->createDepartmentService()->groupActiveByTenantIds($selectedTenantIds);
|
||||
}
|
||||
if (!$customFieldDefinitionsByTenant && $selectedTenantIds) {
|
||||
$customFieldDefinitionsByTenant = UserCustomFieldValueService::buildDefinitionsByTenant($selectedTenantIds);
|
||||
|
||||
Reference in New Issue
Block a user