From 40c59c2f16e44893893d13d8a1157179029fbf88 Mon Sep 17 00:00:00 2001 From: charitha Date: Wed, 16 Nov 2016 12:46:10 +0530 Subject: [PATCH] Fix issues in policy UI --- .../app/modules/business-controllers/user.js | 24 +++++++++++++++++++ .../jaggeryapps/devicemgt/app/modules/init.js | 14 ++++++----- .../public/js/policy-create.js | 9 ++----- .../units/cdmf.unit.policy.wizard/wizard.js | 2 +- 4 files changed, 35 insertions(+), 14 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 c94c1ff97a..0283fd214d 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 @@ -582,6 +582,30 @@ var userModule = function () { return permissions; }; + /** + * Add new role with permissions. + * + * @param roleName Name of the role + * @param users List of users to assign the role + * @param permissions List of permissions + */ + publicMethods.addRole = function (roleName, users, permissions) { + var carbon = require('carbon'); + var tenantId = carbon.server.tenantId(); + var url = carbon.server.address('https') + "/admin/services"; + var server = new carbon.server.Server(url); + var userManager = new carbon.user.UserManager(server, tenantId); + try { + if (!userManager.roleExists(roleName)) { + userManager.addRole(roleName, users, permissions); + } else { + log.info("Role exist with name: " + roleName); + } + } catch (e) { + throw e; + } + }; + publicMethods.addPermissions = function (permissionList, path, init) { var registry, carbon = require("carbon"); var carbonServer = application.get("carbonServer"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js index 1c367b38f5..bf5f26cac8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js @@ -19,7 +19,6 @@ var carbonModule = require("carbon"); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; -var utility = require("/app/modules/utility.js")["utility"]; //noinspection JSUnresolvedFunction Server var carbonServer = new carbonModule.server.Server({ @@ -29,9 +28,12 @@ var carbonServer = new carbonModule.server.Server({ application.put("carbonServer", carbonServer); -//var permissions = { -// "/permission/admin/device-mgt/user": ["ui.execute"], -// "/permission/admin/manage/api/subscribe": ["ui.execute"] -//}; +var permissions = { + "/permission/admin/device-mgt/devices": ["ui.execute"], + "/permission/admin/device-mgt/groups": ["ui.execute"], + "/permission/admin/device-mgt/notifications": ["ui.execute"], + "/permission/admin/device-mgt/policies": ["ui.execute"], + "/permission/admin/manage/api/subscribe": ["ui.execute"] +}; -//userModule.addRole("internal/devicemgt-user", ["admin"], permissions); +userModule.addRole("internal/devicemgt-user", ["admin"], permissions); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/policy-create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/policy-create.js index 4c838a1c48..ee2c805196 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/policy-create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/policy-create.js @@ -220,6 +220,7 @@ var savePolicy = function (policy, state) { "description": policy["description"], "compliance": policy["selectedNonCompliantAction"], "ownershipType": "ANY", + "active": (state != "save"), "profile": { "profileName": policy["policyName"], "deviceType": { @@ -239,14 +240,8 @@ var savePolicy = function (policy, state) { payload["roles"] = []; } - var serviceURL; - if (state == "save") { - serviceURL = "/devicemgt_admin/policies/inactive-policy" - } else if (state == "publish") { - serviceURL = "/devicemgt_admin/policies/active-policy" - } invokerUtil.post( - serviceURL, + "/api/device-mgt/v1.0/policies", payload, function (response) { response = JSON.parse(response); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.js index 49c02f84a8..dfe34da91c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.js @@ -22,7 +22,7 @@ function onRequest(context) { var DTYPE_CONF_DEVICE_TYPE_KEY = "deviceType"; var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label"; - var userModule = require("/app/modules/user.js")["userModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var utility = require('/app/modules/utility.js').utility; var response = userModule.getRoles(); var wizardPage = {};