diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java index 6dd76e1823..75fd081d96 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java @@ -35,6 +35,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupShare; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupUsersList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo; import javax.validation.Valid; import javax.ws.rs.Consumes; @@ -467,6 +468,65 @@ public interface GroupManagementService { required = true) @PathParam("groupId") int groupId); + + @Path("id/{groupId}/roles/create") + @POST + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = HTTPConstants.HEADER_GET, + value = "Create a group sharing role to a device group.", + notes = "Group sharing is done through a group sharing role.", + tags = "Device Group Management") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK. \n Successfully created the role.", + response = DeviceGroupUsersList.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client has already the latest version of " + + "the requested resource."), + @ApiResponse( + code = 404, + message = "No groups found.", + response = ErrorResponse.class), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while creating the role.", + response = ErrorResponse.class) + }) + @Permission(name = "Create roles", permission = "/device-mgt/groups/roles/create") + Response createGroupSharingRole( + @ApiParam( + name = "groupId", + value = "ID of the group.", + required = true) + @PathParam("groupId") int groupId, + @ApiParam( + name = "userName", + value = "User name of the current user.", + required = false) + @QueryParam("userName") String userName, + @ApiParam( + name = "roleInfo", + value = "Group role information with permissions and users", + required = true) + @Valid RoleInfo roleInfo); + @Path("/id/{groupId}/roles") @GET @ApiOperation( @@ -621,7 +681,7 @@ public interface GroupManagementService { required = true) @PathParam("groupId") int groupId); - @Path("/id/{groupId}/devices") + @Path("/id/{groupId}/devices/add") @POST @ApiOperation( produces = MediaType.APPLICATION_JSON, @@ -672,8 +732,8 @@ public interface GroupManagementService { required = true) @Valid List deviceIdentifiers); - @Path("/id/{groupId}/devices") - @DELETE + @Path("/id/{groupId}/devices/remove") + @POST @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = HTTPConstants.HEADER_DELETE, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index 06569d21cf..845cf11b82 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -408,6 +408,40 @@ public interface UserManagementService { @Permission(name = "View Users", permission = "/device-mgt/users/view") Response getUserCount(); + @GET + @Path("/checkUser") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting the User existence status", + notes = "Check if the user exists in the user store.", + tags = "User Management") + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched user exist status.", + response = BasicUserInfoList.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body") + }), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching the total user exist status.", + response = ErrorResponse.class) + }) + @Permission(name = "View Users", permission = "/device-mgt/users/view") + Response isUserExists(@ApiParam( + name = "username", + value = "The username of the user.", + required = true) + @QueryParam("username") String userName); + @GET @Path("/search/usernames") @ApiOperation( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java index ed0264feda..90208d4409 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java @@ -38,7 +38,8 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.*; import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; -import org.wso2.carbon.user.core.UserStoreException; +import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.user.core.multiplecredentials.UserDoesNotExistException; import javax.ws.rs.core.Response; @@ -200,11 +201,32 @@ public class GroupManagementServiceImpl implements GroupManagementService { } } + @Override + public Response createGroupSharingRole(int groupId, String userName, RoleInfo roleInfo) { + try { + DeviceMgtAPIUtils.getGroupManagementProviderService() + .addGroupSharingRole(userName, groupId, roleInfo.getRoleName(), roleInfo.getPermissions()); + return Response.status(Response.Status.CREATED).build(); + } catch (GroupManagementException e) { + String msg = "Error occurred while creating group sharing role."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + @Override public Response getRolesOfGroup(int groupId, String userName) { try { List groupRoles; if(userName != null) { + UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); + if (!userStoreManager.isExistingUser(userName)) { + // returning response with bad request state + return Response.status(Response.Status.CONFLICT).entity( + new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " + + userName + " doesn't exists. Therefore, request made to get user " + + "was refused.").build()).build(); + } groupRoles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(userName, groupId); } else { groupRoles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(groupId); @@ -275,8 +297,7 @@ public class GroupManagementServiceImpl implements GroupManagementService { } } - @Override - public Response removeDevicesFromGroup(int groupId, List deviceIdentifiers) { + @Override public Response removeDevicesFromGroup(int groupId, List deviceIdentifiers) { try { DeviceMgtAPIUtils.getGroupManagementProviderService().removeDevice(groupId, deviceIdentifiers); return Response.status(Response.Status.OK).build(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 8fc57a0c89..96d0cf2c12 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -359,6 +359,25 @@ public class UserManagementServiceImpl implements UserManagementService { } } + @GET + @Path("/checkUser") + @Override public Response isUserExists(@QueryParam("username") String userName) { + try { + UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); + boolean userExists = false; + if (userStoreManager.isExistingUser(userName)) { + userExists = true; + return Response.status(Response.Status.OK).entity(userExists).build(); + } else { + return Response.status(Response.Status.OK).entity(userExists).build(); + } + } catch (UserStoreException e) { + String msg = "Error while retrieving the user."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + @GET @Path("/search/usernames") @Override 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 950b9158bc..de3c30a739 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 @@ -512,9 +512,33 @@ var userModule = function () { if (publicMethods.isAuthorized("/permission/admin/device-mgt/users/add")) { permissions["ADD_USER"] = true; } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/devices/add")) { + permissions["ADD_GROUP_DEVICES"] = true; + } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/devices/remove")) { + permissions["REMOVE_GROUP_DEVICES"] = true; + } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/devices/view")) { + permissions["VIEW_GROUP_DEVICES"] = true; + } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/roles/create")) { + permissions["CREATE_GROUP_ROLES"] = true; + } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/roles/view")) { + permissions["VIEW_GROUP_ROLES"] = true; + } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/update")) { + permissions["UPDATE_GROUP"] = true; + } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/share")) { + permissions["SHARE_GROUP"] = true; + } if (publicMethods.isAuthorized("/permission/admin/device-mgt/users/remove")) { permissions["REMOVE_USER"] = true; } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/remove")) { + permissions["REMOVE_GROUP"] = true; + } if (publicMethods.isAuthorized("/permission/admin/device-mgt/roles/add")) { permissions["ADD_ROLE"] = true; } 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 b225f9c983..7cf43cc2af 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 @@ -190,21 +190,39 @@ {{/if}}
- @@ -273,6 +291,25 @@
+
+ + + +
+