From 0b94a284ad7143f58ff6aa4f1d7a46fc2db0292a Mon Sep 17 00:00:00 2001 From: kamidu Date: Thu, 23 Mar 2017 12:23:21 +0530 Subject: [PATCH] new role filtering related fixes --- .../app/modules/business-controllers/user.js | 30 +++++++++++++++++-- .../pages/cdmf.page.dashboard/dashboard.js | 7 +++-- .../cdmf.page.roles/public/js/role-listing.js | 4 +-- 3 files changed, 35 insertions(+), 6 deletions(-) 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 d1b28389857..96f4d280bc6 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 @@ -302,6 +302,32 @@ var userModule = function () { } }; + /** + * Get User Roles from user store (Internal roles not included). + */ + publicMethods.getFilteredRoles = function (prefix) { + var carbonUser = session.get(constants["USER_SESSION_KEY"]); + var utility = require("/app/modules/utility.js")["utility"]; + if (!carbonUser) { + log.error("User object was not found in the session"); + throw constants["ERRORS"]["USER_NOT_FOUND"]; + } + try { + utility.startTenantFlow(carbonUser); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/roles/filter/" + prefix + "?offset=0&limit=100&user-store=all"; + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + if (response.status == "success") { + response.content = parse(response.content); + } + return response; + } catch (e) { + throw e; + } finally { + utility.endTenantFlow(); + } + }; + /** * Get User Roles count from user store (Internal roles not included). */ @@ -467,8 +493,8 @@ var userModule = function () { try { carbonUser = session.get(constants.USER_SESSION_KEY); } catch (e) { - log.error("User object was not found in the session"); - carbonUser = null; + log.error("User object was not found in the session"); + carbonUser = null; } var utility = require('/app/modules/utility.js').utility; if (!carbonUser) { 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 f52ce80319f..1d2d7c86076 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 @@ -39,8 +39,11 @@ function onRequest() { viewModel.groupCount = groupModule.getGroupCount(); viewModel.userCount = userModule.getUsersCount(); viewModel.policyCount = policyModule.getPoliciesCount(); - viewModel.roleCount = userModule.getRolesCount(); viewModel.isCloud = devicemgtProps.isCloud; - + if (devicemgtProps.isCloud) { + viewModel.roleCount = userModule.getFilteredRoles("devicemgt").content.count; + } else { + viewModel.roleCount = userModule.getRolesCount(); + } return viewModel; } \ No newline at end of file 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 0dd54ad2f85..88db2cbbb9a 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 @@ -98,7 +98,7 @@ function loadRoles() { var dataFilter = function (data) { data = JSON.parse(data); - + console.log(data); var objects = []; var count = 0; $(data.roles).each(function (index) { @@ -137,7 +137,7 @@ function loadRoles() { class: "", data: "name", render: function (name, type, row, meta) { - return '

' + name + '

'; + return '

' + name.replace("devicemgt", ""); + '

'; } }, {