Update dto to list privilege names instead of role names.
Change-Id: I1d8dd77662e89e321e62ae94c0b6396c1bf83c5e
diff --git a/src/main/java/de/ids_mannheim/korap/dto/UserGroupDto.java b/src/main/java/de/ids_mannheim/korap/dto/UserGroupDto.java
index bc09718..0ed52ef 100644
--- a/src/main/java/de/ids_mannheim/korap/dto/UserGroupDto.java
+++ b/src/main/java/de/ids_mannheim/korap/dto/UserGroupDto.java
@@ -5,7 +5,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import de.ids_mannheim.korap.constant.GroupMemberStatus;
-import de.ids_mannheim.korap.constant.PredefinedRole;
+import de.ids_mannheim.korap.constant.PrivilegeType;
import de.ids_mannheim.korap.constant.UserGroupStatus;
import lombok.Getter;
import lombok.Setter;
@@ -33,5 +33,5 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
private GroupMemberStatus userMemberStatus;
@JsonInclude(JsonInclude.Include.NON_NULL)
- private List<PredefinedRole> userRoles;
+ private List<PrivilegeType> userPrivileges;
}
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 0081a9a..ef50116 100644
--- a/src/main/java/de/ids_mannheim/korap/dto/UserGroupMemberDto.java
+++ b/src/main/java/de/ids_mannheim/korap/dto/UserGroupMemberDto.java
@@ -3,7 +3,7 @@
import java.util.List;
import de.ids_mannheim.korap.constant.GroupMemberStatus;
-import de.ids_mannheim.korap.constant.PredefinedRole;
+import de.ids_mannheim.korap.constant.PrivilegeType;
import lombok.Getter;
import lombok.Setter;
@@ -19,5 +19,5 @@
public class UserGroupMemberDto {
private String userId;
private GroupMemberStatus status;
- private List<PredefinedRole> roles;
+ private List<PrivilegeType> 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 e2e0a3d..275ee70 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
@@ -8,7 +8,7 @@
import org.springframework.stereotype.Component;
import de.ids_mannheim.korap.constant.GroupMemberStatus;
-import de.ids_mannheim.korap.constant.PredefinedRole;
+import de.ids_mannheim.korap.constant.PrivilegeType;
import de.ids_mannheim.korap.dto.UserGroupDto;
import de.ids_mannheim.korap.dto.UserGroupMemberDto;
import de.ids_mannheim.korap.entity.Role;
@@ -40,7 +40,7 @@
dto.setUserMemberStatus(userMemberStatus);
if (roleSet != null) {
- dto.setUserRoles(convertRoleToPredefinedRoles(roleSet));
+ dto.setUserPrivileges(createPrivilegeList(roleSet));
}
if (members != null) {
@@ -51,8 +51,7 @@
UserGroupMemberDto memberDto = new UserGroupMemberDto();
memberDto.setUserId(member.getUserId());
memberDto.setStatus(member.getStatus());
- memberDto.setRoles(
- convertRoleToPredefinedRoles(member.getRoles()));
+ memberDto.setPrivileges(createPrivilegeList(member.getRoles()));
memberDtos.add(memberDto);
}
dto.setMembers(memberDtos);
@@ -64,12 +63,12 @@
return dto;
}
- private List<PredefinedRole> convertRoleToPredefinedRoles (Set<Role> roleSet) {
- List<PredefinedRole> roles = new ArrayList<>(roleSet.size());
- for (Role r : roleSet) {
- roles.add(r.getName());
+ private List<PrivilegeType> createPrivilegeList (Set<Role> roles) {
+ List<PrivilegeType> privileges = new ArrayList<>(roles.size());
+ for (Role r : roles) {
+ privileges.add(r.getPrivilege());
}
- Collections.sort(roles);
- return roles;
+ Collections.sort(privileges);
+ return privileges;
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerAdminTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerAdminTest.java
index 138a562..c5af1a5 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerAdminTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerAdminTest.java
@@ -217,7 +217,7 @@
for (int i = 0; i < node.size(); i++) {
member = node.get(i);
if (member.at("/userId").asText().equals(memberUsername)) {
- assertEquals(6, member.at("/roles").size());
+ assertEquals(6, member.at("/privileges").size());
break;
}
}
@@ -242,7 +242,7 @@
for (int i = 0; i < node.size(); i++) {
member = node.get(i);
if (member.at("/userId").asText().equals(memberUsername)) {
- assertEquals(1, member.at("/roles").size());
+ assertEquals(1, member.at("/privileges").size());
break;
}
}
@@ -303,6 +303,6 @@
assertEquals(node.at("/members/3/userId").asText(), "darla");
assertEquals(GroupMemberStatus.PENDING.name(),
node.at("/members/1/status").asText());
- assertEquals(0, node.at("/members/1/roles").size());
+ assertEquals(0, node.at("/members/1/privileges").size());
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
index 7363257..4806241 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
@@ -107,7 +107,7 @@
assertEquals(username, node.at("/members/0/userId").asText());
assertEquals(GroupMemberStatus.ACTIVE.name(),
node.at("/members/0/status").asText());
- assertEquals(5, node.at("/members/0/roles").size());
+ assertEquals(5, node.at("/members/0/privileges").size());
testUpdateUserGroup(groupName);
testInviteMember(groupName, username, "darla");
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 2da127c..3344bf9 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
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.web.controller.usergroup;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
@@ -41,7 +42,8 @@
assertEquals(node.at("/0/name").asText(), "dory-group");
assertEquals(node.at("/0/owner").asText(), "dory");
// group members are not allowed to see other members
- assertEquals(0, node.at("/0/members").size());
+ assertTrue(node.at("/0/members").isMissingNode());
+ System.out.println(node.toPrettyString());
}
// marlin has 2 groups
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupSubscriptionTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupSubscriptionTest.java
index 2d675e3..5ffd446 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupSubscriptionTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupSubscriptionTest.java
@@ -78,7 +78,7 @@
assertEquals(GroupMemberStatus.ACTIVE.name(),
group.at("/userMemberStatus").asText());
- assertEquals(1, group.at("/userRoles").size());
+ assertEquals(1, group.at("/userPrivileges").size());
// unsubscribe marlin from dory-group
testUnsubscribeActiveMember("dory-group");
@@ -116,7 +116,7 @@
for (int i = 0; i < node.size(); i++) {
member = node.get(i);
if (deletedMemberName.equals(member.at("/userId").asText())) {
- assertEquals(0, node.at("/roles").size());
+ assertEquals(0, node.at("/privileges").size());
break;
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java
index e5e46c4..4a5c6bd 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java
@@ -86,7 +86,7 @@
assertEquals(node.at("/members/1/userId").asText(), invitee);
assertEquals(GroupMemberStatus.PENDING.name(),
node.at("/members/1/status").asText());
- assertEquals(0, node.at("/members/1/roles").size());
+ assertEquals(0, node.at("/members/1/privileges").size());
}
protected Response subscribe (String groupName, String username)
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusPublishedTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusPublishedTest.java
index 516b6fc..acfc3bb 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusPublishedTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusPublishedTest.java
@@ -8,6 +8,7 @@
import de.ids_mannheim.korap.constant.GroupMemberStatus;
import de.ids_mannheim.korap.constant.PredefinedRole;
+import de.ids_mannheim.korap.constant.PrivilegeType;
import de.ids_mannheim.korap.constant.ResourceType;
import de.ids_mannheim.korap.constant.UserGroupStatus;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -52,9 +53,9 @@
assertEquals(username, node.at("/members/0/userId").asText());
assertEquals(GroupMemberStatus.ACTIVE.name(),
node.at("/members/0/status").asText());
- assertEquals(1, node.at("/members/0/roles").size());
- assertEquals(PredefinedRole.QUERY_ACCESS.name(),
- node.at("/members/0/roles/0").asText());
+ assertEquals(1, node.at("/members/0/privileges").size());
+ assertEquals(PrivilegeType.READ_QUERY.name(),
+ node.at("/members/0/privileges/0").asText());
String groupName = node.at("/name").asText();
node = listRolesByGroup("admin", groupName);
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java
index 2107491..1ffbdb8 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java
@@ -12,6 +12,7 @@
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.constant.GroupMemberStatus;
import de.ids_mannheim.korap.constant.PredefinedRole;
+import de.ids_mannheim.korap.constant.PrivilegeType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -308,8 +309,8 @@
assertEquals(memberName, node.at("/members/1/userId").asText());
assertEquals(GroupMemberStatus.ACTIVE.name(),
node.at("/members/1/status").asText());
- assertEquals(PredefinedRole.GROUP_MEMBER.name(),
- node.at("/members/1/roles/0").asText());
+ assertEquals(PrivilegeType.DELETE_MEMBER.name(),
+ node.at("/members/1/privileges/0").asText());
}
@Test