api/services/PermissionService.js
function(user, action, model, body) {
    return function(obj) {
      return new Promise(function(resolve, reject) {
        Model.findOne({
          identity: model
        }).then(function(model) {
         return Permission.find({
            model: model.id,
            action: action,
            relation: 'user',
            user: user
          }).populate('criteria');
        }).then(function(permission) {
          if (permission.length > 0 && PermissionService.hasPassingCriteria(obj, permission, body)) {
            resolve(true);
          } else {
            resolve(false);
          }
        }).catch(reject);
      });
    };
  }
function(user, action, model, body) {
    return function(obj) {
      return new Promise(function(resolve, reject) {
        Model.findOne({
          identity: model
        }).then(function(model) {
         return Permission.find({
            model: model.id,
            action: action,
            relation: 'user',
            user: user
          }).populate('criteria');
        }).then(function(permission) {
          if (permission.length > 0 && PermissionService.hasPassingCriteria(obj, permission, body)) {
            resolve(true);
          } else {
            resolve(false);
          }
        }).catch(reject);
      });
    };
  }
function ( user , action , model , body ) { return function ( obj ) { return new Promise ( function ( resolve , reject ) { Model . findOne ( { identity : model } ) . then ( function ( model ) { return Permission . find ( { model : model . id , action : action , relation : 'user' , user : user } ) . populate ( 'criteria' ) ; } ) . then ( function ( permission ) { if ( permission . length > 0 && PermissionService . hasPassingCriteria ( obj , permission , body ) ) { resolve ( true ) ; } else { resolve ( false ) ; } } ) . catch ( reject ) ; } ) ; } ; }
Resolve if the user have the permission to perform this action
@param user
@param action
@param model
@param body
@returns {Function}
Resolve if the user have the permission to perform this action