2018-06-20 08:48:14 +10:00
|
|
|
const _ = require('underscore');
|
|
|
|
const Backbone = require('backbone');
|
|
|
|
|
|
|
|
const model = Backbone.Model.extend({
|
|
|
|
idAttribute: 'id',
|
|
|
|
|
|
|
|
defaults: function () {
|
|
|
|
return {
|
2018-08-16 13:08:56 +10:00
|
|
|
id: undefined,
|
2018-06-20 08:48:14 +10:00
|
|
|
name: '',
|
|
|
|
nickname: '',
|
|
|
|
email: '',
|
|
|
|
is_disabled: false,
|
2018-07-05 08:27:25 +10:00
|
|
|
roles: [],
|
|
|
|
permissions: null
|
2018-06-20 08:48:14 +10:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-07-09 11:22:10 +10:00
|
|
|
/**
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
2018-06-20 08:48:14 +10:00
|
|
|
isAdmin: function () {
|
|
|
|
return _.indexOf(this.get('roles'), 'admin') !== -1;
|
2018-07-09 11:22:10 +10:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the perm has either `view` or `manage` value
|
|
|
|
*
|
|
|
|
* @param {String} item
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
canView: function (item) {
|
|
|
|
let permissions = this.get('permissions');
|
|
|
|
return permissions !== null && typeof permissions[item] !== 'undefined' && ['view', 'manage'].indexOf(permissions[item]) !== -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the perm has `manage` value
|
|
|
|
*
|
|
|
|
* @param {String} item
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
canManage: function (item) {
|
|
|
|
let permissions = this.get('permissions');
|
|
|
|
return permissions !== null && typeof permissions[item] !== 'undefined' && permissions[item] === 'manage';
|
2018-06-20 08:48:14 +10:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Model: model,
|
|
|
|
Collection: Backbone.Collection.extend({
|
|
|
|
model: model
|
|
|
|
})
|
|
|
|
};
|