Fixing secondary role deletion

revert-70aa11f8
Megala 8 years ago
parent 2195a164e5
commit 87150f5074

@ -404,7 +404,12 @@ public interface RoleManagementService {
value = "The name of the role that needs to de deleted.\n" + value = "The name of the role that needs to de deleted.\n" +
"NOTE: Don't delete the admin role", "NOTE: Don't delete the admin role",
required = true) required = true)
@PathParam("roleName") String roleName); @PathParam("roleName") String roleName,
@ApiParam(
name = "user-store",
value = "The name of the UserStore you wish to get the list of roles.",
required = false)
@QueryParam("user-store") String userStoreName);
@PUT @PUT
@Path("/{roleName}/users") @Path("/{roleName}/users")
@ -464,6 +469,11 @@ public interface RoleManagementService {
required = true, required = true,
defaultValue = "admin") defaultValue = "admin")
@PathParam("roleName") String roleName, @PathParam("roleName") String roleName,
@ApiParam(
name = "user-store",
value = "The name of the UserStore you wish to get the list of roles.",
required = false)
@QueryParam("user-store") String userStoreName,
@ApiParam( @ApiParam(
name = "users", name = "users",
value = "Define the users that belong to the role.\n" + value = "Define the users that belong to the role.\n" +

@ -93,12 +93,10 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@GET @GET
@Path("/{roleName}/permissions") @Path("/{roleName}/permissions")
@Override @Override public Response getPermissionsOfRole(@PathParam("roleName") String roleName,
public Response getPermissionsOfRole( @QueryParam("user-store") String userStoreName, @HeaderParam("If-Modified-Since") String ifModifiedSince) {
@PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
if (userStoreName != null && !userStoreName.isEmpty()) { if (userStoreName != null && !userStoreName.isEmpty()) {
roleName = userStoreName + '/' + roleName; roleName = userStoreName + "/" + roleName;
} }
RequestValidationUtil.validateRoleName(roleName); RequestValidationUtil.validateRoleName(roleName);
try { try {
@ -168,12 +166,12 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@Path("/{roleName}") @Path("/{roleName}")
@Override @Override
public Response getRole(@PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName, public Response getRole(@PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName,
@HeaderParam("If-Modified-Since") String ifModifiedSince) { @HeaderParam("If-Modified-Since") String ifModifiedSince) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the list of user roles"); log.debug("Getting the list of user roles");
} }
if (userStoreName != null && !userStoreName.isEmpty()) { if (userStoreName != null && !userStoreName.isEmpty()) {
roleName = userStoreName + '/' + roleName; roleName = userStoreName + "/" + roleName;
} }
RequestValidationUtil.validateRoleName(roleName); RequestValidationUtil.validateRoleName(roleName);
RoleInfo roleInfo = new RoleInfo(); RoleInfo roleInfo = new RoleInfo();
@ -254,10 +252,11 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@PUT @PUT
@Path("/{roleName}") @Path("/{roleName}")
@Override public Response updateRole(@PathParam("roleName") String roleName, RoleInfo roleInfo, @Override
public Response updateRole(@PathParam("roleName") String roleName, RoleInfo roleInfo,
@QueryParam("user-store") String userStoreName) { @QueryParam("user-store") String userStoreName) {
if (userStoreName != null && !userStoreName.isEmpty()) { if (userStoreName != null && !userStoreName.isEmpty()) {
roleName = userStoreName + '/' + roleName; roleName = userStoreName + "/" + roleName;
} }
RequestValidationUtil.validateRoleName(roleName); RequestValidationUtil.validateRoleName(roleName);
RequestValidationUtil.validateRoleDetails(roleInfo); RequestValidationUtil.validateRoleDetails(roleInfo);
@ -315,7 +314,10 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@DELETE @DELETE
@Path("/{roleName}") @Path("/{roleName}")
@Override @Override
public Response deleteRole(@PathParam("roleName") String roleName) { public Response deleteRole(@PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName) {
if (userStoreName != null && !userStoreName.isEmpty()) {
roleName = userStoreName + "/" + roleName;
}
RequestValidationUtil.validateRoleName(roleName); RequestValidationUtil.validateRoleName(roleName);
try { try {
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
@ -346,7 +348,11 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@PUT @PUT
@Path("/{roleName}/users") @Path("/{roleName}/users")
@Override @Override
public Response updateUsersOfRole(@PathParam("roleName") String roleName, List<String> users) { public Response updateUsersOfRole(@PathParam("roleName") String roleName,
@QueryParam("user-store") String userStoreName, List<String> users) {
if (userStoreName != null && !userStoreName.isEmpty()) {
roleName = userStoreName + "/" + roleName;
}
RequestValidationUtil.validateRoleName(roleName); RequestValidationUtil.validateRoleName(roleName);
RequestValidationUtil.validateUsers(users); RequestValidationUtil.validateUsers(users);
try { try {

@ -268,7 +268,7 @@ var userModule = function () {
try { try {
utility.startTenantFlow(carbonUser); utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles?offset=0&limit=100"; "/roles?offset=0&limit=100&user-store=all";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") { if (response.status == "success") {
response.content = parse(response.content).roles; response.content = parse(response.content).roles;
@ -294,7 +294,7 @@ var userModule = function () {
try { try {
utility.startTenantFlow(carbonUser); utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles?offset=0&limit=1"; "/roles?offset=0&limit=1&user-store=all";
return serviceInvokers.XMLHttp.get( return serviceInvokers.XMLHttp.get(
url, function (responsePayload) { url, function (responsePayload) {
return parse(responsePayload["responseText"])["count"]; return parse(responsePayload["responseText"])["count"];

@ -201,7 +201,7 @@ $(document).ready(function () {
$("input#roleName").val(""); $("input#roleName").val("");
$("#domain").val("PRIMARY"); $("#domain").val("PRIMARY");
$("#users").val(""); $("#users").val("");
window.location.href = appContext + "/role/edit-permission/" + roleName; window.location.href = appContext + "/role/edit-permission/" + addRoleFormData.roleName;
} }
}, },
function (jqXHR) { function (jqXHR) {

@ -201,8 +201,15 @@ function loadRoles() {
*/ */
$("#role-grid").on("click", ".remove-role-link", function () { $("#role-grid").on("click", ".remove-role-link", function () {
var role = $(this).data("role"); var role = $(this).data("role");
var userStore;
if (role.indexOf('/') > 0) {
userStore = role.substr(0, role.indexOf('/'));
role = role.substr(role.indexOf('/') + 1);
}
var removeRoleAPI = apiBasePath + "/roles/" + role; var removeRoleAPI = apiBasePath + "/roles/" + role;
if (userStore) {
removeRoleAPI += "?user-store=" + userStore;
}
$(modalPopupContent).html($('#remove-role-modal-content').html()); $(modalPopupContent).html($('#remove-role-modal-content').html());
showPopup(); showPopup();
@ -210,7 +217,11 @@ $("#role-grid").on("click", ".remove-role-link", function () {
invokerUtil.delete( invokerUtil.delete(
removeRoleAPI, removeRoleAPI,
function () { function () {
$("#role-" + role).remove(); if (userStore) {
$("#role-" + userStore + "\\/" + role).remove();
} else {
$("#role-" + role).remove();
}
$(modalPopupContent).html($('#remove-role-success-content').html()); $(modalPopupContent).html($('#remove-role-success-content').html());
$("a#remove-role-success-link").click(function () { $("a#remove-role-success-link").click(function () {
hidePopup(); hidePopup();

@ -159,16 +159,14 @@ $(document).ready(function () {
roleName = roleName.substr(roleName.indexOf('/') + 1); roleName = roleName.substr(roleName.indexOf('/') + 1);
} }
var updateRolePermissionAPI = apiBasePath + "/roles/" + roleName; var updateRolePermissionAPI = apiBasePath + "/roles/" + roleName;
if (userStore) {
updateRolePermissionAPI += "?user-store=" + userStore;
}
var updateRolePermissionData = {}; var updateRolePermissionData = {};
var perms = []; var perms = [];
$("#permissionList li input:checked").each(function(){ $("#permissionList li input:checked").each(function(){
perms.push($(this).data("resourcepath")); perms.push($(this).data("resourcepath"));
}); });
if (userStore) { if (userStore) {
updateRolePermissionData.roleName = userStore + roleName; updateRolePermissionAPI += "?user-store=" + userStore;
updateRolePermissionData.roleName = userStore + "/" + roleName;
} else { } else {
updateRolePermissionData.roleName = roleName; updateRolePermissionData.roleName = roleName;
} }

@ -35,7 +35,7 @@ function onRequest(context) {
var userStore; var userStore;
if (isMatched) { if (isMatched) {
if (uriMatcher.match( uriMatcher.match("/{context}/role/edit/{roleName}"))) { if (uriMatcher.match("/{context}/role/edit/{roleName}")) {
matchedElements = uriMatcher.elements(); matchedElements = uriMatcher.elements();
roleName = matchedElements["roleName"]; roleName = matchedElements["roleName"];
response = userModule.getRole(roleName); response = userModule.getRole(roleName);
@ -43,19 +43,24 @@ function onRequest(context) {
context["role"] = response["content"]; context["role"] = response["content"];
} }
userStore = "PRIMARY"; userStore = "PRIMARY";
} else if (uriMatcher.match( uriMatcher.match("/{context}/role/edit/{userStoreName}/{roleName}"))) { } else if (uriMatcher.match("/{context}/role/edit/{userStoreName}/{roleName}")) {
matchedElements = uriMatcher.elements(); matchedElements = uriMatcher.elements();
roleName = matchedElements["userStoreName"] + "/" + matchedElements["roleName"]; roleName = matchedElements["roleName"];
response = userModule.getRole(roleName); userStore = matchedElements["userStoreName"];
response = userModule.getRole(userStore + "/" + roleName);
if (response["status"] == "success") { if (response["status"] == "success") {
context["role"] = response["content"]; context["role"] = response["content"];
} }
userStore = matchedElements["userStoreName"];
} }
context["userStore"] = userStore; context["userStore"] = userStore;
context["roleNameJSRegEx"] = deviceMgtProps["roleValidationConfig"]["roleNameJSRegEx"]; context["roleNameJSRegEx"] = deviceMgtProps["roleValidationConfig"]["roleNameJSRegEx"];
context["roleNameHelpText"] = deviceMgtProps["roleValidationConfig"]["roleNameHelpMsg"]; context["roleNameHelpText"] = deviceMgtProps["roleValidationConfig"]["roleNameHelpMsg"];
context["roleNameRegExViolationErrorMsg"] = deviceMgtProps["roleValidationConfig"]["roleNameRegExViolationErrorMsg"]; context["roleNameRegExViolationErrorMsg"] = deviceMgtProps["roleValidationConfig"]["roleNameRegExViolationErrorMsg"];
roleName = context["role"]["roleName"];
if (roleName.indexOf("/") > -1) {
context["role"]["roleName"] = roleName.substr(roleName.indexOf("/") + 1);
}
return context; return context;
} else { } else {
//TODO: handle error scenario //TODO: handle error scenario

@ -163,11 +163,11 @@ $(document).ready(function () {
} else { } else {
var addRoleFormData = {}; var addRoleFormData = {};
addRoleFormData.roleName = roleName; addRoleFormData.roleName = roleName;
var addRoleAPI = apiBasePath + "/roles/" + currentRoleName;
if (domain != "PRIMARY"){ if (domain != "PRIMARY"){
addRoleFormData.roleName = domain + "/" + roleName; addRoleFormData.roleName = domain + "/" + roleName;
addRoleAPI = addRoleAPI + "?user-store=" + domain;
} }
var addRoleAPI = apiBasePath + "/roles/" + currentRoleName;
invokerUtil.put( invokerUtil.put(
addRoleAPI, addRoleAPI,
addRoleFormData, addRoleFormData,

Loading…
Cancel
Save