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

admin/curatorprivileges is using radio button

parent 371b0eeb
......@@ -86,10 +86,6 @@ EditUserDialog.prototype.createGui = function () {
name: "DETAILS",
content: self.createGeneralTabContent()
});
guiUtils.addTab(self, {
name: "GLOBAL PRIVILEGES",
content: self.createPrivilegesTabContent()
});
guiUtils.addTab(self, {
name: "PROJECT PRIVILEGES",
content: self.createProjectsTabContent()
......@@ -199,47 +195,40 @@ EditUserDialog.prototype.createGeneralTabContent = function () {
}
}
});
return result;
};
/**
*
* @returns {HTMLElement}
*/
EditUserDialog.prototype.createPrivilegesTabContent = function () {
var self = this;
var result = Functions.createElement({
type: "div",
style: "margin-top:10px;"
});
result.appendChild(self._createPrivilegesTable());
return result;
};
/**
*
* @returns {HTMLElement}
* @private
*/
EditUserDialog.prototype._createPrivilegesTable = function () {
var result = Functions.createElement({
type: "div",
style: "margin-top:10px;"
$(result).on('change', '[name="user-can-create-overlay"]', function () {
if ($(this).is(":checked")) {
return self.grantPrivilege({privilegeType: PrivilegeType.CAN_CREATE_OVERLAYS});
} else {
return self.revokePrivilege({privilegeType: PrivilegeType.CAN_CREATE_OVERLAYS});
}
});
var privilegesTable = Functions.createElement({
type: "table",
name: "privilegesTable",
className: "display",
style: "width:100%"
});
result.appendChild(privilegesTable);
$(result).on("click", "[name='userRole']", function () {
var field = this;
var role = $('[name="user-role-' + self.getUser().getLogin() + '"]:checked', field).val();
var promises = [];
if (role === "ADMIN") {
promises.push(self.grantPrivilege({privilegeType: PrivilegeType.IS_ADMIN}));
promises.push(self.revokePrivilege({privilegeType: PrivilegeType.IS_CURATOR}));
$("[name='user-can-create-overlay-div']", result).css("display", "none");
} else if (role === "CURATOR") {
promises.push(self.revokePrivilege({privilegeType: PrivilegeType.IS_ADMIN}));
promises.push(self.grantPrivilege({privilegeType: PrivilegeType.IS_CURATOR}));
$("[name='user-can-create-overlay-div']", result).css("display", "none");
} else if (role === "USER") {
promises.push(self.revokePrivilege({privilegeType: PrivilegeType.IS_ADMIN}));
promises.push(self.revokePrivilege({privilegeType: PrivilegeType.IS_CURATOR}));
$("[name='user-can-create-overlay-div']", result).css("display", "block");
} else {
GuiConnector.alert("Invalid role: " + role);
}
return Promise.all(promises);
}
);
return result;
};
/**
*
* @returns {HTMLElement}
......@@ -303,7 +292,6 @@ EditUserDialog.prototype.init = function () {
});
self.initProjectsTab();
self.initPrivilegesTab();
return self.refresh().then(function () {
$(window).trigger('resize');
......@@ -331,11 +319,48 @@ EditUserDialog.prototype.refresh = function () {
data.push(['Surname', '<input name="userSurname" value="' + getStringIfDefined(user.getSurname()) + '"/>']);
data.push(['Email', '<input name="userEmail" value="' + getStringIfDefined(user.getEmail()) + '"/>']);
var userRoleId = 'user-role-' + user.getLogin();
var adminChecked = '';
var curatorChecked = '';
var userChecked = '';
var canCreateOverlayDisplay = "none";
var canCreateOverlayChecked = "";
if (self.getIsNewUser()) {
var option = self.getConfiguration().getOption('DEFAULT_' + PrivilegeType.CAN_CREATE_OVERLAYS);
if (option !== null && option !== undefined) {
if (option.getValue().toLowerCase() === "true") {
user.setPrivilege({privilegeType: PrivilegeType.CAN_CREATE_OVERLAYS});
}
}
}
if (user.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.CAN_CREATE_OVERLAYS))) {
canCreateOverlayChecked = " checked ";
}
if (user.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.IS_ADMIN))) {
adminChecked = " checked ";
} else if (user.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.IS_CURATOR))) {
curatorChecked = " checked ";
} else {
canCreateOverlayDisplay = "block";
userChecked = " checked ";
}
data.push(["Role",
"<fieldset name='userRole' id='" + userRoleId + "'> " +
"<input type='radio' name='" + userRoleId + "' value='ADMIN' " + adminChecked + "> ADMIN<br/>" +
"<input type='radio' name='" + userRoleId + "' value='CURATOR' " + curatorChecked + "> CURATOR<br/>" +
"<input type='radio' name='" + userRoleId + "' value='USER' " + userChecked + "> USER <br/>" +
"<div name='user-can-create-overlay-div' style='display:" + canCreateOverlayDisplay + ";'>" +
"<input type='checkbox' style='float:left; ' name='user-can-create-overlay' " + canCreateOverlayChecked + "> User can create overlays " +
"</div>" +
"</fieldset>"]);
dataTable.clear().rows.add(data).draw();
return self.refreshProjects().then(function () {
return self.refreshPrivilegesTab();
});
return self.refreshProjects();
};
/**
......@@ -385,36 +410,6 @@ EditUserDialog.prototype.initProjectsTab = function () {
});
};
/**
*
*/
EditUserDialog.prototype.initPrivilegesTab = function () {
var self = this;
var privilegesTable = $("[name=privilegesTable]", self.getElement())[0];
var columns = [{
title: "Name"
}, {
title: "Value"
}];
$(privilegesTable).DataTable({
columns: columns
});
$(privilegesTable).on("click", "[name='privilege-checkbox']", function () {
var data = $(this).attr("data").split(":");
var type = data[0];
var projectId = data[1];
if ($(this).is(":checked")) {
return self.grantPrivilege({privilegeType: type, objectId: projectId});
} else {
return self.revokePrivilege({privilegeType: type, objectId: projectId});
}
});
};
/**
*
* @param {Authority} privilege
......@@ -453,45 +448,6 @@ EditUserDialog.prototype.revokePrivilege = function (privilege) {
}
};
/**
*
*/
EditUserDialog.prototype.refreshPrivilegesTab = function () {
var self = this;
var dataTable = $("[name=privilegesTable]", self.getElement()).DataTable();
var data = [];
var configuration = self.getConfiguration();
for (var i = 0; i < configuration.getPrivilegeTypes().length; i++) {
var privilege = configuration.getPrivilegeTypes()[i];
var option;
if (privilege.getObjectType() === null) {
if (privilege.getValueType() === "boolean") {
var checked = "";
if (self.getUser().hasPrivilege(privilege)) {
checked = "checked"
} else if (this.getIsNewUser()) {
option = this.getConfiguration().getOption('DEFAULT_' + privilege.getName());
if (option !== null && option !== undefined) {
if (option.getValue().toLowerCase() === "true") {
self.getUser().setPrivilege({privilegeType: privilege.getName()});
checked = "checked";
}
}
}
data.push([
"<span>" + privilege.getCommonName() + "</span>",
"<input type='checkbox' name='privilege-checkbox' data='" + privilege.getName() + "' " + checked + " />"
]);
} else {
throw new Error("Not implemented");
}
}
}
dataTable.clear().rows.add(data).draw();
};
/**
*
* @returns {Promise}
......@@ -593,11 +549,6 @@ EditUserDialog.prototype.destroy = function () {
$(usersTable).DataTable().destroy();
}
var privilegesTable = $("[name=privilegesTable]", div)[0];
if ($.fn.DataTable.isDataTable(privilegesTable)) {
$(privilegesTable).DataTable().destroy();
}
var detailsTable = $("[name=detailsTable]", div)[0];
if ($.fn.DataTable.isDataTable(detailsTable)) {
$(detailsTable).DataTable().destroy();
......
......@@ -138,11 +138,12 @@ describe('EditUserDialog', function () {
dialog = createEditUserDialog(user);
return dialog.init();
}).then(function () {
var checkbox = $("[name=privilege-checkbox]", dialog.getElement())[0];
var checkbox = $("[name=user-can-create-overlay]", dialog.getElement())[0];
checkbox.checked = !checkbox.checked;
return helper.triggerJqueryEvent(checkbox, "click");
return helper.triggerJqueryEvent(checkbox, "change");
}).then(function () {
expect(serializedPrivileges).not.to.deep.equal(user.getPrivileges());
}).finally(function(){
dialog.destroy();
});
});
......
{"connectedToLdap":false,"email":"","id":3,"ldapAccountAvailable":false,"login":"anonymous","maxColor":null,"minColor":null,"name":"","neutralColor":null,"privileges":[{"objectId":null,"privilegeType":"CAN_CREATE_OVERLAYS"}, {"objectId":"empty","privilegeType":"READ_PROJECT"},{"objectId":"parameter","privilegeType":"READ_PROJECT"},{"objectId":"drug_target_sample","privilegeType":"READ_PROJECT"},{"objectId":"GSTP1_subnetwork_220214","privilegeType":"READ_PROJECT"},{"objectId":"pdmap_jun16_test","privilegeType":"READ_PROJECT"},{"objectId":"CDlayerin_v2-semantic","privilegeType":"READ_PROJECT"},{"objectId":"PD_150625_3","privilegeType":"READ_PROJECT"},{"objectId":"doi","privilegeType":"READ_PROJECT"},{"objectId":"complex_model_with_images","privilegeType":"READ_PROJECT"},{"objectId":"complex_model_with_submaps","privilegeType":"READ_PROJECT"},{"objectId":"images","privilegeType":"READ_PROJECT"},{"objectId":"kinteics_test","privilegeType":"READ_PROJECT"},{"objectId":"species_with_boundary_cond","privilegeType":"READ_PROJECT"},{"objectId":"sample","privilegeType":"READ_PROJECT"},{"objectId":"complex_model_with_layouts","privilegeType":"READ_PROJECT"},{"objectId":"pdmap_jan17","privilegeType":"READ_PROJECT"},{"objectId":"ASTHMA_V40_Test9","privilegeType":"READ_PROJECT"},{"objectId":"CDlayerin_v2","privilegeType":"READ_PROJECT"}],"removed":false,"simpleColor":null,"surname":"","termsOfUseConsent":false}
\ No newline at end of file
{"connectedToLdap":false,"email":"","id":3,"ldapAccountAvailable":false,"login":"anonymous","maxColor":null,"minColor":null,"name":"","neutralColor":null,"privileges":[{"objectId":null,"privilegeType":"IS_ADMIN"}, {"objectId":"empty","privilegeType":"READ_PROJECT"},{"objectId":"parameter","privilegeType":"READ_PROJECT"},{"objectId":"drug_target_sample","privilegeType":"READ_PROJECT"},{"objectId":"GSTP1_subnetwork_220214","privilegeType":"READ_PROJECT"},{"objectId":"pdmap_jun16_test","privilegeType":"READ_PROJECT"},{"objectId":"CDlayerin_v2-semantic","privilegeType":"READ_PROJECT"},{"objectId":"PD_150625_3","privilegeType":"READ_PROJECT"},{"objectId":"doi","privilegeType":"READ_PROJECT"},{"objectId":"complex_model_with_images","privilegeType":"READ_PROJECT"},{"objectId":"complex_model_with_submaps","privilegeType":"READ_PROJECT"},{"objectId":"images","privilegeType":"READ_PROJECT"},{"objectId":"kinteics_test","privilegeType":"READ_PROJECT"},{"objectId":"species_with_boundary_cond","privilegeType":"READ_PROJECT"},{"objectId":"sample","privilegeType":"READ_PROJECT"},{"objectId":"complex_model_with_layouts","privilegeType":"READ_PROJECT"},{"objectId":"pdmap_jan17","privilegeType":"READ_PROJECT"},{"objectId":"ASTHMA_V40_Test9","privilegeType":"READ_PROJECT"},{"objectId":"CDlayerin_v2","privilegeType":"READ_PROJECT"}],"removed":false,"simpleColor":null,"surname":"","termsOfUseConsent":false}
\ No newline at end of file
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