public function filterManipulatableRoles($id, array $newRoles)
    {
        $oldRoles = [];
        if ($id && $user = $this->getUser($id)) {
            $oldRoles = $user['roles'];
        }

        $manipulatableRoles = $this->app['permissions']->getManipulatableRoles($this->getCurrentUser());

        $roles = [];
        // Remove roles if the current user can manipulate that role
        foreach ($oldRoles as $role) {
            if ($role === Permissions::ROLE_EVERYONE) {
                continue;
            }
            if (in_array($role, $newRoles) || !in_array($role, $manipulatableRoles)) {
                $roles[] = $role;
            }
        }
        // Add roles if the current user can manipulate that role
        foreach ($newRoles as $role) {
            if (in_array($role, $manipulatableRoles)) {
                $roles[] = $role;
            }
        }

        return array_unique($roles);
    }
public function filterManipulatableRoles($id, array $newRoles)
    {
        $oldRoles = [];
        if ($id && $user = $this->getUser($id)) {
            $oldRoles = $user['roles'];
        }

        $manipulatableRoles = $this->app['permissions']->getManipulatableRoles($this->getCurrentUser());

        $roles = [];
        // Remove roles if the current user can manipulate that role
        foreach ($oldRoles as $role) {
            if ($role === Permissions::ROLE_EVERYONE) {
                continue;
            }
            if (in_array($role, $newRoles) || !in_array($role, $manipulatableRoles)) {
                $roles[] = $role;
            }
        }
        // Add roles if the current user can manipulate that role
        foreach ($newRoles as $role) {
            if (in_array($role, $manipulatableRoles)) {
                $roles[] = $role;
            }
        }

        return array_unique($roles);
    }
public function filterManipulatableRoles ( $ id , array $ newRoles ) { $ oldRoles = [ ] ; if ( $ id && $ user = $ this -> getUser ( $ id ) ) { $ oldRoles = $ user [ 'roles' ] ; } $ manipulatableRoles = $ this -> app [ 'permissions' ] -> getManipulatableRoles ( $ this -> getCurrentUser ( ) ) ; $ roles = [ ] ; // Remove roles if the current user can manipulate that role foreach ( $ oldRoles as $ role ) { if ( $ role === Permissions :: ROLE_EVERYONE ) { continue ; } if ( in_array ( $ role , $ newRoles ) || ! in_array ( $ role , $ manipulatableRoles ) ) { $ roles [ ] = $ role ; } } // Add roles if the current user can manipulate that role foreach ( $ newRoles as $ role ) { if ( in_array ( $ role , $ manipulatableRoles ) ) { $ roles [ ] = $ role ; } } return array_unique ( $ roles ) ; }
Ensure changes to the user's roles match what the current user has
permissions to manipulate.

@param string|int $id       User ID
@param array      $newRoles Roles from form submission

@return string[] The user's roles with the allowed changes
Ensure changes to the user s roles match what the current user has permissions to manipulate .