From bcbde92143ac1703c1f6eda28ea0f9cbc7838b07 Mon Sep 17 00:00:00 2001 From: charithag Date: Wed, 27 Apr 2016 15:40:49 +0530 Subject: [PATCH] Update new analytics components. --- .../devicemgt/app/modules/device.js | 52 +++++------ .../devicemgt/app/modules/group.js | 9 +- .../jaggeryapps/devicemgt/app/modules/user.js | 3 + .../pages/cdmf.page.dashboard/dashboard.js | 2 +- .../app/pages/cdmf.page.devices/devices.js | 7 +- .../public/templates/listing.hbs | 87 ------------------- 6 files changed, 40 insertions(+), 120 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/templates/listing.hbs diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js index 43ee2fc82ce..367db085bc6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js @@ -258,32 +258,34 @@ deviceModule = function () { }; // Refactored methods - publicMethods.getOwnDevicesCount = function () { + publicMethods.getDevicesCount = function () { var carbonUser = session.get(constants.USER_SESSION_KEY); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + carbonUser.username - + "/count"; - return serviceInvokers.XMLHttp.get( - url, function (responsePayload) { - return responsePayload; - }, - function (responsePayload) { - log.error(responsePayload); - return -1; - } - ); - }; - - publicMethods.getAllDevicesCount = function () { - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/count"; - return serviceInvokers.XMLHttp.get( - url, function (responsePayload) { - return responsePayload; - }, - function (responsePayload) { - log.error(responsePayload); - return -1; - } - ); + if (carbonUser) { + var userModule = require("/app/modules/user.js").userModule; + var uiPermissions = userModule.getUIPermissions(); + var url; + if (uiPermissions.LIST_DEVICES) { + url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/count"; + } else if (uiPermissions.LIST_OWN_DEVICES) { + url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + carbonUser.username + + "/count"; + } else { + log.error("Access denied for user: " + carbonUser.username); + return -1; + } + return serviceInvokers.XMLHttp.get( + url, function (responsePayload) { + return responsePayload; + }, + function (responsePayload) { + log.error(responsePayload); + return -1; + } + ); + } else { + log.error("User object was not found in the session"); + throw constants["ERRORS"]["USER_NOT_FOUND"]; + } }; publicMethods.getDeviceTypes = function () { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js index 9ad1b2001b3..3d050b38a15 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js @@ -38,12 +38,14 @@ var groupModule = {}; endPoint = groupServiceEndpoint + "/count"; } else if (permissions.LIST_GROUPS) { endPoint = groupServiceEndpoint + "/user/" + user.username + "/count"; + } else { + log.error("Access denied for user: " + carbonUser.username); + return -1; } return serviceInvokers.XMLHttp.get( endPoint, function (responsePayload) { return responsePayload; - } - , + }, function (responsePayload) { log.error(responsePayload); return -1; @@ -56,8 +58,7 @@ var groupModule = {}; return serviceInvokers.XMLHttp.get( endPoint, function (responsePayload) { return responsePayload; - } - , + }, function (responsePayload) { log.error(responsePayload); return -1; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js index a26e64de9c8..bca48a0362c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js @@ -653,6 +653,9 @@ var userModule = function () { if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/policies/list")) { permissions["LIST_POLICIES"] = true; } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/add")) { + permissions["ADD_DEVICE"] = true; + } if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/groups/add")) { permissions["ADD_GROUP"] = true; } 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 bb2c02374ef..82aa1101a6d 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 @@ -35,7 +35,7 @@ function onRequest(context) { var groupModule = require("/app/modules/group.js").groupModule; var policyModule = require("/app/modules/policy.js").policyModule; - page.device_count = deviceModule.getAllDevicesCount(); + page.device_count = deviceModule.getDevicesCount(); page.group_count = groupModule.getGroupCount(); page.user_count = userModule.getUsers()["content"].length; page.policy_count = policyModule.getAllPolicies()["content"].length; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js index 0dbaa5cff02..851fec3688f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js @@ -34,8 +34,9 @@ function onRequest(context) { var currentUser = session.get(constants.USER_SESSION_KEY); if (currentUser) { page.permissions = {}; - page.permissions.list = stringify(userModule.getUIPermissions()); - if (userModule.isAuthorized("/permission/admin/device-mgt/user/devices/add")) { + var uiPermissions = userModule.getUIPermissions(); + page.permissions.list = stringify(uiPermissions); + if (uiPermissions.ADD_DEVICE) { page.permissions.enroll = true; } page.currentUser = currentUser; @@ -45,7 +46,7 @@ function onRequest(context) { deviceCount = groupModule.getGroupDeviceCount(groupName, groupOwner); page.groupOwner = groupOwner; } else { - deviceCount = deviceModule.getOwnDevicesCount(); + deviceCount = deviceModule.getDevicesCount(); } if (deviceCount > 0) { page.deviceCount = deviceCount; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/templates/listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/templates/listing.hbs deleted file mode 100644 index 07965cfd667..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/templates/listing.hbs +++ /dev/null @@ -1,87 +0,0 @@ -{{#each devices}} - {{deviceMap this}} - - -
- -
- - -

{{name}}

- {{#if properties.VENDOR}} -
({{properties.VENDOR}} - {{properties.DEVICE_MODEL}})
- {{/if}} - - {{enrolmentInfo.owner}} - - {{#equal enrolmentInfo.status "ACTIVE"}} Active{{/equal}} - {{#equal enrolmentInfo.status "INACTIVE"}} Inactive{{/equal}} - {{#equal enrolmentInfo.status "BLOCKED"}} Blocked{{/equal}} - {{#equal enrolmentInfo.status "REMOVED"}} Removed{{/equal}} - - {{type}} - - {{enrolmentInfo.ownership}} - - - {{#unequal enrolmentInfo.status "REMOVED"}} - - - - - - - - - - - - - - - {{#unless ../../isGroupView}} - - - - - - - - {{/unless}} - - - - - - - - - - - - - - - {{/unequal}} - - -{{/each}}