Give a role, access to a resource
352273
function it_can_grant_access_to_roles_by_appending_actions($resourceObject, $groupRules, $groupActionRule)
    {
        $role = $this->getRoleWithName('user');
        $groupRules->update(Argument::any())->shouldBeCalled();
        $groupActionRule->addAction('foo')->shouldBeCalled();
        $this->grantRoleAccess($role, $resourceObject, 'foo');
    }
106928
def update_role(role,**kwargs):
    
    #check_perm(kwargs.get('user_id'), 'edit_role')
    try:
        role_i = db.DBSession.query(Role).filter(Role.id==role.id).one()
        role_i.name = role.name
        role_i.code = role.code
    except NoResultFound:
        raise ResourceNotFoundError("Role (role_id=%s) does not exist"%(role.id))

    for perm in role.permissions:
        _get_perm(perm.id)
        roleperm_i = RolePerm(role_id=role.id,
                              perm_id=perm.id
                              )

        db.DBSession.add(roleperm_i)

    for user in role.users:
        _get_user(user.id)
        roleuser_i = RoleUser(user_id=user.id,
                                         perm_id=perm.id
                                        )

        db.DBSession.add(roleuser_i)

    db.DBSession.flush()
    return role_i
798156
def create(self, project, email, role, **attrs):
        
        attrs.update({'project': project, 'email': email, 'role': role})
        return self._new_resource(payload=attrs)
306456
def process_role(ctx, param, value):
    """"""
    role = Role.query.filter(Role.name == value).first()
    if not role:
        raise click.BadParameter('Role with name \'%s\' not found.', value)
    return role
198256
function adminsOnly(req, res, next) {
  if (req.session && _.contains(req.session.user.roles, 'admin')) {
    next();
  }
  else {
    res.status(401).send('Only administrators can access this resource');
  }
}
195564
def updateRole(self, roleID, name, description):
        """"""
        params = {
            "name" : name,
            "description" : description,
            "f" : "json"
        }
        url = self._url + "/%s/update"
        return self._post(url=url,
                             param_dict=params,
                             proxy_url=self._proxy_url,
                             proxy_port=self._proxy_port)
1006029
def set_role(project_root, environment)
      roles = Bebox::Role.list(project_root)
      nodes = Bebox::Node.list(project_root, environment, 'nodes')
      node = choose_option(nodes, _('wizard.choose_node'))
      role = choose_option(roles, _('wizard.choose_role'))
      output = Bebox::Provision.associate_node_role(project_root, environment, node, role)
      ok _('wizard.node.role_set_success')
      return output
    end
25755
def set_role_id(self, role_name, role_id, mount_point='approle'):
        

        url = '/v1/auth/{0}/role/{1}/role-id'.format(mount_point, role_name)
        params = {
            'role_id': role_id
        }
        return self._adapter.post(url, json=params)
1278999
function hasRole(rbac, role, cb) {
  if (!this.role) {
    cb(null, false);
    return this;
  }

  // check existance of permission
  rbac.hasRole(this.role, role, cb);
  return this;
}
143279
def present(name, owner=None, grants=None, **kwargs):
    '''
    
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': ''}

    if __salt__['mssql.role_exists'](name, **kwargs):
        ret['comment'] = 'Role {0} is already present (Not going to try to set its grants)'.format(name)
        return ret
    if __opts__['test']:
        ret['result'] = None
        ret['comment'] = 'Role {0} is set to be added'.format(name)
        return ret

    role_created = __salt__['mssql.role_create'](name, owner=owner, grants=grants, **kwargs)
    if role_created is not True:  # Non-empty strings are also evaluated to True, so we cannot use if not role_created:
        ret['result'] = False
        ret['comment'] += 'Role {0} failed to be created: {1}'.format(name, role_created)
        return ret
    ret['comment'] += 'Role {0} has been added'.format(name)
    ret['changes'][name] = 'Present'
    return ret
91548
protected function checkRoleResource($role, $resource)
    {
        $resource = $this->checkResource($resource);
        $role = $this->checkRole($role);
        $roleId = ($role->getRoleId() == null) ? StorageInterface::ALL_ROLES : $role->getRoleId();
        $resrcId = ($resource->getResourceId() == null) ? StorageInterface::ALL_RESOURCES : $resource->getResourceId();
        if (!isset($this->permission[$roleId][self::NODE_RESOURCES][$resrcId][self::NODE_PERMISSION])) {
            $this->permission[$roleId][self::NODE_RESOURCES][$resrcId][self::NODE_PERMISSION] = [];
        }

        return $this;
    }
844550
def share(self, with_user, roles=None):
        '''
        
        '''
        return self.proxy.share(table=self.name, with_user=with_user,
                                roles=roles)
581727
def make_resource_handle(self, resource_key, **variables):
        
        if variables.get("repository_type", self.name()) != self.name():
            raise ResourceError("repository_type mismatch - requested %r, "
                                "repository_type is %r"
                                % (variables["repository_type"], self.name()))

        variables["repository_type"] = self.name()

        if variables.get("location", self.location) != self.location:
            raise ResourceError("location mismatch - requested %r, repository "
                                "location is %r" % (variables["location"],
                                                    self.location))
        variables["location"] = self.location

        resource_cls = self.pool.get_resource_class(resource_key)
        variables = resource_cls.normalize_variables(variables)
        return ResourceHandle(resource_key, variables)
1322673
function access(permission, account, callback) {
  // User #1 has all privileges:
  if (account.uid === 1) {
    callback(null, true);
    return;
  }

  // If permissions is already loaded, use them.
  if (account.permissions) {
    callback(null, account.permissions.indexOf(permission) > -1);
    return;
  }

  role_permissions(account.roles, function (err, permissions) {
    if (err) {
      callback(err);
      return;
    }

    callback(null, permissions.indexOf(permission) > -1);
  });
}
1187022
function addPermission(rbac, action, resource, cb) {
  rbac.getPermission(action, resource, (err, permission) => {
    if (err) {
      return cb(err);
    }

    if (!permission) {
      return cb(new Error('Permission not exists'));
    }

    if (indexOf(this.permissions, permission.name) !== -1) {
      return cb(new Error('Permission is already assigned'));
    }

    this.permissions.push(permission.name);
    return this.save((err2, user) => {
      if (err2) {
        return cb(err2);
      }

      if (!user) {
        return cb(new Error('User is undefined'));
      }

      return cb(null, true);
    });
  });

  return this;
}
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)
588300
def assign_role(backend, user, response, *args, **kwargs):
    '''
    
    '''
    if backend.name is 'passthrough' and settings.DEMO is True and 'role' in kwargs['request'].session[passthrough.SESSION_VAR]:
        role = kwargs['request'].session[passthrough.SESSION_VAR]['role']
        if role == 'tutor':
            make_tutor(user)
        if role == 'admin':
            make_admin(user)
        if role == 'owner':
            make_owner(user)