Skip to content

Commit

Permalink
Merge pull request #309 from georchestra/backport/georchestra-gn4.2.x…
Browse files Browse the repository at this point in the history
…-24.0/pr-308

[georchestra-gn4.2.x-24.0] Merge pull request #308 from georchestra/fix-both-reviewer-and-editors
  • Loading branch information
github-actions[bot] authored Nov 20, 2024
2 parents 695a4d9 + 7ae4a6c commit 58003d4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/georchestra-gn4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:

- name: "publish the webapp as artifact"
if: github.repository == 'georchestra/geonetwork' && github.actor != 'dependabot[bot]' && github.ref == 'refs/heads/georchestra-gn4.2.x' && github.event_name != 'pull_request'
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: geonetwork.war
path: web/target/geonetwork.war
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,22 @@ private void synchronizeUserGroups(User user, List<Privilege> privileges) {
}

private List<UserGroup> resolveNewPrivileges(User user, List<Privilege> actual) {
List<Privilege> editors = actual.stream().filter(privilege -> privilege.getProfile() == Profile.Reviewer)//
.map(privilege -> {

List<Privilege> editors = actual.stream().filter(privilege -> privilege.getProfile() == Profile.Reviewer || privilege.getProfile() == Profile.Editor)
// group by geonetwork group
.collect(Collectors.groupingBy(Privilege::getGroup))//
.values().stream()//
// check if both reviewer and editor are present for the same group and profile is only reviewer
.filter(privileges -> privileges.size() == 1 && privileges.get(0).getProfile() == Profile.Reviewer)
// get first privilege (reviewer)
.map(privileges -> privileges.get(0))
// create a new privilege with editor profile
.map(privilege -> {
log.debug("User {} is a reviewer of group {}", user.getUsername(),
privilege.getGroup().getName());
return new Privilege(privilege.getGroup(), Profile.Editor);
}).collect(Collectors.toList());
//Combine all the privileges
editors.addAll(actual);

return editors.stream()//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ public void assertUser(CanonicalUser expected, User user) {
public UserGroup assertGroup(User user, CanonicalGroup belongsTo) {
GroupLink link = assertGroupLink(belongsTo);
Group group = link.getGeonetworkGroup();
Map<Integer, UserGroup> byGroupId = gnUserGroupRepository.findAll(UserGroupSpecs.hasUserId(user.getId()))
.stream().collect(Collectors.toMap(ug -> ug.getGroup().getId(), Function.identity()));
Map<Integer, List<UserGroup>> byGroupId = gnUserGroupRepository.findAll(UserGroupSpecs.hasUserId(user.getId()))
.stream().collect(Collectors.groupingBy(ug -> ug.getGroup().getId()));

UserGroup userGroup = byGroupId.get(group.getId());
UserGroup userGroup = byGroupId.get(group.getId()).get(0);
String msg = String.format("User '%s': link to group %s not found. Got: %s", user.getUsername(),
group.getName(),
user.getUsername() + " user's link to group " + group.getName() + " not found: " + byGroupId.values()
.stream().map(UserGroup::getGroup).map(Group::getName).collect(Collectors.joining(",")));
.stream().map(us -> us.get(0)).map(UserGroup::getGroup).map(Group::getName).collect(Collectors.joining(",")));
assertNotNull(msg, userGroup);
return userGroup;
}
Expand Down

0 comments on commit 58003d4

Please sign in to comment.