2018-04-25 13:27:39 +03:00
|
|
|
const ghostBookshelf = require('./base');
|
|
|
|
|
|
|
|
let Permission,
|
2013-06-25 15:43:15 +04:00
|
|
|
Permissions;
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-09-23 02:20:08 +04:00
|
|
|
Permission = ghostBookshelf.Model.extend({
|
2013-09-14 23:01:46 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
tableName: 'permissions',
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2018-04-25 13:27:39 +03:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2015-06-14 18:58:49 +03:00
|
|
|
roles: function roles() {
|
2018-04-25 13:27:39 +03:00
|
|
|
return this.belongsToMany('Role', 'permissions_roles', 'permission_id', 'role_id');
|
2013-06-25 15:43:15 +04:00
|
|
|
},
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2015-06-14 18:58:49 +03:00
|
|
|
users: function users() {
|
2014-07-13 15:17:18 +04:00
|
|
|
return this.belongsToMany('User');
|
2014-02-12 07:40:39 +04:00
|
|
|
},
|
|
|
|
|
2015-06-14 18:58:49 +03:00
|
|
|
apps: function apps() {
|
2014-07-13 15:17:18 +04:00
|
|
|
return this.belongsToMany('App');
|
2013-06-25 15:43:15 +04:00
|
|
|
}
|
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-09-23 02:20:08 +04:00
|
|
|
Permissions = ghostBookshelf.Collection.extend({
|
2013-06-25 15:43:15 +04:00
|
|
|
model: Permission
|
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
module.exports = {
|
2014-07-13 15:17:18 +04:00
|
|
|
Permission: ghostBookshelf.model('Permission', Permission),
|
|
|
|
Permissions: ghostBookshelf.collection('Permissions', Permissions)
|
2014-02-27 06:44:09 +04:00
|
|
|
};
|