/** * Make sure a User with name $username does not exist (in parent group). * * @param string $username User name * @param string $parentGroupName (optional) name of the parent group to check */ public function ensureUserDoesntExist($username, $parentGroupName = null) { $user = null; if ($parentGroupName) { // find matching Parent Group name $parentSearchHits = $this->searchUserGroups($parentGroupName, self::USERGROUP_ROOT_LOCATION); if (!empty($parentSearchHits)) { foreach ($parentSearchHits as $parentGroupFound) { $groupId = $parentGroupFound->valueObject->contentInfo->id; //Search for already existing matching Child user $user = $this->searchUserByLogin($username, $groupId); if ($user) { break; } } } } else { try { $user = $this->userService->loadUserByLogin($username); } catch (ApiExceptions\NotFoundException $e) { // nothing to do } } if ($user) { try { $this->userService->deleteUser($user); } catch (ApiExceptions\NotFoundException $e) { // nothing to do } } }
/** * Given user is deleted * * @param $userId * * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException * @return \eZ\Publish\Core\REST\Server\Values\NoContent */ public function deleteUser($userId) { $user = $this->userService->loadUser($userId); if ($user->id == $this->repository->getCurrentUser()->id) { throw new Exceptions\ForbiddenException("Currently authenticated user cannot be deleted"); } $this->userService->deleteUser($user); return new Values\NoContent(); }
/** * This method deletes a user * * @param \eZ\Publish\API\Repository\Values\User\User $user * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete the user */ public function deleteUser(User $user) { $returnValue = $this->service->deleteUser($user); $this->signalDispatcher->emit(new DeleteUserSignal(array('userId' => $user->id))); return $returnValue; }