Skip to content

Commit

Permalink
Added role names to user-group list
Browse files Browse the repository at this point in the history
Change-Id: I49cc002072f564179253f8f7eacbfedad4e0d49d
  • Loading branch information
margaretha committed Oct 23, 2024
1 parent 83cdf7f commit 987a051
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,5 +18,6 @@
@Getter
public class UserGroupMemberDto {
private String userId;
private Set<String> roles;
private List<PrivilegeType> privileges;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -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);
}
Expand All @@ -55,6 +57,14 @@ public UserGroupDto createUserGroupDto (UserGroup group,
return dto;
}

private Set<String> createUniqueRoles (Set<Role> roles) {
Set<String> uniqueRoles = new HashSet<String>();
for (Role r : roles) {
uniqueRoles.add(r.getName().name());
}
return uniqueRoles;
}

private List<PrivilegeType> createPrivilegeList (Set<Role> roles) {
List<PrivilegeType> privileges = new ArrayList<>(roles.size());
for (Role r : roles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 987a051

Please sign in to comment.