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

Search endpoint: returned parent group if child doesn't exist but user is member of parent

parent 3c0681e1
No related branches found
No related tags found
No related merge requests found
......@@ -118,6 +118,7 @@ public class JWTWebServiceController {
String groupNamesString = getGroupFromRequest(request, "/ws/jwt/search/", "/vo/search/");
List<String> groupNames = groupNameService.extractGroupNames(groupNamesString);
List<String> existingGroupNames = new ArrayList<>();
GroupEntity group = null;
......@@ -127,19 +128,17 @@ public class JWTWebServiceController {
if (optionalGroup.isPresent()) {
GroupEntity groupEntity = optionalGroup.get();
parentPath = groupEntity.getPath();
existingGroupNames.add(groupName);
boolean isMember = membershipManager.isCurrentUserMemberOf(groupEntity.getId());
if (isMember) {
group = groupEntity;
}
} else {
group = null;
break;
}
}
if (group != null) {
try ( PrintWriter pw = new PrintWriter(response.getOutputStream())) {
pw.println(groupNameService.getCompleteName(groupNames));
pw.println(groupNameService.getCompleteName(existingGroupNames));
}
}
// else: empty response (as defined by GMS standard)
......
......@@ -131,6 +131,61 @@ public class JWTWebServiceControllerTest {
.andExpect(content().string(""));
}
@Test
public void testIsMemberOfParentButChildDoesntExist() throws Exception {
GroupEntity group1 = new GroupEntity();
group1.setId("1");
group1.setPath("1");
group1.setName("LBT");
GroupEntity group2 = new GroupEntity();
group2.setId("2");
group2.setPath("1.2");
group2.setName("OTHERS");
when(groupsDAO.findGroupByParentAndName(eq(""), eq("LBT")))
.thenReturn(Optional.of(group1));
when(groupsDAO.findGroupByParentAndName(eq("1"), eq("OTHERS")))
.thenReturn(Optional.of(group2));
when(membershipManager.isCurrentUserMemberOf(eq(group2.getId()))).thenReturn(true);
String group = "LBT.OTHERS.UNKNOWN";
mockMvc.perform(get("/vo/search/" + group).principal(principal))
.andExpect(status().isOk())
.andExpect(content().string("LBT.OTHERS\n"));
}
@Test
public void testIsMemberOfSuperParentButChildDoesntExist() throws Exception {
GroupEntity group1 = new GroupEntity();
group1.setId("1");
group1.setPath("1");
group1.setName("LBT");
GroupEntity group2 = new GroupEntity();
group2.setId("2");
group2.setPath("1.2");
group2.setName("OTHERS");
when(groupsDAO.findGroupByParentAndName(eq(""), eq("LBT")))
.thenReturn(Optional.of(group1));
when(groupsDAO.findGroupByParentAndName(eq("1"), eq("OTHERS")))
.thenReturn(Optional.of(group2));
when(membershipManager.isCurrentUserMemberOf(eq(group1.getId()))).thenReturn(true);
when(membershipManager.isCurrentUserMemberOf(eq(group2.getId()))).thenReturn(true);
String group = "LBT.OTHERS.UNKNOWN";
mockMvc.perform(get("/vo/search/" + group).principal(principal))
.andExpect(status().isOk())
.andExpect(content().string("LBT.OTHERS\n"));
}
@Test
public void testCreateGroup() throws Exception {
......
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