feat: complete jobcard management workflows and UI
This commit is contained in:
@@ -30,6 +30,18 @@ final class UserAdminService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** Controller-friendly user-create DTO. */
|
||||
public function validateForCreate(array $input, array $existingUsers = []): array
|
||||
{
|
||||
$result = ($this->users ?? new UserRecord())->validateForCreate($input);
|
||||
$email = $result['email'] ?? '';
|
||||
if (is_string($email) && $email !== '' && $this->hasDuplicateEmail($email, $existingUsers, 0)) {
|
||||
$result['errors']['email'] = 'Email address is already in use.';
|
||||
$result['valid'] = false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function validateForEdit(int $id, array $input, array $existingUsers = []): array
|
||||
{
|
||||
@@ -40,7 +52,7 @@ final class UserAdminService
|
||||
|
||||
$result = ($this->users ?? new UserRecord())->validate($input);
|
||||
$existing = $existingUsers[array_search($id, array_map(static fn($row) => is_array($row) ? (int)($row['id'] ?? 0) : 0, $existingUsers), true)] ?? [];
|
||||
if ($this->isProtectedAdministrator($existing) && array_key_exists('role_id', $input) && (int)$input['role_id'] !== (int)($existing['role_id'] ?? 1)) $result['errors']['role_id'] = 'The protected Administrator account cannot be reassigned.';
|
||||
if ($this->isProtectedAdministrator(['id' => $id, ...$existing]) && array_key_exists('role_id', $input) && (int)$input['role_id'] !== 1) $result['errors']['role_id'] = 'The protected Administrator account cannot be reassigned.';
|
||||
$email = $result['email'] ?? '';
|
||||
if (is_string($email) && $email !== '' && $this->hasDuplicateEmail($email, $existingUsers, $id)) {
|
||||
$result['errors']['email'] = 'Email address is already in use.';
|
||||
@@ -52,6 +64,12 @@ final class UserAdminService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** Alias matching controller command terminology. */
|
||||
public function validateEdit(int $id, array $input, array $existingUsers = []): array
|
||||
{
|
||||
return $this->validateForEdit($id, $input, $existingUsers);
|
||||
}
|
||||
|
||||
/** @return array{valid: bool, id: int, is_active: bool, errors: array<string, string>} */
|
||||
public function validateDeactivate(array $user): array
|
||||
{
|
||||
@@ -121,6 +139,7 @@ final class UserAdminService
|
||||
|
||||
public function isProtectedAdministrator(array $user): bool
|
||||
{
|
||||
if (isset($user['id']) && (int)$user['id'] === 1) return true;
|
||||
if (isset($user['role_id']) && (int)$user['role_id'] === 1) return true;
|
||||
$role = $user['role_name'] ?? $user['role'] ?? null;
|
||||
return is_scalar($role) && strtolower(trim((string) $role)) === 'administrator';
|
||||
|
||||
Reference in New Issue
Block a user