src/index.js
function can(rbac, action, resource, cb) {
  // check existance of permission
  rbac.getPermission(action, resource, (err, permission) => {
    if (err) {
      return cb(err);
    }

    if (!permission) {
      return cb(null, false);
    }

    // check user additional permissions
    if (indexOf(this.permissions, permission.name) !== -1) {
      return cb(null, true);
    }

    if (!this.role) {
      return cb(null, false);
    }

    // check permission inside user role
    return rbac.can(this.role, action, resource, cb);
  });

  return this;
}
function can(rbac, action, resource, cb) {
  // check existance of permission
  rbac.getPermission(action, resource, (err, permission) => {
    if (err) {
      return cb(err);
    }

    if (!permission) {
      return cb(null, false);
    }

    // check user additional permissions
    if (indexOf(this.permissions, permission.name) !== -1) {
      return cb(null, true);
    }

    if (!this.role) {
      return cb(null, false);
    }

    // check permission inside user role
    return rbac.can(this.role, action, resource, cb);
  });

  return this;
}
function can ( rbac , action , resource , cb ) { // check existance of permission rbac . getPermission ( action , resource , ( err , permission ) => { if ( err ) { return cb ( err ) ; } if ( ! permission ) { return cb ( null , false ) ; } // check user additional permissions if ( indexOf ( this . permissions , permission . name ) !== - 1 ) { return cb ( null , true ) ; } if ( ! this . role ) { return cb ( null , false ) ; } // check permission inside user role return rbac . can ( this . role , action , resource , cb ) ; } ) ; return this ; }
Check if user has assigned a specific permission
@param  {RBAC}  rbac Instance of RBAC
@param  {String}   action  Name of action
@param  {String}   resource  Name of resource
@return {Boolean}
Check if user has assigned a specific permission