Create a new user group in the given group.

@param $groupPath

@throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException

@return \eZ\Publish\Core\REST\Server\Values\CreatedUser
769642
public function createUser($groupPath, Request $request)
    {
        $userGroupLocation = $this->locationService->loadLocation(
            $this->extractLocationIdFromPath($groupPath)
        );
        $userGroup = $this->userService->loadUserGroup($userGroupLocation->contentId);

        $userCreateStruct = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        try {
            $createdUser = $this->userService->createUser($userCreateStruct, array($userGroup));
        } catch (ApiExceptions\InvalidArgumentException $e) {
            throw new ForbiddenException($e->getMessage());
        }

        $createdContentInfo = $createdUser->getVersionInfo()->getContentInfo();
        $createdLocation = $this->locationService->loadLocation($createdContentInfo->mainLocationId);
        $contentType = $this->contentTypeService->loadContentType($createdContentInfo->contentTypeId);

        return new Values\CreatedUser(
            array(
                'user' => new Values\RestUser(
                    $createdUser,
                    $contentType,
                    $createdContentInfo,
                    $createdLocation,
                    $this->contentService->loadRelations($createdUser->getVersionInfo())
                ),
            )
        );
    }
1306997
static function publishNewUserGroup( $parentNodeIDs, $newGroupAttributes, $isUtf8Encoding = false )
    {
        $newNodeIDs = array();

        if ( !is_array( $newGroupAttributes ) or
             !isset( $newGroupAttributes[ 'name' ] ) or
             empty( $newGroupAttributes[ 'name' ] ) )
        {
            eZDebug::writeWarning( 'Cannot create user group with empty name.', __METHOD__ );
            return $newNodeIDs;
        }
        if ( !is_array( $parentNodeIDs ) or count( $parentNodeIDs ) < 1 )
        {
            eZDebug::writeWarning( 'No one parent node IDs was passed for publishing new group (group name = "' .
                                   $newGroupAttributes[ 'name' ] . '")',
                                   __METHOD__ );
            return $newNodeIDs;
        }

        $ini = eZINI::instance();
        $userGroupClassID = $ini->variable( "UserSettings", "UserGroupClassID" );
        $userCreatorID = $ini->variable( "UserSettings", "UserCreatorID" );
        $defaultSectionID = $ini->variable( "UserSettings", "DefaultSectionID" );

        $userGroupClass = eZContentClass::fetch( $userGroupClassID );
        $contentObject = $userGroupClass->instantiate( $userCreatorID, $defaultSectionID );

        $contentObject->store();

        $contentObjectID = $contentObject->attribute( 'id' );

        reset( $parentNodeIDs );
        $defaultPlacement = current( $parentNodeIDs );
        array_shift( $parentNodeIDs );

        $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObjectID,
                                                           'contentobject_version' => 1,
                                                           'parent_node' => $defaultPlacement,
                                                           // parent_remote_id in node assignment holds remote id of the tree node,
                                                           // not of the parent location or of the node assignment itself
                                                           'parent_remote_id' => uniqid( 'LDAP_' ),
                                                           'is_main' => 1 ) );
        $nodeAssignment->store();

        foreach( $parentNodeIDs as $parentNodeID )
        {
            $newNodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObjectID,
                                                                  'contentobject_version' => 1,
                                                                  'parent_node' => $parentNodeID,
                                                                  // parent_remote_id in node assignment holds remote id of the tree node,
                                                                  // not of the parent location or of the node assignment itself
                                                                  'parent_remote_id' => uniqid( 'LDAP_' ),
                                                                  'is_main' => 0 ) );
            $newNodeAssignment->store();
        }

        $version = $contentObject->version( 1 );
        $version->setAttribute( 'modified', time() );
        $version->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT );
        $version->store();

        $contentObjectAttributes = $version->contentObjectAttributes();

        // find ant set 'name' and 'description' attributes (as standard user group class)
        $nameIdentifier = 'name';
        $descIdentifier = 'description';
        $nameContentAttribute = null;
        $descContentAttribute = null;
        foreach( $contentObjectAttributes as $attribute )
        {
            if ( $attribute->attribute( 'contentclass_attribute_identifier' ) == $nameIdentifier )
            {
                $nameContentAttribute = $attribute;
            }
            else if ( $attribute->attribute( 'contentclass_attribute_identifier' ) == $descIdentifier )
            {
                $descContentAttribute = $attribute;
            }
        }
        if ( $nameContentAttribute )
        {
            if ( $isUtf8Encoding )
                $newGroupAttributes[ 'name' ] = utf8_decode( $newGroupAttributes[ 'name' ] );
            $nameContentAttribute->setAttribute( 'data_text', $newGroupAttributes[ 'name' ] );
            $nameContentAttribute->store();
        }
        if ( $descContentAttribute and
             isset( $newGroupAttributes[ 'description' ] ) )
        {
            if ( $isUtf8Encoding )
                $newGroupAttributes[ 'description' ] = utf8_decode( $newGroupAttributes[ 'description' ] );
            $descContentAttribute->setAttribute( 'data_text', $newGroupAttributes[ 'description' ] );
            $descContentAttribute->store();
        }

        $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID,
                                                                                     'version' => 1 ) );
        $newNodes = eZContentObjectTreeNode::fetchByContentObjectID( $contentObjectID, true, 1 );
        foreach ( $newNodes as $newNode )
        {
            $newNodeIDs[] = $newNode->attribute( 'node_id' );
        }

        return $newNodeIDs;
    }
230610
public function createGroup(string $groupName, int $maxClients = -1)
    {
        if(!isset($this->groups[$groupName]))
        {
            $this->groups[$groupName] = RequestContext::getServerBean('ServerGroup', $this, $groupName, $maxClients);
        }
        return $this->groups[$groupName];
    }
1144176
public static function recursiveChown($path, $user, $group = null)
    {

        // we don't do anything under Windows
        if (FileSystem::getOsIdentifier() === self::OS_IDENTIFIER_WIN) {
            return;
        }

        // we don't have a directory to change the user/group permissions for
        if (is_dir($path) === false) {
            return;
        }

        // get all the files recursively
        $files = FileSystem::globDir($path . '/*');

        // query whether we've a user passed
        if (empty($user) === false) {
            // Change the rights of everything within the defined dirs
            foreach ($files as $file) {
                FileSystem::chown($file, $user, $group);
            }
            FileSystem::chown($path, $user, $group);
        }
    }
496132
public function createApplication(?string $basePath = null): self
    {
        $basePath ?: $basePath = realpath(__DIR__.'/../../../../../');

        $this->app = new Application($basePath);

        return $this;
    }
1269714
private function createCreateForm(PermissionsGroup $permissionsGroup)
    {
        $form = $this->createForm(new PermissionsGroupType(), $permissionsGroup, array(
            'action' => $this->generateUrl('admin_permissionsgroup_create'),
            'method' => 'POST',
        ));

        $form->add('submit', 'submit', array('label' => 'Create'));

        return $form;
    }
519070
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 (ApiExceptions\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
        );
    }
129878
public static function create($classPath) {

        if ( !isset(self::$INSTANES[$classPath]) ) {
            $reflect = new \ReflectionClass($classPath);
            $instance = $reflect->newInstance();
            $instance->initConfigs();
            self::$INSTANES[$classPath] = $instance;
        }
        return self::$INSTANES[$classPath];
    }
692614
def create
      @group = Group.new(group_params.except(:user_id))
      authorize! :create, @group

      if @group.save
        redirect_to @group,
                    notice: "Group was successfully created."
      else
        render :new
      end
    end
459348
public function createMissingPermissions($groupId, array $actionMap)
    {
        $existingPaths = $this->getAllPermissionPathsForGroup($groupId);

        $missingPaths = array_diff(array_keys($actionMap), $existingPaths);

        if (empty($missingPaths)) {
            return;
        }

        $this->connection()->transactional(function () use ($missingPaths, $actionMap, $groupId) {
            foreach ($missingPaths as $missingPath) {
                $action = $actionMap[$missingPath];
                $this->save(
                    new GroupPermission([
                        'group_id' => $groupId,
                        'path' => $missingPath,
                        'plugin' => $action['plugin'],
                        'controller' => $action['controller'],
                        'action' => $action['action'],
                    ])
                );
            }
        });
    }
239929
public function create($path)
    {
        $folders = explode('/', trim(preg_replace('#/+#', '/', $path), '/'));
        $lastFolderId = self::ROOT_DIR_ID;

        foreach ($folders as $name) {

            $command = new CreateFolder($name, $lastFolderId);
            $response = ResponseFactory::getResponse($this->contentClient, $command);

            if ($response instanceof SuccessResponse) {

                if ($response->getStatusCode() == 201) {
                    $lastFolderId = $response->json()['id'];
                    usleep(250);
                    continue;
                }

            } elseif ($response instanceof ErrorResponse) {

                if ($response->getStatusCode() == 409) {
                    $lastFolderId = reset($response->json()['context_info']['conflicts'])['id'];
                    usleep(250);
                    continue;
                }

                throw new \Exception($response->getStatusCode() . (string)$response->getBody());
            }
        }

        if (is_null($lastFolderId)) {
            throw new \Exception();
        }

        return $lastFolderId;
    }
1256894
public function create($userId=null, $eventLog=null, $eventData=null)
    {
        if(is_null($userId)) throw new \Exception('User ID is required.');
        if(is_null($eventLog)) throw new \Exception('Event Log is required.');
        if(!is_numeric($userId)) throw new \Exception("Invalid User ID.");

        $id = $this->save($this->generateEntity(intval($userId), $eventLog, $eventData));
        return $id;
    }
1059813
public function loadUsersFromGroup($groupPath, Request $request)
    {
        $userGroupLocation = $this->locationService->loadLocation(
            $this->extractLocationIdFromPath($groupPath)
        );

        $userGroup = $this->userService->loadUserGroup(
            $userGroupLocation->contentId
        );

        $offset = $request->query->has('offset') ? (int)$request->query->get('offset') : 0;
        $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : 25;

        $users = $this->userService->loadUsersOfUserGroup(
            $userGroup,
            $offset >= 0 ? $offset : 0,
            $limit >= 0 ? $limit : 25,
            Language::ALL
        );

        $restUsers = array();
        foreach ($users as $user) {
            $userContentInfo = $user->getVersionInfo()->getContentInfo();
            $userLocation = $this->locationService->loadLocation($userContentInfo->mainLocationId);
            $contentType = $this->contentTypeService->loadContentType($userContentInfo->contentTypeId);

            $restUsers[] = new Values\RestUser(
                $user,
                $contentType,
                $userContentInfo,
                $userLocation,
                $this->contentService->loadRelations($user->getVersionInfo())
            );
        }

        if ($this->getMediaType($request) === 'application/vnd.ez.api.userlist') {
            return new Values\CachedValue(
                new Values\UserList($restUsers, $request->getPathInfo()),
                array('locationId' => $userGroupLocation->id)
            );
        }

        return new Values\CachedValue(
            new Values\UserRefList($restUsers, $request->getPathInfo()),
            array('locationId' => $userGroupLocation->id)
        );
    }
184933
public function setGroupTemp($groupId)
    {
        if ($groupId == $this->_getVar('user_group')) {
            $this->_unsetVar('current_user_group');
            $this->_unsetVar('current_user_role');
        } else {
            $groups = $this->getAllowedStaffGroups(false);

            $group = $this->userLoader->getGroup($groupId);

            if (isset($groups[$groupId])) {
                $this->_setVar('current_user_group', $groupId);
                $this->_setVar('current_user_role',  $group->getRole());
            } elseif ($group->isActive()) {
                throw new \Gems_Exception($this->_('No access to group'), 403, null, sprintf(
                        $this->_('You are not allowed to switch to the %s group.'),
                        $group->getName()
                        ));
            } else {
                throw new \Gems_Exception($this->_('No access to group'), 403, null, sprintf(
                        $this->_('You cannot switch to an inactive or non-existing group.')
                        ));
            }
        }
        return $this;
    }
1061027
public function allowCreationForSubProperty($propertyPath)
    {
        $this->forProperty($propertyPath)->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true);
        return $this;
    }
996625
public function createDirectory($directoryPath, $permissions = 0777)
    {
        $current = '';
        $parts = array_filter(explode('/', $directoryPath));
        foreach ($parts as $part) {
            $current = "$current/$part";
            if (!empty($part) && !file_exists($current)) {
                mkdir($current, $permissions);
                chmod($current, $permissions);
            }
        }
    }
162903
public static function create_dir($basepath, $name, $chmod = null, $area = null)
	{
		$basepath	= rtrim(static::instance($area)->get_path($basepath), '\\/').DS;
		$new_dir	= static::instance($area)->get_path($basepath.trim($name,'\\/'));
		is_null($chmod) and $chmod = \Config::get('file.chmod.folders', 0777);

		if ( ! is_dir($basepath) or ! is_writable($basepath))
		{
			throw new \InvalidPathException('Invalid basepath: "'.$basepath.'", cannot create directory at this location.');
		}
		elseif (is_dir($new_dir))
		{
			throw new \FileAccessException('Directory: "'.$new_dir.'" exists already, cannot be created.');
		}

		// unify the path separators, and get the part we need to add to the basepath
		$new_dir = substr(str_replace(array('\\', '/'), DS, $new_dir), strlen($basepath));

		// recursively create the directory. we can't use mkdir permissions or recursive
		// due to the fact that mkdir is restricted by the current users umask
		$basepath = rtrim($basepath, DS);
		foreach (explode(DS, $new_dir) as $dir)
		{
			$basepath .= DS.$dir;
			if ( ! is_dir($basepath))
			{
				try
				{
					if ( ! mkdir($basepath))
					{
						return false;
					}
					chmod($basepath, $chmod);
				}
				catch (\PHPErrorException $e)
				{
					return false;
				}
			}
		}

		return true;
	}