2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00
Ghost/core/server/models/permission.js
kirrg001 5f5f0021db 🔥 Drop Node v4 Support
no issue

- support ends today
- see https://github.com/nodejs/Release
- removed `use strict`
2018-05-01 14:06:18 +02:00

50 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)
};