Commit 70854400 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

privilege type changed

parent 903e0f81
......@@ -115,8 +115,8 @@ CommentsAdminPanel.prototype.refreshComments = function () {
var writeAccess = self.getConfiguration().getPrivilegeType(PrivilegeType.WRITE_PROJECT);
var isAdmin = self.getConfiguration().getPrivilegeType(PrivilegeType.IS_ADMIN);
var disable = true;
if (user.hasPrivilege(writeAccess, self.getProject().getId()) || user.hasPrivilege(isAdmin)) {
disable = true;
if (user.hasPrivilege(writeAccess, self.getProject().getProjectId()) || user.hasPrivilege(isAdmin)) {
disable = false;
}
var dataTable = $($("[name='commentsTable']", self.getElement())[0]).DataTable();
......
......@@ -870,7 +870,7 @@ EditProjectDialog.prototype.userToTableRow = function (user, columns) {
if (column.privilegeType !== undefined) {
if (column.privilegeType.getValueType() === "boolean") {
var checked = '';
if (user.hasPrivilege(column.privilegeType, self.getProject().getId())) {
if (user.hasPrivilege(column.privilegeType, self.getProject().getProjectId())) {
checked = 'checked';
}
row[i] = "<input type='checkbox' name='privilege" + "' data='" + column.privilegeType.getName() + "," + login + "' "
......@@ -901,7 +901,10 @@ EditProjectDialog.prototype.overlayToTableRow = function (overlay, users) {
}
var disabled = " disabled ";
if (loggedUser.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.LAYOUT_MANAGEMENT), self.getProject().getId())) {
var isAdmin = loggedUser.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.IS_ADMIN));
var isCurator = loggedUser.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.IS_CURATOR)) &&
loggedUser.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.WRITE_PROJECT), self.getProject().getProjectId());
if (isAdmin || isCurator) {
disabled = "";
}
......
......@@ -358,32 +358,32 @@ EditUserDialog.prototype.initProjectsTab = function () {
var data = $(this).attr("data").split("-");
var privilegeType = data[0];
var objectId = data[1];
var value = $(this).is(":checked") ? 1 : 0;
for (var i = 0; i < configuration.getPrivilegeTypes().length; i++) {
var privilege = configuration.getPrivilegeTypes()[i];
if (privilege.getName() === privilegeType) {
self.getUser().setPrivilege({type: privilege, value: value, objectId: objectId});
if ($(this).is(":checked")) {
return self.grantPrivilege({type: privilege, objectId: objectId});
} else {
return self.revokePrivilege({type: privilege, objectId: objectId});
}
}
}
if (!self.getIsNewUser()) {
return self.updateUser();
}
});
$("[name='defaultProjectsRow']", self.getElement()).on("click", "[name='project-privilege-checkbox']", function () {
var data = $(this).attr("data").split("-");
var privilegeType = data[0];
var objectId = data[1];
var value = $(this).is(":checked") ? 1 : 0;
var objectId = "*";
for (var i = 0; i < configuration.getPrivilegeTypes().length; i++) {
var privilege = configuration.getPrivilegeTypes()[i];
if (privilege.getName() === privilegeType) {
self.getUser().setPrivilege({type: privilege, value: value, objectId: objectId});
if ($(this).is(":checked")) {
return self.grantPrivilege({type: privilege, objectId: objectId});
} else {
return self.revokePrivilege({type: privilege, objectId: objectId});
}
}
}
if (!self.getIsNewUser()) {
return self.updateUser();
}
});
};
......@@ -471,20 +471,8 @@ EditUserDialog.prototype.refreshPrivilegesTab = function () {
"<span>" + privilege.getCommonName() + "</span>",
"<input type='checkbox' name='privilege-checkbox' data='" + privilege.getName() + "' " + checked + " />"
]);
} else if (privilege.getValueType() === "int") {
var value = self.getUser().getPrivilegeValue(privilege);
if (this.getIsNewUser()) {
option = this.getConfiguration().getOption('DEFAULT_' + privilege.getName());
if (option !== null && option !== undefined) {
value = parseInt(option.getValue());
self.getUser().setPrivilege({type: privilege, value: value});
}
}
data.push([
"<span>" + privilege.getCommonName() + "</span>",
"<input name='privilege-int' data='" + privilege.getName() + "' value='" + value + "' />"
]);
} else {
throw new Error("Not implemented");
}
}
}
......@@ -562,14 +550,14 @@ EditUserDialog.prototype.projectToTableRow = function (project, columns) {
for (var i = 1; i < columns.length; i++) {
var privilege = columns[i].privilegeType;
var checked = "";
if (user.hasPrivilege(privilege, id)) {
if (user.hasPrivilege(privilege, projectId)) {
checked = "checked";
} else if (this.getIsNewUser()) {
var option = this.getConfiguration().getOption('DEFAULT_' + privilege.getName());
if (option !== null && option !== undefined) {
if (option.getValue().toLowerCase() === "true") {
user.setPrivilege({type: privilege, objectId: id});
user.setPrivilege({type: privilege, objectId: projectId});
checked = "checked";
}
}
......
......@@ -230,7 +230,7 @@ GenomeAdminPanel.prototype.genomeToTableRow = function (genome, user) {
row[4] = genome.getSourceUrl();
var disabled = " disabled ";
if (user.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.MANAGE_GENOMES))) {
if (user.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.IS_ADMIN))) {
disabled = "";
}
row[5] = "<button name='editGenome' data='" + genome.getId() + "'" + disabled + "><i class='fa fa-edit' style='font-size:17px'></i></button>";
......
......@@ -245,19 +245,30 @@ User.prototype.getPreferences = function () {
/**
*
* @param {PrivilegeType} type
* @param {number} [objectId]
* @param {number|string} [objectId]
* @returns {boolean}
*/
User.prototype.hasPrivilege = function (type, objectId) {
return this.getPrivilegeValue(type, objectId) > 0;
if (objectId===undefined) {
objectId = null;
}
for (var i = 0; i < this._privileges.length; i++) {
var privilege = this._privileges[i];
if (privilege.privilegeType === type.getName()) {
if (objectId === privilege.objectId) {
return true;
}
}
}
return false;
};
/**
*
* @param {Object} params
* @param {number} [params.objectId]
* @param {number|string} [params.objectId]
* @param {PrivilegeType} params.type
* @param {number} [params.value=1]
* @param {boolean} [params.value=true]
*/
User.prototype.setPrivilege = function (params) {
var objectId = params.objectId;
......@@ -286,25 +297,6 @@ User.prototype.setPrivilege = function (params) {
});
};
/**
*
* @param {PrivilegeType} type
* @param {number} [objectId]
*
* @returns {number}
*/
User.prototype.getPrivilegeValue = function (type, objectId) {
for (var i = 0; i < this._privileges.length; i++) {
var privilege = this._privileges[i];
if (privilege.type === type.getName()) {
if (objectId === privilege.objectId) {
return privilege.value;
}
}
}
return 0;
};
/**
*
* @param {Configuration} configuration
......@@ -321,14 +313,14 @@ User.prototype.privilegesToExport = function (configuration) {
}
for (i = 0; i < self.getPrivileges().length; i++) {
var privilege = self.getPrivileges()[i];
if (validTypes[privilege.type]) {
if (result[privilege.type] === undefined) {
result[privilege.type] = {};
if (validTypes[privilege.privilegeType]) {
if (result[privilege.privilegeType] === undefined) {
result[privilege.privilegeType] = {};
}
if (privilege.objectId !== undefined) {
result[privilege.type][privilege.objectId] = privilege.value;
result[privilege.privilegeType][privilege.objectId] = privilege.value;
} else {
result[privilege.type] = privilege.value;
result[privilege.privilegeType] = privilege.value;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment