Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user synchronizer if only reviewer and not both #308

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
pmauduit marked this conversation as resolved.
Show resolved Hide resolved
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
Loading