mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
c70dfde7e3
- fixes #517 - prevents this from occuring again in future with other relations - validation function & stripping done for all models - casper test for flow, plus validation & logged out tests
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
var GhostBookshelf = require('./base'),
|
|
User = require('./user').User,
|
|
Role = require('./role').Role,
|
|
Permission,
|
|
Permissions;
|
|
|
|
Permission = GhostBookshelf.Model.extend({
|
|
tableName: 'permissions',
|
|
|
|
permittedAttributes: ['id', 'name', 'object_type', 'action_type', 'object_id'],
|
|
|
|
initialize: function () {
|
|
this.on('saving', this.saving, this);
|
|
this.on('saving', this.validate, this);
|
|
},
|
|
|
|
validate: function () {
|
|
// TODO: validate object_type, action_type and object_id
|
|
GhostBookshelf.validator.check(this.get('name'), "Permission name cannot be blank").notEmpty();
|
|
},
|
|
|
|
saving: function () {
|
|
// Deal with the related data here
|
|
|
|
// Remove any properties which don't belong on the post model
|
|
this.attributes = this.pick(this.permittedAttributes);
|
|
},
|
|
|
|
roles: function () {
|
|
return this.belongsToMany(Role);
|
|
},
|
|
|
|
users: function () {
|
|
return this.belongsToMany(User);
|
|
}
|
|
});
|
|
|
|
Permissions = GhostBookshelf.Collection.extend({
|
|
model: Permission
|
|
});
|
|
|
|
module.exports = {
|
|
Permission: Permission,
|
|
Permissions: Permissions
|
|
}; |