diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java index fb11549d5c2..0476ba4cde1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java @@ -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" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index b5c4370f328..088b29672f6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -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 { @@ -168,12 +166,12 @@ public class RoleManagementServiceImpl implements RoleManagementService { @Path("/{roleName}") @Override 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()) { 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 users) { + public Response updateUsersOfRole(@PathParam("roleName") String roleName, + @QueryParam("user-store") String userStoreName, List users) { + if (userStoreName != null && !userStoreName.isEmpty()) { + roleName = userStoreName + "/" + roleName; + } RequestValidationUtil.validateRoleName(roleName); RequestValidationUtil.validateUsers(users); try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index b74757d6781..36164975b29 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -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"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js index 93f7817db93..a5fb63e8766 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js @@ -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) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index ae0e40fd58f..1d9fdf30035 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -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 () { - $("#role-" + role).remove(); + 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(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js index 78560c15624..8dcdc85a433 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js @@ -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; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js index 3b6635dd9f5..940867904f5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js @@ -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 diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js index e038c32592b..a2c4161c0a2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js @@ -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,