src/index.js
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;
}
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;
}
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 ; }
Assign additional permissions to the user
@param  {String|Array}   permissions  Array of permissions or string representing of permission
@param  {Function} cb Callback
Assign additional permissions to the user