2013-09-22 17:20:08 -05:00
|
|
|
var ghostBookshelf = require('./base'),
|
2013-09-24 05:46:30 -05:00
|
|
|
User = require('./user').User,
|
|
|
|
Role = require('./role').Role,
|
2014-02-11 22:40:39 -05:00
|
|
|
App = require('./app').App,
|
2014-03-14 12:36:45 -05:00
|
|
|
|
2013-06-25 06:43:15 -05:00
|
|
|
Permission,
|
|
|
|
Permissions;
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-09-22 17:20:08 -05:00
|
|
|
Permission = ghostBookshelf.Model.extend({
|
2013-09-14 14:01:46 -05:00
|
|
|
|
2013-06-25 06:43:15 -05:00
|
|
|
tableName: 'permissions',
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 06:43:15 -05:00
|
|
|
roles: function () {
|
|
|
|
return this.belongsToMany(Role);
|
|
|
|
},
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 06:43:15 -05:00
|
|
|
users: function () {
|
|
|
|
return this.belongsToMany(User);
|
2014-02-11 22:40:39 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
apps: function () {
|
|
|
|
return this.belongsToMany(App);
|
2013-06-25 06:43:15 -05:00
|
|
|
}
|
2014-05-05 20:45:08 -05:00
|
|
|
}, {
|
|
|
|
/**
|
|
|
|
* Returns an array of keys permitted in a method's `options` hash, depending on the current method.
|
|
|
|
* @param {String} methodName The name of the method to check valid options for.
|
|
|
|
* @return {Array} Keys allowed in the `options` hash of the model's method.
|
|
|
|
*/
|
|
|
|
permittedOptions: function (methodName) {
|
|
|
|
var options = ghostBookshelf.Model.permittedOptions(),
|
|
|
|
|
|
|
|
// whitelists for the `options` hash argument on methods, by method name.
|
|
|
|
// these are the only options that can be passed to Bookshelf / Knex.
|
|
|
|
validOptions = {
|
|
|
|
add: ['user']
|
|
|
|
};
|
|
|
|
|
|
|
|
if (validOptions[methodName]) {
|
|
|
|
options = options.concat(validOptions[methodName]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
},
|
2013-06-25 06:43:15 -05:00
|
|
|
});
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-09-22 17:20:08 -05:00
|
|
|
Permissions = ghostBookshelf.Collection.extend({
|
2013-06-25 06:43:15 -05:00
|
|
|
model: Permission
|
|
|
|
});
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 06:43:15 -05:00
|
|
|
module.exports = {
|
|
|
|
Permission: Permission,
|
|
|
|
Permissions: Permissions
|
2014-02-26 21:44:09 -05:00
|
|
|
};
|