From 47572d08f555999d1ecb9f5d9ebdbd444fd32dd6 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 25 Apr 2016 20:29:11 +0530 Subject: [PATCH 1/5] Removing obsolete dependencies to ApplicationManager interface from DeviceManagementService SPI --- .../common/spi/DeviceManagementService.java | 5 +-- .../mgt/core/TestDeviceManagementService.java | 35 ------------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java index 143fd1e8db..80bf030305 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java @@ -30,7 +30,7 @@ import java.util.List; * Composite interface that acts as the SPI exposing all device management as well as application management * functionalities. */ -public interface DeviceManagementService extends ApplicationManager { +public interface DeviceManagementService { /** * Method to retrieve the provider type that implements DeviceManager interface. @@ -58,6 +58,7 @@ public interface DeviceManagementService extends ApplicationManager { ApplicationManager getApplicationManager(); - void notifyOperationToDevices(Operation operation, List deviceIds) throws DeviceManagementException; + void notifyOperationToDevices(Operation operation, + List deviceIds) throws DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index c94a00fe8d..c3f15b7711 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -74,39 +74,4 @@ public class TestDeviceManagementService implements DeviceManagementService { } - @Override - public Application[] getApplications(String domain, int pageNumber, int size) - throws ApplicationManagementException { - return new Application[0]; - } - - @Override - public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, String status) - throws ApplicationManagementException { - - } - - @Override - public String getApplicationStatus(DeviceIdentifier deviceId, Application application) - throws ApplicationManagementException { - return null; - } - - @Override - public void installApplicationForDevices(Operation operation, List deviceIdentifiers) - throws ApplicationManagementException { - - } - - @Override - public void installApplicationForUsers(Operation operation, List userNameList) - throws ApplicationManagementException { - - } - - @Override - public void installApplicationForUserRoles(Operation operation, List userRoleList) - throws ApplicationManagementException { - - } } From f2ba20baeb5d1cfc71ad75d64a4ba4282ef15123 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 25 Apr 2016 20:42:10 +0530 Subject: [PATCH 2/5] Code cleanup --- .../device/mgt/core/TestDeviceManagementService.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index c3f15b7711..1e8c533d7e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -17,17 +17,12 @@ */ package org.wso2.carbon.device.mgt.core; -import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.app.mgt.Application; -import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; -import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; -import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; -import org.wso2.carbon.device.mgt.core.common.TestDataHolder; -import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import java.util.List; From a10a693507081539f03767dde61708a4e2b232a7 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 25 Apr 2016 21:07:57 +0530 Subject: [PATCH 3/5] Fixing find bugs reported issues --- .../org/wso2/carbon/device/mgt/common/EnrolmentInfo.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java index 7b3ff89d1f..eb37127d2e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java @@ -118,4 +118,10 @@ public class EnrolmentInfo implements Serializable { } return false; } + + @Override + public int hashCode() { + return owner.hashCode() ^ ownership.hashCode(); + } + } From aef892fece0b5a32ebc00c1d7d4870a4e46564e6 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 25 Apr 2016 21:08:14 +0530 Subject: [PATCH 4/5] Code cleanup --- .../mgt/TenantConfiguration.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/TenantConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/TenantConfiguration.java index 3f326d2000..ece6a23a78 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/TenantConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/TenantConfiguration.java @@ -28,29 +28,29 @@ import java.util.List; /** * Represents the tenant configuration for a device platform. */ -@XmlRootElement(name="tenantConfiguration") +@XmlRootElement(name = "tenantConfiguration") @XmlAccessorType(XmlAccessType.NONE) -public class TenantConfiguration implements Serializable{ +public class TenantConfiguration implements Serializable { - @XmlElement(name="type") - private String type; - @XmlElement(name="configuration") - private List configuration; + @XmlElement(name = "type") + private String type; + @XmlElement(name = "configuration") + private List configuration; - public String getType() { - return type; - } + public String getType() { + return type; + } - public void setType(String type) { - this.type = type; - } + public void setType(String type) { + this.type = type; + } - public List getConfiguration() { - return configuration; - } + public List getConfiguration() { + return configuration; + } - public void setConfiguration(List configuration) { - this.configuration = configuration; - } + public void setConfiguration(List configuration) { + this.configuration = configuration; + } } From dfb7e9a9c8267101a851c210f708f3687755a32a Mon Sep 17 00:00:00 2001 From: charithag Date: Mon, 25 Apr 2016 22:36:41 +0530 Subject: [PATCH 5/5] Fix permissions --- .../java/org/wso2/carbon/mdm/api/Group.java | 47 ++-- .../src/main/webapp/META-INF/permissions.xml | 229 ++++++++++++------ .../jaggeryapps/devicemgt/api/group-api.jag | 133 ---------- .../jaggeryapps/devicemgt/app/modules/init.js | 9 +- .../jaggeryapps/devicemgt/app/modules/user.js | 16 +- .../app/pages/cdmf.page.devices/devices.hbs | 2 +- .../cdmf.page.devices/public/js/listing.js | 31 +-- .../cdmf.page.groups/public/js/listing.js | 15 +- 8 files changed, 230 insertions(+), 252 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/mdm/api/Group.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/mdm/api/Group.java index 8c86419aea..71d91f97f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/mdm/api/Group.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/mdm/api/Group.java @@ -97,7 +97,7 @@ public class Group { } } - @Path("/{owner}/{groupName}") + @Path("/owner/{owner}/name/{groupName}") @PUT @Consumes("application/json") @Produces("application/json") @@ -112,7 +112,7 @@ public class Group { } } - @Path("/{owner}/{groupName}") + @Path("/owner/{owner}/name/{groupName}") @DELETE public Response deleteGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner) { try { @@ -160,7 +160,7 @@ public class Group { } } - @Path("/{owner}/{groupName}") + @Path("/owner/{owner}/name/{groupName}") @GET @Produces("application/json") public Response getGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner) { @@ -177,14 +177,14 @@ public class Group { } } - @Path("/search") + @Path("/user/{user}/search") @GET @Produces("application/json") public Response findGroups(@QueryParam("groupName") String groupName, - @QueryParam("userName") String userName) { + @PathParam("user") String user) { try { List groups = DeviceMgtAPIUtils.getGroupManagementProviderService() - .findInGroups(groupName, userName); + .findInGroups(groupName, user); DeviceGroup[] deviceGroups = new DeviceGroup[groups.size()]; groups.toArray(deviceGroups); return Response.status(Response.Status.OK).entity(deviceGroups).build(); @@ -216,6 +216,19 @@ public class Group { } } + @Path("/count") + @GET + @Produces("application/json") + public Response getAllGroupCount() { + try { + int count = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroupCount(); + return Response.status(Response.Status.OK).entity(count).build(); + } catch (GroupManagementException e) { + log.error(e.getMessage(), e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); + } + } + @Path("/user/{user}/count") @GET @Produces("application/json") @@ -229,7 +242,7 @@ public class Group { } } - @Path("/{owner}/{groupName}/share") + @Path("/owner/{owner}/name/{groupName}/share") @PUT @Produces("application/json") public Response shareGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner, @@ -250,7 +263,7 @@ public class Group { } } - @Path("/{owner}/{groupName}/unshare") + @Path("/owner/{owner}/name/{groupName}/unshare") @PUT @Produces("application/json") public Response unShareGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner, @@ -270,7 +283,7 @@ public class Group { } } - @Path("/{owner}/{groupName}/share/roles/{roleName}/permissions") + @Path("/owner/{owner}/name/{groupName}/share/roles/{roleName}/permissions") @PUT @Produces("application/json") public Response addSharing(@QueryParam("shareUser") String shareUser, @PathParam("groupName") String groupName, @@ -293,7 +306,7 @@ public class Group { } @DELETE - @Path("/{owner}/{groupName}/share/roles/{roleName}/permissions") + @Path("/owner/{owner}/name/{groupName}/share/roles/{roleName}/permissions") @Produces("application/json") public Response removeSharing(@QueryParam("userName") String userName, @PathParam("groupName") String groupName, @PathParam("owner") String owner, @@ -313,7 +326,7 @@ public class Group { } @GET - @Path("/{owner}/{groupName}/share/roles") + @Path("/owner/{owner}/name/{groupName}/share/roles") @Produces("application/json") public Response getRoles(@PathParam("groupName") String groupName, @PathParam("owner") String owner, @QueryParam("userName") String userName) { @@ -334,7 +347,7 @@ public class Group { } @GET - @Path("/{owner}/{groupName}/users") + @Path("/owner/{owner}/name/{groupName}/users") @Produces("application/json") public Response getUsers(@PathParam("groupName") String groupName, @PathParam("owner") String owner) { @@ -351,7 +364,7 @@ public class Group { } @GET - @Path("/{owner}/{groupName}/devices/all") + @Path("/owner/{owner}/name/{groupName}/devices/all") @Produces("application/json") public Response getDevices(@PathParam("groupName") String groupName, @PathParam("owner") String owner) { @@ -368,7 +381,7 @@ public class Group { } @GET - @Path("/{owner}/{groupName}/devices/count") + @Path("/owner/{owner}/name/{groupName}/devices/count") @Produces("application/json") public Response getDeviceCount(@PathParam("groupName") String groupName, @PathParam("owner") String owner) { @@ -382,7 +395,7 @@ public class Group { } @PUT - @Path("/{owner}/{groupName}/devices/{deviceType}/{deviceId}") + @Path("/owner/{owner}/name/{groupName}/devices/{deviceType}/{deviceId}") @Produces("application/json") public Response addDevice(@PathParam("groupName") String groupName, @PathParam("owner") String owner, @PathParam("deviceId") String deviceId, @@ -404,7 +417,7 @@ public class Group { } @DELETE - @Path("/{owner}/{groupName}/devices/{deviceType}/{deviceId}") + @Path("/owner/{owner}/name/{groupName}/devices/{deviceType}/{deviceId}") @Produces("application/json") public Response removeDevice(@PathParam("groupName") String groupName, @PathParam("owner") String owner, @PathParam("deviceId") String deviceId, @@ -425,7 +438,7 @@ public class Group { } @GET - @Path("/{owner}/{groupName}/users/{userName}/permissions") + @Path("/owner/{owner}/name/{groupName}/users/{userName}/permissions") @Produces("application/json") public Response getPermissions(@PathParam("userName") String userName, @PathParam("groupName") String groupName, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml index 42fd366369..e99164cdb2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml @@ -59,6 +59,13 @@ GET + + User Devices + /device-mgt/user/devices + / + GET + + Policies /device-mgt/admin/policies @@ -66,6 +73,13 @@ GET + + User Policies + /device-mgt/user/policies + / + GET + + Notifications /device-mgt/admin/notifications @@ -73,6 +87,13 @@ GET + + User Notifications + /device-mgt/user/notifications + / + GET + + Users /device-mgt/admin/users @@ -87,6 +108,13 @@ GET + + User Operations + /device-mgt/user/operations + / + GET + + Applications /device-mgt/admin/operations/applications @@ -123,12 +151,19 @@ - List devices + List device types /device-mgt/admin/devices/list /devices/types GET + + List device types + /device-mgt/user/devices/list + /devices/types + GET + + Add policy /device-mgt/admin/policies/add @@ -136,6 +171,13 @@ GET + + Add User policy + /device-mgt/user/policies/add + /devices/types + GET + + Edit policy /device-mgt/admin/policies/update @@ -143,6 +185,13 @@ GET + + Edit User policy + /device-mgt/user/policies/update + /devices/types + GET + + View device /device-mgt/admin/devices/view @@ -151,7 +200,7 @@ - View device + View user device /device-mgt/user/devices/view /devices/view GET @@ -173,12 +222,19 @@ - List devices + Devices Count All /device-mgt/admin/devices/list /devices/count GET + + Device Count + /device-mgt/user/devices/list + /devices/user/*/count + GET + + List devices /device-mgt/admin/devices/list @@ -501,19 +557,12 @@ - List devices + List user devices /device-mgt/user/devices/list /users/devices GET - - List devices - /device-mgt/admin/devices/list - /users/devices - GET - - View user /device-mgt/admin/users/view @@ -854,143 +903,185 @@ - Group Management + Group Management Admin /device-mgt/admin/groups + / + GET + + + + Group Management User + /device-mgt/user/groups + / + GET + + + + Add Group + /device-mgt/user/groups/add /groups POST - Group Management - /device-mgt/admin/groups - /groups/*/* + Group update + /device-mgt/user/groups/update + /groups/owner/*/name/* PUT - Group Management - /device-mgt/admin/groups - /groups/*/* + Group Delete + /device-mgt/user/groups/delete + /groups/owner/*/name/* DELETE - Group Management - /device-mgt/admin/groups + List All Groups + /device-mgt/admin/groups/list /groups GET - Group Management - /device-mgt/admin/groups + List Groups + /device-mgt/user/groups/list /groups/user/* GET - Group Management - /device-mgt/admin/groups - /groups/*/* + List Groups + /device-mgt/user/groups/list + /groups/user/*/all GET - Group Management - /device-mgt/admin/groups - /groups/search + View Group + /device-mgt/user/groups/view + /groups/owner/*/name/* GET - Group Management - /device-mgt/admin/groups - /groups/user/*/all + Search Group User + /device-mgt/user/groups/list + /groups/user/*/search GET - Group Management - /device-mgt/admin/groups + All Group Count + /device-mgt/admin/groups/list + /groups/count + GET + + + + Group Count + /device-mgt/user/groups/list /groups/user/*/count GET - Group Management - /device-mgt/admin/groups - /groups/*/*/share + Group Share + /device-mgt/user/groups/share + /groups/owner/*/name/*/share PUT - Group Management - /device-mgt/admin/groups - /groups/*/*/unshare + Group Unshare + /device-mgt/user/groups/unshare + /groups/owner/*/name/*/unshare PUT - Group Management - /device-mgt/admin/groups - /groups/*/*/share/roles/*/permissions + Group Roles + /device-mgt/user/groups/roles + /groups/owner/*/name/*/share/roles + GET + + + + Group Permissions + /device-mgt/admin/groups/roles/permissions + /groups/owner/*/name/*/share/roles/*/permissions + GET + + + + Group Add Permissions + /device-mgt/admin/groups/roles/permissions/add + /groups/owner/*/name/*/share/roles/*/permissions PUT - Group Management - /device-mgt/admin/groups - /groups/*/*/share/roles/*/permissions + Group Delete Permissions + /device-mgt/admin/groups/roles/permissions/delete + /groups/owner/*/name/*/share/roles/*/permissions DELETE - Group Management - /device-mgt/admin/groups - /groups/*/*/share/roles + Group Users + /device-mgt/user/groups/users + / GET - Group Management - /device-mgt/admin/groups - /groups/*/*/users + List Group Users + /device-mgt/user/groups/users/list + /groups/owner/*/name/*/users GET - Group Management - /device-mgt/admin/groups - /groups/*/*/devices/all + Get Permissions for Group + /device-mgt/user/groups/users/permissions + /groups/owner/*/name/*/users/*/permissions GET - Group Management - /device-mgt/admin/groups - /groups/*/*/devices/count + Group Devices + /device-mgt/user/groups/devices + / GET - Group Management - /device-mgt/admin/groups - /groups/*/*/devices/*/* - PUT + List Group Devices + /device-mgt/user/groups/devices/list + /groups/owner/*/name/*/devices/all + GET - Group Management - /device-mgt/admin/groups - /groups/*/*/devices/*/* - DELETE + Group Devices Count + /device-mgt/user/groups/devices/count + /groups/owner/*/name/*/devices/count + GET - Group Management - /device-mgt/admin/groups - /groups/*/*/users/*/permissions - GET + Add Device to Group + /device-mgt/user/groups/devices/add + /groups/owner/*/name/*/devices/*/* + PUT + + + + Remove Device from Group + /device-mgt/user/groups/devices/remove + /groups/owner/*/name/*/devices/*/* + DELETE diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag deleted file mode 100644 index 5795fb9df5..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag +++ /dev/null @@ -1,133 +0,0 @@ -<% -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var uri = request.getRequestURI(); -var uriMatcher = new URIMatcher(String(uri)); - -var log = new Log("apis/group-api.jag"); - -var constants = require("/app/modules/constants.js"); - -var utility = require("/app/modules/utility.js").utility; -var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); -var responseProcessor = require('utils').response; - -var deviceCloudService = devicemgtProps["httpsURL"] + "/common/group_manager"; - -var user = session.get(constants.USER_SESSION_KEY); - -var groupModule = require("/app/modules/group.js").groupModule; - -var result, endPoint, data, groupId, group, role; - -if (!user) { - response = responseProcessor.buildErrorResponse(response, 401, "Unauthorized"); -} else { - - if (uriMatcher.match("/{context}/api/group/add")) { - group = request.getContent(); - result = groupModule.addGroup(group); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/update")) { - groupId = uriMatcher.elements().groupId; - group = request.getContent(); - result = groupModule.updateGroup(groupId, group); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/remove")) { - groupId = uriMatcher.elements().groupId; - result = groupModule.removeGroup(groupId); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}")) { - groupId = uriMatcher.elements().groupId; - result = groupModule.getGroup(groupId); - - } else if (uriMatcher.match("/{context}/api/group/name/{groupName}")) { - var groupName = uriMatcher.elements().groupName; - result = groupModule.findGroups(groupName); - - } else if (uriMatcher.match("/{context}/api/group/all")) { - result = groupModule.getGroups(); - - } else if (uriMatcher.match("/{context}/api/group/all/count")) { - result = groupModule.getGroupCount(); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/share")) { - groupId = uriMatcher.elements().groupId; - var shareUser = request.getContent()["shareUser"]; - role = request.getContent()["role"]; - result = groupModule.shareGroup(groupId, shareUser, role); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/unshare")) { - groupId = uriMatcher.elements().groupId; - var unShareUser = request.getContent()["unShareUser"]; - role = request.getContent()["role"]; - result = groupModule.unshareGroup(groupId, unShareUser, role); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/add")) { - groupId = uriMatcher.elements().groupId; - var permissions = request.getContent()["permissions"]; - role = request.getContent()["role"]; - result = groupModule.addRole(groupId, role, permissions); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/delete")) { - groupId = uriMatcher.elements().groupId; - role = request.getContent()["role"]; - endPoint = deviceCloudService + "/group/id/" + groupId + "/role/" + role; - result = groupModule.deleteRole(groupId, role); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/all")) { - groupId = uriMatcher.elements().groupId; - result = groupModule.getGroupRoles(groupId); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/role/all")) { - groupId = uriMatcher.elements().groupId; - var userId = uriMatcher.elements().userId; - result = groupModule.getUserRoles(groupId, userId); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/rolemapping")) { - groupId = uriMatcher.elements().groupId; - userId = uriMatcher.elements().userId; - result = groupModule.getRoleMapping(groupId, userId); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/roleupdate")) { - groupId = uriMatcher.elements().groupId; - userId = uriMatcher.elements().userId; - var roleMap = request.getContent(); - result = groupModule.setRoleMapping(groupId, userId, roleMap); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/user/all")) { - groupId = uriMatcher.elements().groupId; - result = groupModule.getUsers(groupId); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/device/all")) { - groupId = uriMatcher.elements().groupId; - result = groupModule.getDevices(groupId); - - } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/assign")) { - groupId = uriMatcher.elements().groupId; - var deviceId = request.getContent()["deviceId"]; - var deviceType = request.getContent()["deviceType"]; - result = groupModule.assignDevice(groupId, deviceId, deviceType); - } -} -// returning the result. -if (result) { - print(result); -} -%> 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 2a22b1c987..2aa4bc8f62 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 @@ -28,13 +28,6 @@ var userModule = require("/app/modules/user.js")["userModule"]; var utility = require("/app/modules/utility.js")["utility"]; var permissions = { - '/permission/admin/device-mgt/devices': ['ui.execute'], - '/permission/admin/device-mgt/operations': ['ui.execute'], - '/permission/admin/device-mgt/policies': ['ui.execute'], - '/permission/admin/device-mgt/user': ['ui.execute'], - '/permission/admin/device-mgt/users': ['ui.execute'], - '/permission/admin/device-mgt/admin/devices': ['ui.execute'], - '/permission/admin/device-mgt/admin/groups': ['ui.execute'], - '/permission/admin/device-mgt/admin/policies': ['ui.execute'] + '/permission/admin/device-mgt/user': ['ui.execute'] }; userModule.addRole("devicemgt-user", ["admin"], permissions); 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 1c1139b3aa..a26e64de9c 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 @@ -632,7 +632,13 @@ var userModule = function () { if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) { permissions["LIST_DEVICES"] = true; } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) { + permissions["LIST_OWN_DEVICES"] = true; + } if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/list")) { + permissions["LIST_ALL_GROUPS"] = true; + } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/groups/list")) { permissions["LIST_GROUPS"] = true; } if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/list")) { @@ -642,9 +648,12 @@ var userModule = function () { permissions["LIST_ROLES"] = true; } if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/list")) { + permissions["LIST_ALL_POLICIES"] = true; + } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/policies/list")) { permissions["LIST_POLICIES"] = true; } - if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/add")) { + if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/groups/add")) { permissions["ADD_GROUP"] = true; } if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/add")) { @@ -656,7 +665,7 @@ var userModule = function () { if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/add")) { permissions["ADD_ROLE"] = true; } - if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/add")) { + if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/policies/add")) { permissions["ADD_POLICY"] = true; } if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/priority")) { @@ -668,9 +677,6 @@ var userModule = function () { if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/platform-configs/view")) { permissions["TENANT_CONFIGURATION"] = true; } - if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) { - permissions["LIST_OWN_DEVICES"] = true; - } return permissions; }; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs index e4663a57ba..20edeaf190 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs @@ -59,9 +59,9 @@
+ {{unit "cdmf.unit.device.operation-mod"}} {{#if deviceCount}} -
    diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index 767c37f684..8e19a542d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -383,18 +383,21 @@ function loadGroupedDevices(groupId) { } function initPage() { - var groupId = getParameterByName('groupId'); - invokerUtil.get( - "/devicemgt_admin/devices/count", + var deviceListing = $("#device-listing"); + var currentUser = deviceListing.data("currentUser"); + var serviceURL; + if ($.hasPermission("LIST_DEVICES")) { + serviceURL = "/devicemgt_admin/devices/count"; + } else if ($.hasPermission("LIST_OWN_DEVICES")) { + //Get authenticated users devices + serviceURL = "/devicemgt_admin/devices/user/"+currentUser+"/count"; + } + invokerUtil.get(serviceURL, function (data) { if (data) { data = JSON.parse(data); if (Number(data) > 0) { - if (groupId) { - loadGroupedDevices(groupId); - } else { - loadDevices(); - } + loadDevices(); } else { $("#loading-content").remove(); $("#device-listing-status-msg").text("No enrolled devices found."); @@ -411,20 +414,20 @@ function initPage() { * DOM ready functions. */ $(document).ready(function () { - - initPage(); - /* Adding selected class for selected devices */ $(deviceCheckbox).each(function () { addDeviceSelectedClass(this); }); - var i; var permissionList = $("#permission").data("permission"); - for (i = 0; i < permissionList.length; i++) { - $.setPermission(permissionList[i]); + for (var key in permissionList) { + if (permissionList.hasOwnProperty(key)){ + $.setPermission(key); + } } + initPage(); + /* for device list sorting drop down */ $(".ctrl-filter-type-switcher").popover({ html : true, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index 3bc47b0aff..2ba4f0cd35 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js @@ -271,6 +271,7 @@ function attachEvents() { $("a#remove-group-yes-link").click(function () { var successCallback = function (data) { + data = JSON.parse(data); if (data.status == 200) { $(modalPopupContent).html($('#remove-group-200-content').html()); setTimeout(function () { @@ -282,7 +283,7 @@ function attachEvents() { } }; - invokerUtil.delete("/devicemgt_admin/groups/" + groupOwner + "/" + groupName, + invokerUtil.delete("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName, successCallback, function (message) { displayErrors(message.content); }); @@ -315,6 +316,7 @@ function attachEvents() { var group = {"name": newGroupName, "description": newGroupDescription, "owner": groupOwner}; var successCallback = function (data) { + data = JSON.parse(data); if (data.status == 200) { $(modalPopupContent).html($('#edit-group-200-content').html()); $("h4[data-groupid='" + groupId + "']").html(newGroupName); @@ -326,7 +328,7 @@ function attachEvents() { } }; - invokerUtil.put("/devicemgt_admin/groups/" + groupOwner + "/" + groupName, + invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName, group, successCallback, function (message) { displayErrors(message.content); }); @@ -343,6 +345,7 @@ function getAllRoles(groupName, groupOwner, selectedUser) { $('#user-roles').html('
'); $("a#share-group-yes-link").hide(); var successCallback = function (data) { + data = JSON.parse(data); if (data.status == 200) { if (data.data.length > 0) { generateRoleMap(groupName, groupOwner, selectedUser, data.data); @@ -354,7 +357,7 @@ function getAllRoles(groupName, groupOwner, selectedUser) { } }; - invokerUtil.get("/devicemgt_admin/groups/" + groupOwner + "/" + groupName + "/share/roles", + invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles", successCallback, function (message) { displayErrors(message.content); }); @@ -366,6 +369,7 @@ function getAllRoles(groupName, groupOwner, selectedUser) { function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) { var successCallback = function (data) { + data = JSON.parse(data); if (data.status == 200) { var userRoles = data.data; var roleMap = []; @@ -407,7 +411,7 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) { } }; - invokerUtil.get("/devicemgt_admin/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser, + invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles?userName=" + selectedUser, successCallback, function (message) { displayErrors(message.content); }); @@ -419,6 +423,7 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) { function updateGroupShare(groupName, groupOwner, selectedUser, role) { var successCallback = function (data) { + data = JSON.parse(data); var status = data.status; if (status == 200) { $(modalPopupContent).html($('#share-group-200-content').html()); @@ -431,7 +436,7 @@ function updateGroupShare(groupName, groupOwner, selectedUser, role) { } }; - invokerUtil.put("/devicemgt_admin/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser, + invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles?userName=" + selectedUser, role, successCallback, function (message) { displayErrors(message.content); });