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: Remove the user from the old group synchronized profile property groups - EXO-64814 - Meeds-io/meeds#1052 #2702

Merged
merged 10 commits into from
Aug 8, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package org.exoplatform.social.core.listeners;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -126,6 +127,7 @@ private void synchronizeProperty(Map.Entry<String, Object> property, Group profi
Group newPropertyNameGroup = getOrCreateGroup(propertyName, profileGroup);
try {
Group newPropertyValueGroup = getOrCreateGroup(propertyValue, newPropertyNameGroup);
removeUserFromExistingPropertyGroup(newPropertyNameGroup, user);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't you removing then adding the user to the same group here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are removing the user from the existing child group, and then adding them to the newly created child group within the same larger (parent) group!

addUserToGroup(newPropertyValueGroup, user);
} catch (Exception e) {
LOG.error("Error while adding property value group {} under property Group {}",
Expand Down Expand Up @@ -173,6 +175,20 @@ private void addUserToGroup(Group group, User user) throws Exception {
}
}

private void removeUserFromExistingPropertyGroup(Group group, User user) throws Exception {
Collection<Group> groups = organizationService.getGroupHandler().findGroups(group);
if (!groups.isEmpty()) {
MembershipHandler memberShipHandler = organizationService.getMembershipHandler();
for (Group gr : groups){
Membership memberShip = memberShipHandler.findMembershipByUserGroupAndType(user.getUserName(),
gr.getId(),
MEMBER);
if (memberShip != null) {
memberShipHandler.removeMembership(memberShip.getId(), true);
}
}
}
}
private String buildGroupId(Group parentGroup, String groupName) {
if (parentGroup == null) {
return "/" + groupName.toLowerCase();
Expand Down