webapp.scripts.components.entities.permission.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of centraldogma-server Show documentation
Show all versions of centraldogma-server Show documentation
Highly-available version-controlled service configuration repository based on Git, ZooKeeper and HTTP/2 (centraldogma-server)
'use strict';
angular.module('CentralDogmaAdmin')
.factory('Permission', function () {
function Permission() {
this.elements = [];
}
Permission.prototype = {
pushNew: function () {
this.elements.push({
name: null,
read: false,
write: false
});
},
remove: function (perm) {
this.elements = this.elements.filter(function (value) {
return value !== perm;
});
},
validate: function (perm) {
// If 'write' is permitted, 'read' should also be permitted.
if (perm.write === true) {
perm.read = true;
}
}
};
Permission.toSet = function (perm) {
var set = [];
if (perm.read === true) {
set.push('READ');
}
if (perm.write === true) {
set.push('WRITE');
}
return set;
};
Permission.toRequest = function (name, perm) {
return {
id: name,
permissions: Permission.toSet(perm)
};
};
Permission.makePermissionTable = function (permissionMap) {
var permTable = {};
Object.entries(permissionMap).forEach(function (entry) {
const permSet = new Set(entry[1]);
permTable[entry[0]] = {
read: permSet.has('READ'),
write: permSet.has('WRITE')
};
});
return permTable;
};
return (Permission);
});