2018-06-19 18:48:14 -04:00
|
|
|
const _ = require('underscore');
|
|
|
|
const Backbone = require('backbone');
|
|
|
|
|
|
|
|
const model = Backbone.Model.extend({
|
|
|
|
idAttribute: 'id',
|
|
|
|
|
|
|
|
defaults: function () {
|
|
|
|
return {
|
2018-08-15 23:08:56 -04:00
|
|
|
id: undefined,
|
2018-06-19 18:48:14 -04:00
|
|
|
name: '',
|
|
|
|
nickname: '',
|
|
|
|
email: '',
|
|
|
|
is_disabled: false,
|
2018-07-04 18:27:25 -04:00
|
|
|
roles: [],
|
|
|
|
permissions: null
|
2018-06-19 18:48:14 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-07-08 21:22:10 -04:00
|
|
|
/**
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
2018-06-19 18:48:14 -04:00
|
|
|
isAdmin: function () {
|
|
|
|
return _.indexOf(this.get('roles'), 'admin') !== -1;
|
2018-07-08 21:22:10 -04: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-19 18:48:14 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Model: model,
|
|
|
|
Collection: Backbone.Collection.extend({
|
|
|
|
model: model
|
|
|
|
})
|
|
|
|
};
|