2013-06-25 15:43:15 +04:00
|
|
|
var GhostBookshelf = require('./base'),
|
|
|
|
User = require('./user').User,
|
|
|
|
Role = require('./role').Role,
|
|
|
|
Permission,
|
|
|
|
Permissions;
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +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
|
|
|
|
2013-09-14 23:01:46 +04:00
|
|
|
permittedAttributes: ['id', 'uuid', 'name', 'object_type', 'action_type', 'object_id', 'created_at', 'created_by',
|
|
|
|
'updated_at', 'updated_by'],
|
2013-08-25 14:49:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
validate: function () {
|
|
|
|
// TODO: validate object_type, action_type and object_id
|
|
|
|
GhostBookshelf.validator.check(this.get('name'), "Permission name cannot be blank").notEmpty();
|
|
|
|
},
|
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
roles: function () {
|
|
|
|
return this.belongsToMany(Role);
|
|
|
|
},
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
users: function () {
|
|
|
|
return this.belongsToMany(User);
|
|
|
|
}
|
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
Permissions = GhostBookshelf.Collection.extend({
|
|
|
|
model: Permission
|
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
module.exports = {
|
|
|
|
Permission: Permission,
|
|
|
|
Permissions: Permissions
|
|
|
|
};
|