From 987a0512dd9fa8273cb03d1d78c3b782ffbe5a61 Mon Sep 17 00:00:00 2001 From: margaretha Date: Wed, 23 Oct 2024 11:19:29 +0200 Subject: [PATCH] Added role names to user-group list Change-Id: I49cc002072f564179253f8f7eacbfedad4e0d49d --- Changes | 2 +- .../de/ids_mannheim/korap/dto/UserGroupMemberDto.java | 2 ++ .../korap/dto/converter/UserGroupConverter.java | 10 ++++++++++ .../web/controller/usergroup/UserGroupListTest.java | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 639a5fe6..d4f1302d 100644 --- a/Changes +++ b/Changes @@ -22,7 +22,7 @@ - Disallow scope all for non super clients. - Changed memberUsername to member in the new member-role-addition web-service. - Removed user-privileges from user-group list response. -- +- Added role names to user-group list # version 0.74.1-SNAPSHOT diff --git a/src/main/java/de/ids_mannheim/korap/dto/UserGroupMemberDto.java b/src/main/java/de/ids_mannheim/korap/dto/UserGroupMemberDto.java index 40ea6d48..f3112487 100644 --- a/src/main/java/de/ids_mannheim/korap/dto/UserGroupMemberDto.java +++ b/src/main/java/de/ids_mannheim/korap/dto/UserGroupMemberDto.java @@ -1,6 +1,7 @@ package de.ids_mannheim.korap.dto; import java.util.List; +import java.util.Set; import de.ids_mannheim.korap.constant.PrivilegeType; import lombok.Getter; @@ -17,5 +18,6 @@ @Getter public class UserGroupMemberDto { private String userId; + private Set roles; private List privileges; } diff --git a/src/main/java/de/ids_mannheim/korap/dto/converter/UserGroupConverter.java b/src/main/java/de/ids_mannheim/korap/dto/converter/UserGroupConverter.java index 7fbaa101..f959264a 100644 --- a/src/main/java/de/ids_mannheim/korap/dto/converter/UserGroupConverter.java +++ b/src/main/java/de/ids_mannheim/korap/dto/converter/UserGroupConverter.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -43,6 +44,7 @@ public UserGroupDto createUserGroupDto (UserGroup group, UserGroupMemberDto memberDto = new UserGroupMemberDto(); memberDto.setUserId(member.getUserId()); + memberDto.setRoles(createUniqueRoles(member.getRoles())); memberDto.setPrivileges(createPrivilegeList(member.getRoles())); memberDtos.add(memberDto); } @@ -55,6 +57,14 @@ public UserGroupDto createUserGroupDto (UserGroup group, return dto; } + private Set createUniqueRoles (Set roles) { + Set uniqueRoles = new HashSet(); + for (Role r : roles) { + uniqueRoles.add(r.getName().name()); + } + return uniqueRoles; + } + private List createPrivilegeList (Set roles) { List privileges = new ArrayList<>(roles.size()); for (Role r : roles) { diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupListTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupListTest.java index b96467ae..51c1d50b 100644 --- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupListTest.java +++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupListTest.java @@ -28,6 +28,15 @@ public void testListDoryGroups () throws KustvaktException { assertEquals(group.at("/owner").asText(), "dory"); assertEquals(3, group.at("/members").size()); + assertEquals(group.at("/members/0/userId").asText(), "dory"); + assertEquals(group.at("/members/0/roles").size(), 1); + assertEquals(group.at("/members/0/roles/0").asText(), "GROUP_ADMIN"); + assertEquals(group.at("/members/0/privileges").size(), 5); + + assertEquals(group.at("/members/1/userId").asText(), "marlin"); + assertEquals(group.at("/members/1/roles").size(), 1); + assertEquals(group.at("/members/1/roles/0").asText(), "GROUP_MEMBER"); + testListNemoGroups(); testListMarlinGroups();