Neos.Neos/Classes/Command/UserCommandController.php
public function addRoleCommand($username, $role, $authenticationProvider = null)
    {
        $users = $this->findUsersByUsernamePattern($username, $authenticationProvider);
        if (empty($users)) {
            $this->outputLine('No users that match name-pattern "%s" do exist.', [$username]);
            $this->quit(1);
        }

        foreach ($users as $user) {
            $username = $this->userService->getUsername($user, $authenticationProvider);
            try {
                if ($this->userService->addRoleToUser($user, $role) > 0) {
                    $this->outputLine('Added role "%s" to accounts of user "%s".', [$role, $username]);
                } else {
                    $this->outputLine('User "%s" already had the role "%s" assigned.', [$username, $role]);
                }
            } catch (NoSuchRoleException $exception) {
                $this->outputLine('The role "%s" does not exist.', [$role]);
                $this->quit(2);
            }
        }
    }
public function addRoleCommand($username, $role, $authenticationProvider = null)
    {
        $users = $this->findUsersByUsernamePattern($username, $authenticationProvider);
        if (empty($users)) {
            $this->outputLine('No users that match name-pattern "%s" do exist.', [$username]);
            $this->quit(1);
        }

        foreach ($users as $user) {
            $username = $this->userService->getUsername($user, $authenticationProvider);
            try {
                if ($this->userService->addRoleToUser($user, $role) > 0) {
                    $this->outputLine('Added role "%s" to accounts of user "%s".', [$role, $username]);
                } else {
                    $this->outputLine('User "%s" already had the role "%s" assigned.', [$username, $role]);
                }
            } catch (NoSuchRoleException $exception) {
                $this->outputLine('The role "%s" does not exist.', [$role]);
                $this->quit(2);
            }
        }
    }
public function addRoleCommand ( $ username , $ role , $ authenticationProvider = null ) { $ users = $ this -> findUsersByUsernamePattern ( $ username , $ authenticationProvider ) ; if ( empty ( $ users ) ) { $ this -> outputLine ( 'No users that match name-pattern "%s" do exist.' , [ $ username ] ) ; $ this -> quit ( 1 ) ; } foreach ( $ users as $ user ) { $ username = $ this -> userService -> getUsername ( $ user , $ authenticationProvider ) ; try { if ( $ this -> userService -> addRoleToUser ( $ user , $ role ) > 0 ) { $ this -> outputLine ( 'Added role "%s" to accounts of user "%s".' , [ $ role , $ username ] ) ; } else { $ this -> outputLine ( 'User "%s" already had the role "%s" assigned.' , [ $ username , $ role ] ) ; } } catch ( NoSuchRoleException $ exception ) { $ this -> outputLine ( 'The role "%s" does not exist.' , [ $ role ] ) ; $ this -> quit ( 2 ) ; } } }
Add a role to a user

This command allows for adding a specific role to an existing user.

Roles can optionally be specified as a comma separated list. For all roles provided by Neos, the role
namespace "Neos.Neos:" can be omitted.

If an authentication provider was specified, the user will be determined by an account identified by "username"
related to the given provider. However, once a user has been found, the new role will be added to <b>all</b>
existing accounts related to that user, regardless of its authentication provider.

@param string $username The username of the user (globbing is supported)
@param string $role Role to be added to the user, for example "Neos.Neos:Administrator" or just "Administrator"
@param string $authenticationProvider Name of the authentication provider to use. Example: "Neos.Neos:Backend"
@return void
Add a role to a user