From e53b0c386058b5e3a48e93bdb982342899b45534 Mon Sep 17 00:00:00 2001 From: charitha Date: Mon, 10 Oct 2016 20:00:39 +0530 Subject: [PATCH] Fix group count listing in dashboard --- .../jaxrs/service/api/GroupManagementService.java | 2 +- .../api/admin/GroupManagementAdminService.java | 1 + .../app/modules/business-controllers/group.js | 15 +++++++-------- .../app/modules/business-controllers/user.js | 4 ++-- .../app/pages/cdmf.page.dashboard/dashboard.js | 4 +--- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java index ce409aa02c..0fa5b9e0b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java @@ -53,7 +53,7 @@ import java.util.List; /** * Device group related REST-API. This can be used to manipulated device group related details. */ -@API(name = "Group Management", version = "1.0.0", context = "/api/device-mgt/v1.0/groups", tags = {"device_management"}) +@API(name = "GroupManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/groups", tags = {"device_management"}) @Path("/groups") @Api(value = "Device Group Management", description = "This API carries all device group management related operations " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java index 670fcab323..6757c471b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java @@ -106,6 +106,7 @@ public interface GroupManagementAdminService { value = "Maximum size of resource array to return.") @QueryParam("limit") int limit); + @Path("/count") @GET @ApiOperation( produces = MediaType.APPLICATION_JSON, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js index fcbeea8a5a..d4569b6804 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js @@ -26,8 +26,7 @@ var groupModule = {}; var utility = require("/app/modules/utility.js").utility; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; - var groupServiceEndpoint = devicemgtProps["httpsURL"] + - devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/groups"; + var deviceServiceEndpoint = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0"; var user = session.get(constants.USER_SESSION_KEY); @@ -36,26 +35,26 @@ var groupModule = {}; groupModule.getGroupCount = function () { var permissions = userModule.getUIPermissions(); if (permissions.LIST_ALL_GROUPS) { - endPoint = groupServiceEndpoint + "/count"; + endPoint = deviceServiceEndpoint + "/admin/groups/count"; } else if (permissions.LIST_GROUPS) { - endPoint = groupServiceEndpoint + "/user/" + user.username + "/count"; + endPoint = deviceServiceEndpoint + "/groups/count"; } else { log.error("Access denied for user: " + carbonUser.username); return -1; } return serviceInvokers.XMLHttp.get( endPoint, function (responsePayload) { - return responsePayload; + return responsePayload["responseText"]; }, function (responsePayload) { - log.error(responsePayload); + log.error(responsePayload["responseText"]); return -1; } ); }; groupModule.getGroupDeviceCount = function (groupName, owner) { - endPoint = groupServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices/count"; + endPoint = deviceServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices/count"; return serviceInvokers.XMLHttp.get( endPoint, function (responsePayload) { return responsePayload; @@ -68,7 +67,7 @@ var groupModule = {}; }; groupModule.getGroupDevices = function (groupName, owner) { - endPoint = groupServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices"; + endPoint = deviceServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices"; return serviceInvokers.XMLHttp.get( endPoint, function (responsePayload) { return responsePayload; 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 b229ab8ef8..8103c6b5bb 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 @@ -477,10 +477,10 @@ var userModule = function () { if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) { permissions["LIST_OWN_DEVICES"] = true; } - if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/list")) { + if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/view")) { permissions["LIST_ALL_GROUPS"] = true; } - if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/groups/list")) { + if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/view")) { permissions["LIST_GROUPS"] = true; } if (publicMethods.isAuthorized("/permission/admin/device-mgt/users/list")) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js index c848b86f6e..35a4eb0c05 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js @@ -36,9 +36,7 @@ function onRequest() { viewModel.permissions = permissions; viewModel.enrollmentURL = devicemgtProps.enrollmentURL; viewModel.deviceCount = deviceModule.getDevicesCount(); - //TODO: Enable Group Management Service API on CDMF - //page.group_count = groupModule.getGroupCount(); - viewModel.groupCount = -1; + viewModel.groupCount = groupModule.getGroupCount(); viewModel.userCount = userModule.getUsersCount(); viewModel.policyCount = policyModule.getPoliciesCount(); viewModel.roleCount = userModule.getRolesCount();