Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<MembershipEntry> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<MembershipEntry> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,27 @@
*/
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.services.organization.OrganizationService;
import org.exoplatform.portal.config.UserACL;
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;
import io.meeds.social.translation.plugin.TranslationPlugin;
import io.meeds.social.translation.service.TranslationService;

import jakarta.annotation.PostConstruct;
import lombok.Setter;

@Component
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;

Expand All @@ -62,9 +48,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);
}

Expand All @@ -90,8 +78,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;
}
Expand All @@ -107,21 +96,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<MembershipEntry> 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;
}
}