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);
 }
 /**
  * Checks if the User with email $email exists.
  *
  * @param string $email User email
  * @param string $parentGroupName User group name to search inside
  *
  * @return bool true if it exists, false if not
  */
 public function checkUserExistenceByEmail($email, $parentGroupName = null)
 {
     $existingUsers = $this->userService->loadUsersByEmail($email);
     if (count($existingUsers) == 0) {
         return false;
     }
     if ($parentGroupName) {
         foreach ($existingUsers as $user) {
             $userGroups = $this->userService->loadUserGroupsOfUser($user);
             foreach ($userGroups as $userGroup) {
                 if ($userGroup->getFieldValue('name') == $parentGroupName) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
 /**
  * Loads the user groups the user belongs to
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed read the user or user group
  *
  * @param \eZ\Publish\API\Repository\Values\User\User $user
  *
  * @return \eZ\Publish\API\Repository\Values\User\UserGroup[]
  */
 public function loadUserGroupsOfUser(User $user)
 {
     return $this->service->loadUserGroupsOfUser($user);
 }
Beispiel #4
0
 /**
  * Loads the user groups the user belongs to.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed read the user or user group
  *
  * @param \eZ\Publish\API\Repository\Values\User\User $user
  * @param int $offset the start offset for paging
  * @param int $limit the number of user groups returned
  *
  * @return \eZ\Publish\API\Repository\Values\User\UserGroup[]
  */
 public function loadUserGroupsOfUser(User $user, $offset = 0, $limit = 25)
 {
     return $this->service->loadUserGroupsOfUser($user, $offset, $limit);
 }