/** * Create new User Group inside existing parent User Group. * * @param string $name User Group name * @param \eZ\Publish\API\Repository\Values\User\UserGroup $parentGroup (optional) parent user group, defaults to UserGroup "/Users" * * @return \eZ\Publish\API\Repository\Values\User\UserGroup */ public function createUserGroup($name, $parentGroup = null) { if (!$parentGroup) { $parentGroup = $this->userService->loadUserGroup(self::USERGROUP_ROOT_CONTENT_ID); } $userGroupCreateStruct = $this->userService->newUserGroupCreateStruct('eng-GB'); $userGroupCreateStruct->setField('name', $name); return $this->userService->createUserGroup($userGroupCreateStruct, $parentGroup); }
/** * Create a new user group under the given parent * To create a top level group use /user/groups/1/5/subgroups * * @param $groupPath * * @throws \eZ\Publish\Core\REST\Server\Exceptions\BadRequestException * @return \eZ\Publish\Core\REST\Server\Values\CreatedUserGroup */ public function createUserGroup($groupPath) { $userGroupLocation = $this->locationService->loadLocation($this->extractLocationIdFromPath($groupPath)); $createdUserGroup = $this->userService->createUserGroup($this->inputDispatcher->parse(new Message(array('Content-Type' => $this->request->headers->get('Content-Type')), $this->request->getContent())), $this->userService->loadUserGroup($userGroupLocation->contentId)); $createdContentInfo = $createdUserGroup->getVersionInfo()->getContentInfo(); $createdLocation = $this->locationService->loadLocation($createdContentInfo->mainLocationId); $contentType = $this->contentTypeService->loadContentType($createdContentInfo->contentTypeId); return new Values\CreatedUserGroup(array('userGroup' => new Values\RestUserGroup($createdUserGroup, $contentType, $createdContentInfo, $createdLocation, $this->contentService->loadRelations($createdUserGroup->getVersionInfo())))); }
/** * @inheritdoc */ public function visit(TreeNodeInterface $node, &$data) { if (!is_array($data)) { return null; } $struct = $this->userService->newUserGroupCreateStruct(''); $this->fillValueObject($struct, $data, ['content_type']); $defaultUserGroup = $this->userService->loadUserGroup(self::DEFAULT_USER_GROUP_ID); // @todo: process parent user group $userGroup = $this->userService->createUserGroup($struct, $defaultUserGroup); $this->saveUserGroupDataToCollection($node, $userGroup); if (isset($data['roles'])) { foreach ($data['roles'] as $roleId) { $role = $this->repository->getRoleService()->loadRoleByIdentifier($roleId); // @doc: parameter RoleLimitation is not supported. // Not possible to assign role to user or group with limitation $this->repository->getRoleService()->assignRoleToUserGroup($role, $userGroup); } } return $userGroup; }
/** * Creates a new user group using the data provided in the ContentCreateStruct parameter * * In 4.x in the content type parameter in the profile is ignored * - the content type is determined via configuration and can be set to null. * The returned version is published. * * @param \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct $userGroupCreateStruct a structure for setting all necessary data to create this user group * @param \eZ\Publish\API\Repository\Values\User\UserGroup $parentGroup * * @return \eZ\Publish\API\Repository\Values\User\UserGroup * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a user group * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the input structure has invalid data * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userGroupCreateStruct is not valid * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or set to an empty value */ public function createUserGroup(UserGroupCreateStruct $userGroupCreateStruct, UserGroup $parentGroup) { $returnValue = $this->service->createUserGroup($userGroupCreateStruct, $parentGroup); $this->signalDispatcher->emit(new CreateUserGroupSignal(array('userGroupId' => $returnValue->id))); return $returnValue; }