52 lines
2.2 KiB
JavaScript
52 lines
2.2 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by viktor.shevchenko on 11/3/2014.
|
|
*/
|
|
function AccessMappingVO() {
|
|
}
|
|
// inherit BaseVO
|
|
AccessMappingVO.prototype = new BaseVO();
|
|
// correct the constructor pointer
|
|
AccessMappingVO.prototype.constructor = AccessMappingVO;
|
|
AccessMappingVO.prototype.getProps = function () {
|
|
var keys = Object.keys(new AccessMappingVO());
|
|
return BaseVO.prototype.getProps().concat(keys);
|
|
};
|
|
AccessMappingVO.prototype.parseAccessMap = function (accesses, type) {
|
|
var accessMappings = {};
|
|
if (type === EntityVO.TYPE_INCIDENT || type === EntityVO.TYPE_CHANGE
|
|
|| type === EntityVO.TYPE_WORKORDER || type === EntityVO.TYPE_TASK) {
|
|
var fields = _.filter(accesses, { type: 1 });
|
|
accesses = _.reject(accesses, { type: 1 });
|
|
accessMappings.fieldMappings = {};
|
|
_.forEach(fields, function (field) {
|
|
accessMappings.fieldMappings[field.id] = field.permission;
|
|
});
|
|
}
|
|
_.forEach(accesses, function (access) {
|
|
if (access.id) {
|
|
var accessMappingId = '';
|
|
if (access.id.indexOf('action') !== -1) {
|
|
accessMappingId = access.id.replace(/\-/g, '').replace('action', '') + 'ActionAllowed';
|
|
}
|
|
else if (access.id.indexOf('self-assignment') !== -1) {
|
|
accessMappingId = access.id.replace('self-assignment', '').replace(/\-/g, '') + 'SelfAssignmentAllowed';
|
|
}
|
|
else if (access.id.indexOf('add-approver') !== -1) {
|
|
accessMappingId = access.id.replace('add-approver', '').replace(/\-/g, '') + 'addApproverEditAllowed';
|
|
}
|
|
else {
|
|
accessMappingId = access.id + 'EditAllowed';
|
|
}
|
|
accessMappings[accessMappingId] = (access.permission === 'write');
|
|
if (accessMappingId === 'relationsEditAllowed') {
|
|
accessMappings['relationsDeleteAllowed'] = (access.permission === 'delete') ? true : accessMappings['relationsEditAllowed'];
|
|
}
|
|
if (accessMappings.fieldMappings && !accessMappings.fieldMappings[access.id]) {
|
|
accessMappings.fieldMappings[access.id] = access.permission;
|
|
}
|
|
}
|
|
});
|
|
return accessMappings;
|
|
};
|