class UserManagementService (View source)

Domain service for user management operations

This service encapsulates business logic related to user operations and coordinates between repositories and other domain services.

Constants

ERR_USERNAME_REQUIRED

ERR_INVALID_LDAP

ERR_INVALID_AUTH_METHOD

ERR_ZONE_LIMIT

ERR_PASSWORD_REQUIRED

ERR_PASSWORD_POLICY

ERR_FIELD_LENGTH

ERR_USERNAME_EXISTS

ERR_EMAIL_EXISTS

ERR_INVALID_EMAIL

ERR_NO_TEMPLATE

ERR_TEMPLATE_NOT_FOUND

ERR_NOT_FOUND

ERR_PASSWORD_FORBIDDEN

ERR_LAST_ADMIN

ERR_LAST_ADMIN_DEMOTE

ERR_TRANSFER_TARGET

ERR_ZONE_DELETE_FORBIDDEN

ERR_ZONE_META_FORBIDDEN

ERR_ZONE_WRITE

ERR_WRITE

Methods

__construct(UserRepositoryInterface $userRepository, PermissionService $permissionService, UserProfileAssembler $profileAssembler, PasswordHasherInterface $authService, PasswordPolicyInterface $passwordPolicy, bool $ldapEnabled, DomainManagerInterface $domainManager, ZoneManagementService $zones, bool $remoteUserEnabled = false, ZoneOwnershipLimit|null $ownershipLimit = null, bool $protectLastAdminOnEdit = false, LoggerInterface|null $logger = null, TransactionInterface|null $transaction = null)

No description

array|null
getUserById(int $userId)

Get a user by ID with complete information including permissions

array
getUsersList(Pagination $pagination)

Get paginated list of users with their details and permissions

array
getUsersPage(Pagination $pagination, string|null $search = null, array $sort = [])

Get one page of users with their details and permissions, without counting them

int
countUsers(string|null $search = null)

Count all users, or those matching the search

bool
userExists(int $userId)

Check if a user exists by ID

array|null
getUserByUsername(string $username)

Get user details by username (similar to list format)

array|null
getUserByEmail(string $email)

Get user details by email (similar to list format)

array
createUser(CreateUserCommand $command)

Create a new user

array
updateUser(int $userId, UpdateUserCommand $command)

Update an existing user

array
deleteUser(int $userId, int|null $transferToUserId = null, int|null $actingUserId = null)

Delete a user and transfer their zones to another user

array
deleteUserWithZoneDecisions(int $actingUserId, int $userId, array $zoneDecisions)

Delete a user, deciding zone by zone what happens to what they own: each decision names a zone id and a target, 'delete' or 'new_owner' (with 'newowner'); any other target leaves the zone as it is. Every decision is checked against the acting user's zone rights before any zone is touched, so a later refusal cannot leave the earlier ones half applied. That the acting user may delete this user at all is the caller's check.

array
assignPermissionTemplate(int $userId, int $permTemplId)

Assign permission template to a user

Details

__construct(UserRepositoryInterface $userRepository, PermissionService $permissionService, UserProfileAssembler $profileAssembler, PasswordHasherInterface $authService, PasswordPolicyInterface $passwordPolicy, bool $ldapEnabled, DomainManagerInterface $domainManager, ZoneManagementService $zones, bool $remoteUserEnabled = false, ZoneOwnershipLimit|null $ownershipLimit = null, bool $protectLastAdminOnEdit = false, LoggerInterface|null $logger = null, TransactionInterface|null $transaction = null)

No description

Parameters

UserRepositoryInterface $userRepository
PermissionService $permissionService
UserProfileAssembler $profileAssembler
PasswordHasherInterface $authService
PasswordPolicyInterface $passwordPolicy
bool $ldapEnabled
DomainManagerInterface $domainManager
ZoneManagementService $zones
bool $remoteUserEnabled
ZoneOwnershipLimit|null $ownershipLimit
bool $protectLastAdminOnEdit
LoggerInterface|null $logger
TransactionInterface|null $transaction

array|null getUserById(int $userId)

Get a user by ID with complete information including permissions

Parameters

int $userId

User ID

Return Value

array|null

User data with permissions or null if not found

array getUsersList(Pagination $pagination)

Get paginated list of users with their details and permissions

Parameters

Pagination $pagination

Pagination parameters

Return Value

array

Array with 'data' and 'total_count' keys

array getUsersPage(Pagination $pagination, string|null $search = null, array $sort = [])

Get one page of users with their details and permissions, without counting them

Parameters

Pagination $pagination
string|null $search

Case-insensitive substring filter on username, full name, email or description

array $sort

Sort keys (id, username, fullname or email); empty sorts by id

Return Value

array

int countUsers(string|null $search = null)

Count all users, or those matching the search

Parameters

string|null $search

Case-insensitive substring filter on username, full name, email or description

Return Value

int

bool userExists(int $userId)

Check if a user exists by ID

Parameters

int $userId

User ID

Return Value

bool

True if user exists, false otherwise

array|null getUserByUsername(string $username)

Get user details by username (similar to list format)

Parameters

string $username

Username to search for

Return Value

array|null

User data in list format or null if not found

array|null getUserByEmail(string $email)

Get user details by email (similar to list format)

Parameters

string $email

Email to search for

Return Value

array|null

User data in list format or null if not found

array createUser(CreateUserCommand $command)

Create a new user

Parameters

CreateUserCommand $command

Return Value

array

Result with success status, message, and user ID if successful

array updateUser(int $userId, UpdateUserCommand $command)

Update an existing user

Parameters

int $userId

User ID to update

UpdateUserCommand $command

Return Value

array

Result with success status and message

array deleteUser(int $userId, int|null $transferToUserId = null, int|null $actingUserId = null)

Delete a user and transfer their zones to another user

Parameters

int $userId

User ID to delete

int|null $transferToUserId

User ID to transfer zones to (required if user has zones)

int|null $actingUserId

When given, the transfer needs meta-edit rights on every zone, as the web form requires, and this user inherits the deleted user's templates shared with groups

Return Value

array

Result with success status and message

array deleteUserWithZoneDecisions(int $actingUserId, int $userId, array $zoneDecisions)

Delete a user, deciding zone by zone what happens to what they own: each decision names a zone id and a target, 'delete' or 'new_owner' (with 'newowner'); any other target leaves the zone as it is. Every decision is checked against the acting user's zone rights before any zone is touched, so a later refusal cannot leave the earlier ones half applied. That the acting user may delete this user at all is the caller's check.

Parameters

int $actingUserId
int $userId
array $zoneDecisions

Entries that are not a decision (no zid, unknown target) are ignored

Return Value

array

array assignPermissionTemplate(int $userId, int $permTemplId)

Assign permission template to a user

Parameters

int $userId

User ID

int $permTemplId

Permission template ID

Return Value

array

Result with success status and message