Beispiel #1
0
 /**
  * Assigns the user to a user group
  *
  * @param $userId
  *
  * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
  * @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList
  */
 public function assignUserToUserGroup($userId)
 {
     $user = $this->userService->loadUser($userId);
     try {
         $userGroupLocation = $this->locationService->loadLocation($this->extractLocationIdFromPath($this->request->query->get('group')));
     } catch (APINotFoundException $e) {
         throw new Exceptions\ForbiddenException($e->getMessage());
     }
     try {
         $userGroup = $this->userService->loadUserGroup($userGroupLocation->contentId);
     } catch (APINotFoundException $e) {
         throw new Exceptions\ForbiddenException($e->getMessage());
     }
     try {
         $this->userService->assignUserToUserGroup($user, $userGroup);
     } catch (InvalidArgumentException $e) {
         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);
 }
 /**
  * Assigns a new user group to 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 assign the user group to the user
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is already in the given user group
  */
 public function assignUserToUserGroup(User $user, UserGroup $userGroup)
 {
     $returnValue = $this->service->assignUserToUserGroup($user, $userGroup);
     $this->signalDispatcher->emit(new AssignUserToUserGroupSignal(array('userId' => $user->id, 'userGroupId' => $userGroup->id)));
     return $returnValue;
 }