1
0
mirror of https://github.com/NginxProxyManager/nginx-proxy-manager.git synced 2025-08-31 01:01:09 +03:00
Files
nginx-proxy-manager/src/frontend/js/models/user.js
Jamie Curnow 291cb9625e More i18n
2018-07-19 09:47:55 +10:00

57 lines
1.4 KiB
JavaScript

'use strict';
const _ = require('underscore');
const Backbone = require('backbone');
const model = Backbone.Model.extend({
idAttribute: 'id',
defaults: function () {
return {
id: 0,
name: '',
nickname: '',
email: '',
is_disabled: false,
roles: [],
permissions: null
};
},
/**
* @returns {Boolean}
*/
isAdmin: function () {
return _.indexOf(this.get('roles'), 'admin') !== -1;
},
/**
* 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';
}
});
module.exports = {
Model: model,
Collection: Backbone.Collection.extend({
model: model
})
};