2018-06-19 18:48:14 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const _ = require('underscore');
|
|
|
|
const Backbone = require('backbone');
|
|
|
|
|
|
|
|
const model = Backbone.Model.extend({
|
|
|
|
idAttribute: 'id',
|
|
|
|
|
|
|
|
defaults: function () {
|
|
|
|
return {
|
2018-07-18 19:47:55 -04:00
|
|
|
id: 0,
|
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
|
|
|
|
})
|
|
|
|
};
|