From 000a664415d47f942336fe40ef1c1ae1b25421f3 Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Thu, 29 Jan 2026 10:05:00 +0100 Subject: [PATCH 1/2] feat: Retrieve Memberships from User ACL instead of OrganizationService - MEED-10149 - Meeds-io/MIPs#240 (#681) This change will centralize the users memberships retrieval to be made from `UserACL` Service rather than `OrganizationService`. This centralization will allow to optimize the Code enhancements and evolutivity. --- .../plugin/LinkSettingTranslationPlugin.java | 42 ++++--------------- .../link/plugin/LinkTranslationPlugin.java | 36 +++------------- .../plugin/NewsListViewTranslationPlugin.java | 34 ++++----------- 3 files changed, 20 insertions(+), 92 deletions(-) diff --git a/content-service/src/main/java/io/meeds/content/link/plugin/LinkSettingTranslationPlugin.java b/content-service/src/main/java/io/meeds/content/link/plugin/LinkSettingTranslationPlugin.java index c1356284a..106b40cd0 100644 --- a/content-service/src/main/java/io/meeds/content/link/plugin/LinkSettingTranslationPlugin.java +++ b/content-service/src/main/java/io/meeds/content/link/plugin/LinkSettingTranslationPlugin.java @@ -18,19 +18,13 @@ */ package io.meeds.content.link.plugin; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.exoplatform.commons.exception.ObjectNotFoundException; +import org.exoplatform.portal.config.UserACL; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; -import org.exoplatform.services.organization.OrganizationService; -import org.exoplatform.services.security.Identity; -import org.exoplatform.services.security.IdentityRegistry; -import org.exoplatform.services.security.MembershipEntry; import io.meeds.content.link.model.LinkSetting; import io.meeds.content.link.service.LinkService; @@ -42,21 +36,18 @@ @Component public class LinkSettingTranslationPlugin extends TranslationPlugin { - public static final String LINK_SETTINGS_OBJECT_TYPE = "link-settings"; - - private static final Log LOG = ExoLogger.getLogger(LinkSettingTranslationPlugin.class); + public static final String LINK_SETTINGS_OBJECT_TYPE = "link-settings"; - @Autowired - protected LinkService linkService; + private static final Log LOG = ExoLogger.getLogger(LinkSettingTranslationPlugin.class); @Autowired - protected IdentityRegistry identityRegistry; + protected LinkService linkService; @Autowired - protected OrganizationService organizationService; + protected TranslationService translationService; @Autowired - protected TranslationService translationService; + protected UserACL userAcl; @PostConstruct public void init() { @@ -72,7 +63,7 @@ public String getObjectType() { public boolean hasAccessPermission(String linkSettingId, String username) throws ObjectNotFoundException { try { LinkSetting linkSetting = linkService.getLinkSettingById(Long.parseLong(linkSettingId)); - return linkSetting != null && linkService.hasAccessPermission(linkSetting.getName(), getIdentity(username)); + return linkSetting != null && linkService.hasAccessPermission(linkSetting.getName(), userAcl.getUserIdentity(username)); } catch (Exception e) { LOG.warn("Error checking access permission on link setting with id {} for user {}", linkSettingId, username, e); return false; @@ -83,7 +74,7 @@ public boolean hasAccessPermission(String linkSettingId, String username) throws public boolean hasEditPermission(String linkSettingId, String username) throws ObjectNotFoundException { try { LinkSetting linkSetting = linkService.getLinkSettingById(Long.parseLong(linkSettingId)); - return linkSetting != null && linkService.hasEditPermission(linkSetting.getName(), getIdentity(username)); + return linkSetting != null && linkService.hasEditPermission(linkSetting.getName(), userAcl.getUserIdentity(username)); } catch (Exception e) { LOG.warn("Error checking edit permission on link setting with id {} for user {}", linkSettingId, username, e); return false; @@ -100,21 +91,4 @@ public long getSpaceId(String linkSettingId) throws ObjectNotFoundException { return 0; } - private Identity getIdentity(String username) throws Exception { - if (StringUtils.isBlank(username)) { - return null; - } - Identity aclIdentity = identityRegistry.getIdentity(username); - if (aclIdentity == null) { - List entries = organizationService.getMembershipHandler() - .findMembershipsByUser(username) - .stream() - .map(membership -> new MembershipEntry(membership.getGroupId(), - membership.getMembershipType())) - .toList(); - aclIdentity = new Identity(username, entries); - identityRegistry.register(aclIdentity); - } - return aclIdentity; - } } diff --git a/content-service/src/main/java/io/meeds/content/link/plugin/LinkTranslationPlugin.java b/content-service/src/main/java/io/meeds/content/link/plugin/LinkTranslationPlugin.java index 449b8ac4e..2b6fa5e9d 100644 --- a/content-service/src/main/java/io/meeds/content/link/plugin/LinkTranslationPlugin.java +++ b/content-service/src/main/java/io/meeds/content/link/plugin/LinkTranslationPlugin.java @@ -18,19 +18,13 @@ */ package io.meeds.content.link.plugin; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.exoplatform.commons.exception.ObjectNotFoundException; +import org.exoplatform.portal.config.UserACL; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; -import org.exoplatform.services.organization.OrganizationService; -import org.exoplatform.services.security.Identity; -import org.exoplatform.services.security.IdentityRegistry; -import org.exoplatform.services.security.MembershipEntry; import io.meeds.content.link.model.LinkSetting; import io.meeds.content.link.service.LinkService; @@ -50,13 +44,10 @@ public class LinkTranslationPlugin extends TranslationPlugin { private LinkService linkService; @Autowired - private IdentityRegistry identityRegistry; - - @Autowired - private OrganizationService organizationService; + private TranslationService translationService; @Autowired - private TranslationService translationService; + protected UserACL userAcl; @PostConstruct public void init() { @@ -72,7 +63,7 @@ public String getObjectType() { public boolean hasAccessPermission(String linkId, String username) throws ObjectNotFoundException { try { LinkSetting linkSetting = linkService.getLinkSettingByLinkId(Long.parseLong(linkId)); - return linkSetting != null && linkService.hasAccessPermission(linkSetting.getName(), getIdentity(username)); + return linkSetting != null && linkService.hasAccessPermission(linkSetting.getName(), userAcl.getUserIdentity(username)); } catch (Exception e) { LOG.warn("Error checking access permission on link with id {} for user {}", linkId, username, e); return false; @@ -83,7 +74,7 @@ public boolean hasAccessPermission(String linkId, String username) throws Object public boolean hasEditPermission(String linkId, String username) throws ObjectNotFoundException { try { LinkSetting linkSetting = linkService.getLinkSettingByLinkId(Long.parseLong(linkId)); - return linkSetting != null && linkService.hasEditPermission(linkSetting.getName(), getIdentity(username)); + return linkSetting != null && linkService.hasEditPermission(linkSetting.getName(), userAcl.getUserIdentity(username)); } catch (Exception e) { LOG.warn("Error checking edit permission on link with id {} for user {}", linkId, username, e); return false; @@ -100,21 +91,4 @@ public long getSpaceId(String linkId) throws ObjectNotFoundException { return 0; } - private Identity getIdentity(String username) throws Exception { - if (StringUtils.isBlank(username)) { - return null; - } - Identity aclIdentity = identityRegistry.getIdentity(username); - if (aclIdentity == null) { - List entries = organizationService.getMembershipHandler() - .findMembershipsByUser(username) - .stream() - .map(membership -> new MembershipEntry(membership.getGroupId(), - membership.getMembershipType())) - .toList(); - aclIdentity = new Identity(username, entries); - identityRegistry.register(aclIdentity); - } - return aclIdentity; - } } diff --git a/content-service/src/main/java/io/meeds/content/news/plugin/NewsListViewTranslationPlugin.java b/content-service/src/main/java/io/meeds/content/news/plugin/NewsListViewTranslationPlugin.java index d5ef78738..9356935a2 100644 --- a/content-service/src/main/java/io/meeds/content/news/plugin/NewsListViewTranslationPlugin.java +++ b/content-service/src/main/java/io/meeds/content/news/plugin/NewsListViewTranslationPlugin.java @@ -28,6 +28,7 @@ import org.exoplatform.commons.api.settings.SettingValue; import org.exoplatform.commons.exception.ObjectNotFoundException; import org.exoplatform.container.ExoContainerContext; +import org.exoplatform.portal.config.UserACL; import org.exoplatform.services.organization.OrganizationService; import org.exoplatform.services.security.Identity; import org.exoplatform.services.security.IdentityRegistry; @@ -46,13 +47,6 @@ public class NewsListViewTranslationPlugin extends TranslationPlugin { public static final String NEWS_LIST_VIEW_OBJECT_TYPE = "newsListView"; - - @Setter - private IdentityRegistry identityRegistry; - - @Autowired - private OrganizationService organizationService; - @Autowired private TranslationService translationService; @@ -62,9 +56,11 @@ public class NewsListViewTranslationPlugin extends TranslationPlugin { @Autowired private SettingService settingService; + @Autowired + private UserACL userAcl; + @PostConstruct public void init() { - setIdentityRegistry(ExoContainerContext.getService(IdentityRegistry.class)); translationService.addPlugin(this); } @@ -90,8 +86,9 @@ public boolean hasEditPermission(String objectId, String username) { NewsUtils.NEWS_LIST_VIEW_SCOPE, objectId); String settingName = settingNameValue != null ? settingNameValue.getValue().toString() : null; - return getIdentity(username) != null - && (cmsService.hasEditPermission(getIdentity(username), "newsListViewPortlet", settingName)); + Identity userAclIdentity = userAcl.getUserIdentity(username); + return userAclIdentity != null + && (cmsService.hasEditPermission(userAclIdentity, "newsListViewPortlet", settingName)); } catch (Exception e) { return false; } @@ -107,21 +104,4 @@ public long getSpaceId(String objectId) throws ObjectNotFoundException { return 0; } - private Identity getIdentity(String username) throws Exception { - if (StringUtils.isBlank(username)) { - return null; - } - Identity aclIdentity = identityRegistry.getIdentity(username); - if (aclIdentity == null) { - List entries = organizationService.getMembershipHandler() - .findMembershipsByUser(username) - .stream() - .map(membership -> new MembershipEntry(membership.getGroupId(), - membership.getMembershipType())) - .toList(); - aclIdentity = new Identity(username, entries); - identityRegistry.register(aclIdentity); - } - return aclIdentity; - } } From d908ddaf911b0ae1815e87a5e31795e2d3df8b8c Mon Sep 17 00:00:00 2001 From: sofyenne Date: Thu, 12 Feb 2026 10:29:40 +0100 Subject: [PATCH 2/2] feat: Remove unused import - MEED-10244 - Meeds-io/MIPs#240 --- .../news/plugin/NewsListViewTranslationPlugin.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/content-service/src/main/java/io/meeds/content/news/plugin/NewsListViewTranslationPlugin.java b/content-service/src/main/java/io/meeds/content/news/plugin/NewsListViewTranslationPlugin.java index 9356935a2..593832116 100644 --- a/content-service/src/main/java/io/meeds/content/news/plugin/NewsListViewTranslationPlugin.java +++ b/content-service/src/main/java/io/meeds/content/news/plugin/NewsListViewTranslationPlugin.java @@ -18,21 +18,14 @@ */ package io.meeds.content.news.plugin; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.exoplatform.commons.api.settings.SettingService; import org.exoplatform.commons.api.settings.SettingValue; import org.exoplatform.commons.exception.ObjectNotFoundException; -import org.exoplatform.container.ExoContainerContext; import org.exoplatform.portal.config.UserACL; -import org.exoplatform.services.organization.OrganizationService; import org.exoplatform.services.security.Identity; -import org.exoplatform.services.security.IdentityRegistry; -import org.exoplatform.services.security.MembershipEntry; import io.meeds.content.news.utils.NewsUtils; import io.meeds.social.cms.service.CMSService; @@ -40,7 +33,6 @@ import io.meeds.social.translation.service.TranslationService; import jakarta.annotation.PostConstruct; -import lombok.Setter; @Component public class NewsListViewTranslationPlugin extends TranslationPlugin {