From c61cd484a0391d41a51395da854adf7f669e0388 Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Tue, 29 Nov 2016 18:34:25 +0530 Subject: [PATCH] IOTS-296: Adding group selection capability when adding a policy This commit introduces the device group select capabilty and saving the policy when creating and editing policies. --- .../device/mgt/jaxrs/beans/PolicyWrapper.java | 13 +++ .../impl/PolicyManagementServiceImpl.java | 1 + .../app/modules/business-controllers/group.js | 26 +++++ .../units/cdmf.unit.policy.create/create.hbs | 22 +++++ .../units/cdmf.unit.policy.create/create.js | 12 +++ .../public/js/policy-create.js | 48 +++++++++ .../app/units/cdmf.unit.policy.edit/edit.hbs | 98 ++++++++++++------- .../app/units/cdmf.unit.policy.edit/edit.js | 8 +- .../public/js/policy-edit.js | 54 ++++++++++ 9 files changed, 246 insertions(+), 36 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java index c0c768eeb2..e7ef0c0e6e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper; import javax.validation.constraints.Size; import java.util.List; @@ -75,6 +76,10 @@ public class PolicyWrapper { required = true) private List users; + @ApiModelProperty(name = "deviceGroups", value = "Lists out the groups on whose devices the policy is enforced", + required = true) + private List deviceGroups; + public Profile getProfile() { return profile; } @@ -147,4 +152,12 @@ public class PolicyWrapper { this.users = users; } + public List getDeviceGroups() { + return deviceGroups; + } + + public void setDeviceGroups(List deviceGroups) { + this.deviceGroups = deviceGroups; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index 3934ceedf1..16e7a8eb06 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -122,6 +122,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { policy.setRoles(policyWrapper.getRoles()); policy.setUsers(policyWrapper.getUsers()); policy.setCompliance(policyWrapper.getCompliance()); + policy.setDeviceGroups(policyWrapper.getDeviceGroups()); //TODO iterates the device identifiers to create the object. need to implement a proper DAO layer here. List devices = new ArrayList(); List deviceIdentifiers = policyWrapper.getDeviceIdentifiers(); 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 5862f6bc8e..fefd73bd0b 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 @@ -79,4 +79,30 @@ var groupModule = {}; ); }; + groupModule.getGroups = function () { + var permissions = userModule.getUIPermissions(); + if (permissions.LIST_ALL_GROUPS) { + endPoint = deviceServiceEndpoint + "/admin/groups"; + } else if (permissions.LIST_GROUPS) { + endPoint = deviceServiceEndpoint + "/groups"; + } else { + log.error("Access denied for user: " + carbonUser.username); + return -1; + } + return serviceInvokers.XMLHttp.get( + endPoint, function (responsePayload) { + var data = JSON.parse(responsePayload.responseText); + if(data) { + return data.deviceGroups; + } else { + return []; + } + }, + function (responsePayload) { + log.error(responsePayload); + return -1; + } + ); + }; + }(groupModule)); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs index 50d5548c1d..32e124a9a4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs @@ -1,5 +1,7 @@ {{#zone "content"}} {{#if isAuthorized}} +
@@ -188,6 +190,26 @@
{{/if}} + {{#if isAuthorizedViewGroups}} + +
+
+
+ + +
+
+
+
+ {{/if}}