Skip to content
Snippets Groups Projects
Commit 5c13e18b authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added optional recursive parameter to list groups endpoint

parent d8a9c640
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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")
......
......@@ -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));
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment