mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 09:52:09 +03:00
b03ecd9ebc
Refs #2170 This removes the circular dependency problem from our models thanks to https://github.com/tgriesser/bookshelf/issues/181 - add the registry plugin - switch all models and collections to be registered - switch relationships to be defined using a string, which calls from the registry
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
var ghostBookshelf = require('./base'),
|
|
|
|
Permission,
|
|
Permissions;
|
|
|
|
Permission = ghostBookshelf.Model.extend({
|
|
|
|
tableName: 'permissions',
|
|
|
|
roles: function () {
|
|
return this.belongsToMany('Role');
|
|
},
|
|
|
|
users: function () {
|
|
return this.belongsToMany('User');
|
|
},
|
|
|
|
apps: function () {
|
|
return this.belongsToMany('App');
|
|
}
|
|
}, {
|
|
/**
|
|
* 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;
|
|
}
|
|
});
|
|
|
|
Permissions = ghostBookshelf.Collection.extend({
|
|
model: Permission
|
|
});
|
|
|
|
module.exports = {
|
|
Permission: ghostBookshelf.model('Permission', Permission),
|
|
Permissions: ghostBookshelf.collection('Permissions', Permissions)
|
|
};
|