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" +
"NOTE: Don't delete the admin role",
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
@Path("/{roleName}/users")
@ -464,6 +469,11 @@ public interface RoleManagementService {
required = true,
defaultValue = "admin")
@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(
name = "users",
value = "Define the users that belong to the role.\n" +

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

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

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

@ -201,8 +201,15 @@ function loadRoles() {
*/
$("#role-grid").on("click", ".remove-role-link", function () {
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;
if (userStore) {
removeRoleAPI += "?user-store=" + userStore;
}
$(modalPopupContent).html($('#remove-role-modal-content').html());
showPopup();
@ -210,7 +217,11 @@ $("#role-grid").on("click", ".remove-role-link", function () {
invokerUtil.delete(
removeRoleAPI,
function () {
if (userStore) {
$("#role-" + userStore + "\\/" + role).remove();
} else {
$("#role-" + role).remove();
}
$(modalPopupContent).html($('#remove-role-success-content').html());
$("a#remove-role-success-link").click(function () {
hidePopup();

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

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

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

Loading…
Cancel
Save