From ec3f5afcb7232f1945fb9c76472c79f750c3eb25 Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Sat, 19 Oct 2019 12:18:02 +0530 Subject: [PATCH] Prevent same policy ID bieng avaialble in selecting a corrective policy --- .../public/js/policy-create.js | 2 +- .../app/units/cdmf.unit.policy.edit/edit.js | 14 +++++++++++++- .../cdmf.unit.policy.edit/public/js/policy-edit.js | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/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.create/public/js/policy-create.js index 16085c4b77..90f59b1f89 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/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.create/public/js/policy-create.js @@ -276,7 +276,7 @@ stepForwardFrom["policy-type"] = function () { var correctiveActionList = []; if (policy.type === "GENERAL") { var selectedCorrectivePolicyId = $("#corrective-policy-input").val(); - if (selectedCorrectivePolicyId !== "none") { + if (selectedCorrectivePolicyId && selectedCorrectivePolicyId !== "none") { var correctiveAction = { "actionType": "POLICY", "policyId": selectedCorrectivePolicyId diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.js index 1474a895cf..be04a6aa7c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.js @@ -35,6 +35,7 @@ function onRequest(context) { var deviceType = request.getParameter("deviceType"); + var policyId = request.getParameter("id"); var utility = require("/app/modules/utility.js").utility; var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; @@ -84,7 +85,18 @@ function onRequest(context) { var enrollmentApps = policyModule.getStoreAppsForPolicy(); context["storeApps"] = JSON.stringify(enrollmentApps["content"]); - context["correctivePolicies"] = JSON.stringify(policyModule.getAllPoliciesByType("CORRECTIVE")["content"]); + var correctivePolicies = policyModule.getAllPoliciesByType("CORRECTIVE")["content"]; + if (correctivePolicies) { + var i; + for (i = 0; i < correctivePolicies.length; i++) { + if (correctivePolicies[i].id.toString() === policyId) { + correctivePolicies.splice(i, 1); + break; + } + } + } + + context["correctivePolicies"] = JSON.stringify(correctivePolicies); return context; } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/public/js/policy-edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/public/js/policy-edit.js index eabcfbca38..061b02b0c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/public/js/policy-edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/public/js/policy-edit.js @@ -282,7 +282,7 @@ stepForwardFrom["policy-profile"] = function () { } var policyType = currentlyEffected.policyType; - $("input[name=policy-type-radio-btn][value=" + policyType + "]").prop("checked", true); + $("input[name=policy-type-radio-btn][value=" + policyType + "]").prop("checked", true).trigger('change'); // add policy correction action page if (!isCorrectiveActionProfileAdded) { @@ -336,7 +336,7 @@ stepForwardFrom["policy-type"] = function () { var correctiveActionList = []; if (policy.type === "GENERAL") { var selectedCorrectivePolicyId = $("#corrective-policy-input").val(); - if (selectedCorrectivePolicyId !== "none") { + if (selectedCorrectivePolicyId && selectedCorrectivePolicyId !== "none") { var correctiveAction = { "actionType": "POLICY", "policyId": selectedCorrectivePolicyId