From 5c13e18b6a5b338b6e90a8a9f7a22b6fa294f332 Mon Sep 17 00:00:00 2001 From: Sonia Zorba <sonia.zorba@inaf.it> Date: Wed, 17 Mar 2021 18:47:14 +0100 Subject: [PATCH] Added optional recursive parameter to list groups endpoint --- .../main/java/it/inaf/ia2/gms/client/GmsClient.java | 4 ++-- .../it/inaf/ia2/gms/client/call/ListGroupsCall.java | 5 +++-- .../inaf/ia2/gms/client/call/GetUserGroupsTest.java | 4 ++-- .../ia2/gms/controller/JWTWebServiceController.java | 13 ++++++++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/gms-client/gms-client/src/main/java/it/inaf/ia2/gms/client/GmsClient.java b/gms-client/gms-client/src/main/java/it/inaf/ia2/gms/client/GmsClient.java index 304df22..5560987 100644 --- a/gms-client/gms-client/src/main/java/it/inaf/ia2/gms/client/GmsClient.java +++ b/gms-client/gms-client/src/main/java/it/inaf/ia2/gms/client/GmsClient.java @@ -98,8 +98,8 @@ public class GmsClient extends BaseClient { }).orElse(super.getInvalidStatusCodeExceptionMessage(request, response)); } - public List<String> listGroups(String prefix) { - return new ListGroupsCall(this).listGroups(prefix); + public List<String> listGroups(String prefix, boolean recursive) { + return new ListGroupsCall(this).listGroups(prefix, recursive); } public List<String> getUserGroups(String userId) { diff --git a/gms-client/gms-client/src/main/java/it/inaf/ia2/gms/client/call/ListGroupsCall.java b/gms-client/gms-client/src/main/java/it/inaf/ia2/gms/client/call/ListGroupsCall.java index 2c3123e..f032d9c 100644 --- a/gms-client/gms-client/src/main/java/it/inaf/ia2/gms/client/call/ListGroupsCall.java +++ b/gms-client/gms-client/src/main/java/it/inaf/ia2/gms/client/call/ListGroupsCall.java @@ -19,14 +19,15 @@ public class ListGroupsCall extends BaseCall<GmsClient> { * the privileges to see that information). The prefix is removed by the * service. */ - public List<String> listGroups(String prefix) { + public List<String> listGroups(String prefix, boolean recursive) { List<String> groups = new ArrayList<>(); - String uri = "ws/jwt/list"; + String uri = "list"; if (prefix != null && !prefix.isBlank()) { uri += "/" + prefix; } + uri += "?recursive=" + recursive; HttpRequest groupsRequest = client.newRequest(uri) .header("Accept", "text/plain") diff --git a/gms-client/gms-client/src/test/java/it/inaf/ia2/gms/client/call/GetUserGroupsTest.java b/gms-client/gms-client/src/test/java/it/inaf/ia2/gms/client/call/GetUserGroupsTest.java index 3b2dee6..d7cde9f 100644 --- a/gms-client/gms-client/src/test/java/it/inaf/ia2/gms/client/call/GetUserGroupsTest.java +++ b/gms-client/gms-client/src/test/java/it/inaf/ia2/gms/client/call/GetUserGroupsTest.java @@ -50,9 +50,9 @@ public class GetUserGroupsTest extends BaseGmsClientTest { CompletableFuture response = CompletableFuture.completedFuture(getMockedStreamResponse(200, body)); when(httpClient.sendAsync(any(), any())).thenReturn(response); - List<String> groups = gmsClient.listGroups("LBT."); + List<String> groups = gmsClient.listGroups("LBT.", false); - verify(httpClient, times(1)).sendAsync(endpointEq("GET", "ws/jwt/list/LBT."), any()); + verify(httpClient, times(1)).sendAsync(endpointEq("GET", "list/LBT.?recursive=false"), any()); assertEquals(2, groups.size()); assertEquals("INAF", groups.get(0)); diff --git a/gms/src/main/java/it/inaf/ia2/gms/controller/JWTWebServiceController.java b/gms/src/main/java/it/inaf/ia2/gms/controller/JWTWebServiceController.java index e675daa..983e874 100644 --- a/gms/src/main/java/it/inaf/ia2/gms/controller/JWTWebServiceController.java +++ b/gms/src/main/java/it/inaf/ia2/gms/controller/JWTWebServiceController.java @@ -136,14 +136,21 @@ public class JWTWebServiceController { // else: empty response (as defined by GMS standard) } - @GetMapping(value = {"/ws/jwt/list/{group:.+}", "/ws/jwt/list"}, produces = MediaType.TEXT_PLAIN_VALUE) - public void listGroups(@PathVariable("group") Optional<String> groupNames, Principal principal, HttpServletResponse response) throws IOException { + @GetMapping(value = {"/ws/jwt/list/{group:.+}", "/ws/jwt/list", "/list"}, produces = MediaType.TEXT_PLAIN_VALUE) + public void listGroups(@PathVariable("group") Optional<String> groupNames, + @RequestParam(value = "recursive", defaultValue = "false") boolean recursive, + Principal principal, HttpServletResponse response) throws IOException { String userId = principal.getName(); GroupEntity parentGroup = groupNameService.getGroupFromNames(groupNames); - List<GroupEntity> allSubGroups = groupsDAO.getDirectSubGroups(parentGroup.getPath()); + List<GroupEntity> allSubGroups; + if (recursive) { + allSubGroups = groupsDAO.getAllChildren(parentGroup.getPath()); + } else { + allSubGroups = groupsDAO.getDirectSubGroups(parentGroup.getPath()); + } // Select only the groups visible to the user List<PermissionEntity> permissions = permissionsDAO.findUserPermissions(userId); -- GitLab