mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 11:22:19 +03:00
5f5f0021db
no issue - support ends today - see https://github.com/nodejs/Release - removed `use strict`
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
const ghostBookshelf = require('./base');
|
|
|
|
let Permission,
|
|
Permissions;
|
|
|
|
Permission = ghostBookshelf.Model.extend({
|
|
|
|
tableName: 'permissions',
|
|
|
|
relationships: ['roles'],
|
|
relationshipBelongsTo: {
|
|
roles: 'roles'
|
|
},
|
|
|
|
/**
|
|
* The base model keeps only the columns, which are defined in the schema.
|
|
* We have to add the relations on top, otherwise bookshelf-relations
|
|
* has no access to the nested relations, which should be updated.
|
|
*/
|
|
permittedAttributes: function permittedAttributes() {
|
|
let filteredKeys = ghostBookshelf.Model.prototype.permittedAttributes.apply(this, arguments);
|
|
|
|
this.relationships.forEach((key) => {
|
|
filteredKeys.push(key);
|
|
});
|
|
|
|
return filteredKeys;
|
|
},
|
|
|
|
roles: function roles() {
|
|
return this.belongsToMany('Role', 'permissions_roles', 'permission_id', 'role_id');
|
|
},
|
|
|
|
users: function users() {
|
|
return this.belongsToMany('User');
|
|
},
|
|
|
|
apps: function apps() {
|
|
return this.belongsToMany('App');
|
|
}
|
|
});
|
|
|
|
Permissions = ghostBookshelf.Collection.extend({
|
|
model: Permission
|
|
});
|
|
|
|
module.exports = {
|
|
Permission: ghostBookshelf.model('Permission', Permission),
|
|
Permissions: ghostBookshelf.collection('Permissions', Permissions)
|
|
};
|