api/services/PermissionService.js
function(options) {

    var ok = Promise.resolve();
    var permissions = options.permissions;

    if (!_.isArray(permissions)) {
      permissions = [permissions];
    }


    // look up the model id based on the model name for each permission, and change it to an id
    ok = ok.then(function() {
      return Promise.all(permissions.map(function(permission) {
        return Model.findOne({
            name: permission.model
          })
          .then(function(model) {
            permission.model = model.id;
            return permission;
          });
      }));
    });

    // look up user ids based on usernames, and replace the names with ids
    ok = ok.then(function(permissions) {
      if (options.users) {
        return User.find({
            username: options.users
          })
          .then(function(users) {
            options.users = users;
          });
      }
    });

    ok = ok.then(function(users) {
      return Role.create(options);
    });

    return ok;
  }
function(options) {

    var ok = Promise.resolve();
    var permissions = options.permissions;

    if (!_.isArray(permissions)) {
      permissions = [permissions];
    }


    // look up the model id based on the model name for each permission, and change it to an id
    ok = ok.then(function() {
      return Promise.all(permissions.map(function(permission) {
        return Model.findOne({
            name: permission.model
          })
          .then(function(model) {
            permission.model = model.id;
            return permission;
          });
      }));
    });

    // look up user ids based on usernames, and replace the names with ids
    ok = ok.then(function(permissions) {
      if (options.users) {
        return User.find({
            username: options.users
          })
          .then(function(users) {
            options.users = users;
          });
      }
    });

    ok = ok.then(function(users) {
      return Role.create(options);
    });

    return ok;
  }
function ( options ) { var ok = Promise . resolve ( ) ; var permissions = options . permissions ; if ( ! _ . isArray ( permissions ) ) { permissions = [ permissions ] ; } // look up the model id based on the model name for each permission, and change it to an id ok = ok . then ( function ( ) { return Promise . all ( permissions . map ( function ( permission ) { return Model . findOne ( { name : permission . model } ) . then ( function ( model ) { permission . model = model . id ; return permission ; } ) ; } ) ) ; } ) ; // look up user ids based on usernames, and replace the names with ids ok = ok . then ( function ( permissions ) { if ( options . users ) { return User . find ( { username : options . users } ) . then ( function ( users ) { options . users = users ; } ) ; } } ) ; ok = ok . then ( function ( users ) { return Role . create ( options ) ; } ) ; return ok ; }
create a new role
@param options
@param options.name {string} - role name
@param options.permissions {permission object, or array of permissions objects}
@param options.permissions.model {string} - the name of the model that the permission is associated with
@param options.permissions.criteria - optional criteria object
@param options.permissions.criteria.where - optional waterline query syntax object for specifying permissions
@param options.permissions.criteria.blacklist {string array} - optional attribute blacklist
@param options.users {array of user names} - optional array of user ids that have this role
create a new role