major update

This commit is contained in:
2026-03-04 15:56:58 +01:00
parent 16759a2732
commit 8f4dd5840d
478 changed files with 24313 additions and 8201 deletions

View File

@@ -6,6 +6,7 @@ use MintyPHP\I18n;
use MintyPHP\Repository\User\UserListQueryRepository;
use MintyPHP\Repository\User\UserReadRepository;
use MintyPHP\Repository\User\UserWriteRepository;
use MintyPHP\Service\Audit\SystemAuditService;
class UserAccountService
{
@@ -16,7 +17,9 @@ class UserAccountService
private readonly UserAssignmentService $userAssignmentService,
private readonly UserPasswordService $userPasswordService,
private readonly UserSettingsGateway $settingsGateway,
private readonly UserScopeGateway $scopeGateway
private readonly UserScopeGateway $scopeGateway,
private readonly UserDirectoryGateway $directoryGateway,
private readonly SystemAuditService $systemAuditService
) {
}
@@ -84,6 +87,13 @@ class UserAccountService
return ['ok' => false, 'status' => 500, 'error' => 'delete_failed'];
}
$this->systemAuditService->record('admin.users.delete', 'success', [
'actor_user_id' => $currentUserId > 0 ? $currentUserId : null,
'target_type' => 'user',
'target_id' => $userId,
'target_uuid' => (string) ($user['uuid'] ?? ''),
]);
return ['ok' => true, 'user' => $user];
}
@@ -117,6 +127,16 @@ class UserAccountService
return ['ok' => false, 'error' => 'delete_failed'];
}
$this->systemAuditService->record('admin.users.bulk_update', 'success', [
'actor_user_id' => $currentUserId > 0 ? $currentUserId : null,
'target_type' => 'user',
'metadata' => [
'action' => 'delete',
'count' => count($uuids),
'target_uuids' => $uuids,
],
]);
return ['ok' => true, 'count' => count($uuids)];
}
@@ -218,6 +238,18 @@ class UserAccountService
$this->userAssignmentService->syncDepartments($userId, $departmentIds);
}
$this->systemAuditService->record('admin.users.create', 'success', [
'actor_user_id' => $currentUserId > 0 ? $currentUserId : null,
'target_type' => 'user',
'target_id' => $userId > 0 ? $userId : null,
'target_uuid' => is_string($uuid) ? $uuid : '',
'metadata' => [
'assigned_tenant_ids' => $tenantIds,
'assigned_role_ids' => $roleIds,
'assigned_department_ids' => $departmentIds,
],
]);
return ['ok' => true, 'form' => $form, 'uuid' => $uuid];
}
@@ -320,6 +352,25 @@ class UserAccountService
$this->userAssignmentService->bumpAuthzVersion($userId);
}
$this->systemAuditService->record('admin.users.update', 'success', [
'actor_user_id' => $currentUserId > 0 ? $currentUserId : null,
'target_type' => 'user',
'target_id' => $userId,
'target_uuid' => (string) ($existing['uuid'] ?? ''),
'before' => [
'active' => $existing['active'] ?? null,
'locale' => $existing['locale'] ?? null,
'theme' => $existing['theme'] ?? null,
'primary_tenant_id' => $existing['primary_tenant_id'] ?? null,
],
'after' => [
'active' => $form['active'],
'locale' => $form['locale'],
'theme' => $form['theme'],
'primary_tenant_id' => $form['primary_tenant_id'] ?? ($existing['primary_tenant_id'] ?? null),
],
]);
return ['ok' => true, 'form' => $form];
}
@@ -352,6 +403,15 @@ class UserAccountService
$this->userAssignmentService->bumpAuthzVersion($userId);
$this->systemAuditService->record($active ? 'admin.users.activate' : 'admin.users.deactivate', 'success', [
'actor_user_id' => $currentUserId > 0 ? $currentUserId : null,
'target_type' => 'user',
'target_id' => $userId,
'target_uuid' => (string) ($user['uuid'] ?? ''),
'before' => ['active' => $user['active'] ?? null],
'after' => ['active' => $active ? 1 : 0],
]);
return ['ok' => true, 'user' => $user];
}
@@ -386,6 +446,16 @@ class UserAccountService
$this->userWriteRepository->bumpAuthzVersionByUserIds($userIds);
}
$this->systemAuditService->record('admin.users.bulk_update', 'success', [
'actor_user_id' => $currentUserId > 0 ? $currentUserId : null,
'target_type' => 'user',
'metadata' => [
'action' => $active ? 'activate' : 'deactivate',
'count' => count($uuids),
'target_uuids' => $uuids,
],
]);
return ['ok' => true, 'count' => count($uuids)];
}
@@ -490,8 +560,7 @@ class UserAccountService
if (array_key_exists('current_tenant_uuid', $input)) {
$tenantUuid = trim((string) ($input['current_tenant_uuid'] ?? ''));
if ($tenantUuid !== '') {
$tenantService = directoryServicesFactory()->createTenantService();
$tenant = $tenantService->findByUuid($tenantUuid);
$tenant = $this->directoryGateway->findTenantByUuid($tenantUuid);
if (!$tenant || !isset($tenant['id'])) {
$errors[] = t('Tenant not found');
} else {