saves the role for the user in the data store
169124
def set_roles *roles
      raise ArgumentError, "A single role strategy can only allow setting a single role, was: #{roles}" if (roles.size > 1)
      set_role roles.flat_uniq.first
    end
1139283
def set_role_perm(role_id, perm_id,**kwargs):
    
    #check_perm(kwargs.get('user_id'), 'edit_perm')

    _get_perm(perm_id)
    role_i = _get_role(role_id)
    roleperm_i = RolePerm(role_id=role_id, perm_id=perm_id)

    role_i.roleperms.append(roleperm_i)

    db.DBSession.flush()

    return role_i
138852
def add_role_to_user(self, user, role):
        
        user, role = self._prepare_role_modify_args(user, role)
        result = self.UserRole.select().where(
            self.UserRole.user == user.id,
            self.UserRole.role == role.id,
        )
        if result.count():
            return False
        else:
            self.put(self.UserRole.create(user=user.id, role=role.id))
            return True
211377
def create_role(self, **kwargs):
        """"""

        role = self.role_model(**kwargs)
        return self.put(role)
852236
def role_update(self, role_id, data, **kwargs):
        ""
        api_path = "/api/v2/roles/{role_id}"
        api_path = api_path.format(role_id=role_id)
        return self.call(api_path, method="PUT", data=data, **kwargs)
885238
def remove_role_from_user(self, user, role):
        
        user.remove_role(role)
        self.save(user)
        events.user_lost_role_event.send(user, role=role)
812940
public function save()
    {
        if ($this->widget && $this->widget->OwnerID && $this->widget->OwnerID != Member::currentUserID()) {
            // check ownership, not just write access
            return;
        }
        //Note : Gridster uses weird names... size_x? Why just not width, Argh...
        //			Admittedly, col and row makes sense since it's essentially
        //			using cells to align up objects.
        $obj = self::get()->byID($this->request->param('ID'));
        $obj->PosX = $this->request->postVar('col');
        $obj->PosY = $this->request->postVar('row');
        $obj->Width = $this->request->postVar('size_x');
        $obj->Height = $this->request->postVar('size_y');

        // only allow the owner access to write. 

        $obj->write();
    }
186473
def persist_registered_roles!
      @roles.each do |name, description|
        Sipity::Role.find_or_create_by!(name: name).tap do |role|
          role.description = description
          role.save!
        end
      end
    end
1047189
function storeModel(model, permissionSchemaKey) {
    if (model && model.rolePermissions) {
        var obj = {
            permissionSchemaKey: permissionSchemaKey,
            rolePermissions: model.rolePermissions
        };
        exports.store(obj);
    }
}
1223098
public function storeRolePermission(Role $role, Permission $permission)
    {
        $this->getTable()->insert([
            'role' => $role->getRoleName(),
            'type' => $permission->getType(),
            'action' => $permission->getAction(),
            'resource_type' => $permission->getResourceType(),
            'resource_id' => $permission->getResourceId(),
        ]);

        $this->resetPermissionsCacheForRole($role);
    }
1079276
def save(self):
        
        self.stack.append(self.dispatch_table)
        self.dispatch_table = self.default_table.copy()
731532
def add_role(self, role):
        
        schema = RoleSchema()
        ok = schema.process(role)
        if not ok or not role.id:
            err = 'Role must be valid and saved before adding to user'
            raise x.UserException(err)

        self.__roles.append(role)
317739
def add_user_role(self, user, role):
        
        self.project_service.set_auth(self._token_project)
        self.project_service.add_user_role(user, role)
5124
def role_add(self, role=None, login=None, envs=[], query='/roles/'):
        
        data = {'login': self.args.login}
        juicer.utils.Log.log_debug(
                "Add Role '%s' to '%s'", role, login)

        for env in self.args.envs:
            if not juicer.utils.role_exists_p(role, self.connectors[env]):
                juicer.utils.Log.log_info("role `%s` doesn't exist in %s... skipping!",
                                          (role, env))
                continue
            elif not juicer.utils.user_exists_p(login, self.connectors[env]):
                juicer.utils.Log.log_info("user `%s` doesn't exist in %s... skipping!",
                                          (login, env))
            else:
                url = "%s%s/users/" % (query, role)
                _r = self.connectors[env].post(url, data)
                if _r.status_code == Constants.PULP_POST_OK:
                    juicer.utils.Log.log_info("added user `%s` to role `%s` in %s",
                                              (login, role, env))
                else:
                    _r.raise_for_status()
        return True
998402
protected function initSURole() : void
    {
        $this->stdout("Init SU role \n",  Console::FG_YELLOW);
        $this->authManager->removeAll();
        $su = $this->authManager->createRole(Rbac::R_SU);
        $su->description = 'Super User';
        $this->authManager->add($su);
    }
1192490
def set_admin(email):
    ''''''
    user = datastore.get_user(email)
    log.info('Adding admin role to user %s (%s)', user.fullname, user.email)
    role = datastore.find_or_create_role('admin')
    datastore.add_role_to_user(user, role)
    success('User %s (%s) is now administrator' % (user.fullname, user.email))
790714
def post(method, hmc, uri, uri_parms, body, logon_required,
             wait_for_completion):
        """"""
        assert wait_for_completion is True  # synchronous operation
        user_role_oid = uri_parms[0]
        user_role_uri = '/api/user-roles/' + user_role_oid
        try:
            user_role = hmc.lookup_by_uri(user_role_uri)
        except KeyError:
            raise InvalidResourceError(method, uri)
        check_required_fields(method, uri, body,
                              ['permitted-object', 'permitted-object-type'])
        # Reject if User Role is system-defined:
        if user_role.properties['type'] == 'system-defined':
            raise BadRequestError(
                method, uri, reason=314, message="Cannot add permission to "
                "system-defined user role: {}".format(user_role_uri))
        # Apply defaults, so our internally stored copy has all fields:
        permission = copy.deepcopy(body)
        if 'include-members' not in permission:
            permission['include-members'] = False
        if 'view-only-mode' not in permission:
            permission['view-only-mode'] = True
        # Add the permission to its store (the faked User Role object):
        if user_role.properties.get('permissions', None) is None:
            user_role.properties['permissions'] = []
        user_role.properties['permissions'].append(permission)