Apply `role_id` to `new_user_id`

        Note this function returns the `Role` instance associated with `role_id`
968286
def set_user_role(new_user_id, role_id, **kwargs):
    
    #check_perm(kwargs.get('user_id'), 'edit_role')
    try:
        _get_user(new_user_id)
        role_i = _get_role(role_id)
        roleuser_i = RoleUser(user_id=new_user_id, role_id=role_id)
        role_i.roleusers.append(roleuser_i)
        db.DBSession.flush()
    except Exception as e: # Will occur if the foreign keys do not exist
        log.exception(e)
        raise ResourceNotFoundError("User or Role does not exist")

    return role_i
533985
def add_role(*_, role_handle=None, user_id=None):
    
    click.echo(green('\nAdding role to user:'))
    click.echo(green('-' * 40))
    with get_app().app_context():
        user = find_user(dict(id=user_id))
        if not user:
            click.echo(red('User not found\n'))
            return

        role = role_service.first(handle=role_handle)
        if not role:
            click.echo(red('No such role ({})\n'.format(role_handle)))
            return

        user_service.add_role_to_user(user, role)
        msg = 'Added role "{}" to user "{}"'.format(role.handle, user.email)
        click.echo(green(msg))
        return
974588
protected function updateRole($role_id)
    {
        if (!$this->isError() && !$this->role->update($role_id, $this->getSubmitted())) {
            $this->errorAndExit($this->text('Unexpected result'));
        }
    }
634436
def update_role(id, name)
      current_path = "/api/v1/roles/#{id}/update"
      payload = { 'new_name' => name }.to_json
      @conn.put(current_path, payload)
    end
1255076
def remove_role_from_user(self, user, role):
        
        user, role = self._prepare_role_modify_args(user, role)
        result = self.UserRole.select().where(
            self.UserRole.user == user,
            self.UserRole.role == role,
        )
        if result.count():
            query = self.UserRole.delete().where(
                self.UserRole.user == user, self.UserRole.role == role)
            query.execute()
            return True
        else:
            return False
868929
public function revokeRole($role, $user_id)
    {
        $user = \App\User::findorfail($user_id);

        $user->removeRole(str_slug($role, ' '));

        return redirect('scaffold-users/edit/'.$user_id);
    }
1054752
def set_roles(role, reason = nil)
      role_ids = role_id_array(role)
      API::Server.update_member(@bot.token, @server.id, @user.id, roles: role_ids, reason: reason)
    end
438626
def role_delete(self, role_id, **kwargs):
        ""
        api_path = "/api/v2/roles/{role_id}"
        api_path = api_path.format(role_id=role_id)
        return self.call(api_path, method="DELETE", **kwargs)
127418
def get_role_id(self, role_name, mount_point='approle'):
        

        url = '/v1/auth/{0}/role/{1}/role-id'.format(mount_point, role_name)
        return self._adapter.get(url).json()['data']['role_id']
1189632
def add_role role
      raise ArgumentError, '#add_role takes a single role String or Symbol as the argument' if !role || role.kind_of?(Array)
      add_roles role
    end
986421
def assign(self, role):
        ''''''
        if role.owner_id != self.id:
            return self.roles.add(role)
822301
async def role(self, *args, **kwargs):
        

        return await self._makeApiCall(self.funcinfo["role"], *args, **kwargs)
204799
def remove_role(*_, role_handle=None, user_id=None):
    
    click.echo(green('\nRemoving role from user:'))
    click.echo(green('-' * 40))
    with get_app().app_context():
        user = find_user(dict(id=user_id))
        if not user:
            click.echo(red('User not found\n'))
            return

        remove_role = None
        for role in user.roles:
            if role.handle == role_handle:
                remove_role = role

        if not remove_role:
            click.echo(red('User does not have such role\n'))
            return

        user_service.remove_role_from_user(user, remove_role)
        msg = 'Role "{}" removed from user "{}"\n'.format(
            remove_role.handle,
            user.email
        )
        click.echo(green(msg))
        return
1351146
def find_or_create_role(self, name, **kwargs):
        
        kwargs["name"] = name
        return self.find_role(name) or self.create_role(**kwargs)
512601
def add_role_to_user(user, role):
    
    user = _query_to_user(user)
    role = _query_to_role(role)
    if click.confirm(f'Are you sure you want to add {role!r} to {user!r}?'):
        user.roles.append(role)
        user_manager.save(user, commit=True)
        click.echo(f'Successfully added {role!r} to {user!r}')
    else:
        click.echo('Cancelled.')
1089733
def set_role new_role
      value = make_valid_role new_role 
      return false if !value
      store.set_role(value)      
    end
13426
public function update($role_id, array $data)
    {
        $result = null;
        $this->hook->attach('user.role.update.before', $role_id, $data, $result, $this);

        if (isset($result)) {
            return (bool) $result;
        }

        $result = (bool) $this->db->update('role', $data, array('role_id' => $role_id));
        $this->hook->attach('user.role.update.after', $role_id, $data, $result, $this);
        return (bool) $result;
    }