From 988828bef487799addf23cbba3157dda8d918dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20D=C3=A9nari=C3=A9?= Date: Mon, 28 Oct 2024 17:08:04 +0100 Subject: [PATCH] fix: Profile for disabled users can be reindexed - EXO-75104 Before this fix, when update a user profile, the user is reindex in ES, even if he is disabled This commit ensure to not reindex the user if he is disabled Resolves meeds-io/meeds#2534 --- .../listener/ProfileESListenerImpl.java | 72 +++++++++++++------ 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/component/core/src/main/java/org/exoplatform/social/core/jpa/search/listener/ProfileESListenerImpl.java b/component/core/src/main/java/org/exoplatform/social/core/jpa/search/listener/ProfileESListenerImpl.java index 48d90f75138..15f9b712b8b 100644 --- a/component/core/src/main/java/org/exoplatform/social/core/jpa/search/listener/ProfileESListenerImpl.java +++ b/component/core/src/main/java/org/exoplatform/social/core/jpa/search/listener/ProfileESListenerImpl.java @@ -18,8 +18,10 @@ import org.exoplatform.commons.search.index.IndexingService; import org.exoplatform.commons.utils.CommonsUtils; +import org.exoplatform.commons.utils.IdentifierUtil; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; +import org.exoplatform.social.core.identity.model.Identity; import org.exoplatform.social.core.jpa.search.ProfileIndexingServiceConnector; import org.exoplatform.social.core.profile.ProfileLifeCycleEvent; import org.exoplatform.social.core.profile.ProfileListenerPlugin; @@ -34,12 +36,17 @@ public class ProfileESListenerImpl extends ProfileListenerPlugin { @Override public void avatarUpdated(ProfileLifeCycleEvent event) { - IndexingService indexingService = CommonsUtils.getService(IndexingService.class); - String id = event.getProfile().getIdentity().getId(); + if (event.getProfile().getIdentity().isEnable()) { + IndexingService indexingService = CommonsUtils.getService(IndexingService.class); + String id = event.getProfile().getIdentity().getId(); - LOG.debug("Notifying indexing service for profile avatar update id={}", id); + LOG.debug("Notifying indexing service for profile avatar update id={}", id); + + indexingService.reindex(ProfileIndexingServiceConnector.TYPE, id); + } else { + LOG.debug("Ignore notifying indexing service for profile avatar update for disabled id={}", event.getProfile().getIdentity().getId()); + } - indexingService.reindex(ProfileIndexingServiceConnector.TYPE, id); } @Override @@ -49,50 +56,69 @@ public void bannerUpdated(ProfileLifeCycleEvent event) { @Override public void contactSectionUpdated(ProfileLifeCycleEvent event) { - IndexingService indexingService = CommonsUtils.getService(IndexingService.class); - String id = event.getProfile().getIdentity().getId(); + if (event.getProfile().getIdentity().isEnable()) { + IndexingService indexingService = CommonsUtils.getService(IndexingService.class); + String id = event.getProfile().getIdentity().getId(); - LOG.debug("Notifying indexing service for the profile contact update id={}", id); + LOG.debug("Notifying indexing service for the profile contact update id={}", id); - indexingService.reindex(ProfileIndexingServiceConnector.TYPE, id); + indexingService.reindex(ProfileIndexingServiceConnector.TYPE, id); + } else { + LOG.debug("Ignore notifying indexing service for profile contact update for disabled id={}", event.getProfile().getIdentity().getId()); + } } @Override public void aboutMeUpdated(ProfileLifeCycleEvent event) { - String id = event.getProfile().getIdentity().getId(); + if (event.getProfile().getIdentity().isEnable()) { + String id = event.getProfile().getIdentity().getId(); - LOG.debug("Notifying indexing service for the profile aboutme update id={}", id); + LOG.debug("Notifying indexing service for the profile aboutme update id={}", id); - CommonsUtils.getService(IndexingService.class).reindex(ProfileIndexingServiceConnector.TYPE, id); + CommonsUtils.getService(IndexingService.class).reindex(ProfileIndexingServiceConnector.TYPE, id); + } else { + LOG.debug("Ignore notifying indexing service for profile aboutme update for disabled id={}", event.getProfile().getIdentity().getId()); + } } @Override public void experienceSectionUpdated(ProfileLifeCycleEvent event) { - String id = event.getProfile().getIdentity().getId(); + if (event.getProfile().getIdentity().isEnable()) { + String id = event.getProfile().getIdentity().getId(); - LOG.debug("Notifying indexing service for the profile experience update id={}", id); + LOG.debug("Notifying indexing service for the profile experience update id={}", id); - CommonsUtils.getService(IndexingService.class).reindex(ProfileIndexingServiceConnector.TYPE, id); + CommonsUtils.getService(IndexingService.class).reindex(ProfileIndexingServiceConnector.TYPE, id); + } else { + LOG.debug("Ignore notifying indexing service for profile experience update for disabled id={}", event.getProfile().getIdentity().getId()); + } } @Override public void createProfile(ProfileLifeCycleEvent event) { - IndexingService indexingService = CommonsUtils.getService(IndexingService.class); - String id = event.getProfile().getIdentity().getId(); + if (event.getProfile().getIdentity().isEnable()) { + IndexingService indexingService = CommonsUtils.getService(IndexingService.class); + String id = event.getProfile().getIdentity().getId(); - LOG.debug("Notifying indexing service for the profile creation id={}", id); + LOG.debug("Notifying indexing service for the profile creation id={}", id); - indexingService.index(ProfileIndexingServiceConnector.TYPE, id); + indexingService.index(ProfileIndexingServiceConnector.TYPE, id); + } else { + LOG.debug("Ignore notifying indexing service for profile creation for disabled id={}", event.getProfile().getIdentity().getId()); + } } @Override public void technicalUpdated(ProfileLifeCycleEvent event) { - IndexingService indexingService = CommonsUtils.getService(IndexingService.class); - String id = event.getProfile().getIdentity().getId(); + if (event.getProfile().getIdentity().isEnable()) { + IndexingService indexingService = CommonsUtils.getService(IndexingService.class); + String id = event.getProfile().getIdentity().getId(); - LOG.debug("Notifying indexing service for the profile update id={}, technical property changed", id); + LOG.debug("Notifying indexing service for the profile update id={}, technical property changed", id); - indexingService.reindex(ProfileIndexingServiceConnector.TYPE, id); + indexingService.reindex(ProfileIndexingServiceConnector.TYPE, id); + } else { + LOG.debug("Ignore notifying indexing service for the profile update for disabled id={}, technical property changed", event.getProfile().getIdentity().getId()); + } } - }