/** * Unassigns the user from a user group * * @param $userId * @param $groupPath * * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException * @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList */ public function unassignUserFromUserGroup($userId, $groupPath) { $user = $this->userService->loadUser($userId); $userGroupLocation = $this->locationService->loadLocation(trim($groupPath, '/')); $userGroup = $this->userService->loadUserGroup($userGroupLocation->contentId); try { $this->userService->unAssignUserFromUserGroup($user, $userGroup); } catch (InvalidArgumentException $e) { // User is not in the group throw new Exceptions\ForbiddenException($e->getMessage()); } $userGroups = $this->userService->loadUserGroupsOfUser($user); $restUserGroups = array(); foreach ($userGroups as $userGroup) { $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo(); $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId); $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId); $restUserGroups[] = new Values\RestUserGroup($userGroup, $contentType, $userGroupContentInfo, $userGroupLocation, $this->contentService->loadRelations($userGroup->getVersionInfo())); } return new Values\UserGroupRefList($restUserGroups, $this->router->generate('ezpublish_rest_loadUserGroupsOfUser', array('userId' => $userId)), $userId); }
/** * Removes a user group from the user * * @param \eZ\Publish\API\Repository\Values\User\User $user * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove the user group from the user * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is not in the given user group */ public function unAssignUserFromUserGroup(User $user, UserGroup $userGroup) { $returnValue = $this->service->unAssignUserFromUserGroup($user, $userGroup); $this->signalDispatcher->emit(new UnAssignUserFromUserGroupSignal(array('userId' => $user->id, 'userGroupId' => $userGroup->id))); return $returnValue; }