From 46ad7f5a7ad15d046827745a227547dfa27271b4 Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Tue, 29 Oct 2024 11:41:24 +0100 Subject: [PATCH] feat: Allow to display Application and Section Backgrounds retrieved from Space templates - MEED-7684 - Meeds-io/MIPs#165 (#246) This change will give access permission to Page, Section and Application Background images attached in Spaces Site Template Pages. --- .../LayoutBackgroundAttachmentPlugin.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/layout-service/src/main/java/io/meeds/layout/plugin/attachment/LayoutBackgroundAttachmentPlugin.java b/layout-service/src/main/java/io/meeds/layout/plugin/attachment/LayoutBackgroundAttachmentPlugin.java index 8fedca301..c90e0e04c 100644 --- a/layout-service/src/main/java/io/meeds/layout/plugin/attachment/LayoutBackgroundAttachmentPlugin.java +++ b/layout-service/src/main/java/io/meeds/layout/plugin/attachment/LayoutBackgroundAttachmentPlugin.java @@ -26,6 +26,7 @@ import org.exoplatform.commons.exception.ObjectNotFoundException; import org.exoplatform.portal.config.model.Page; +import org.exoplatform.portal.mop.SiteType; import org.exoplatform.portal.mop.page.PageKey; import org.exoplatform.portal.mop.service.LayoutService; import org.exoplatform.services.security.Identity; @@ -63,14 +64,14 @@ public String getObjectType() { @Override public boolean hasEditPermission(Identity userIdentity, String entityId) throws ObjectNotFoundException { - return layoutAclService.canEditPage(getPageKey(entityId.split("_")[0]), - userIdentity == null ? null : userIdentity.getUserId()); + return layoutAclService.canEditPage(getPageKey(entityId), getUsername(userIdentity)); } @Override public boolean hasAccessPermission(Identity userIdentity, String entityId) throws ObjectNotFoundException { - return layoutAclService.canViewPage(getPageKey(entityId.split("_")[0]), - userIdentity == null ? null : userIdentity.getUserId()); + PageKey pageKey = getPageKey(entityId); + return pageKey.getSite().getType() == SiteType.GROUP_TEMPLATE + || layoutAclService.canViewPage(pageKey, getUsername(userIdentity)); } @Override @@ -84,10 +85,14 @@ public long getSpaceId(String objectId) throws ObjectNotFoundException { } private PageKey getPageKey(String entityId) { - String pageUuid = entityId.replace("page_", ""); + String pageUuid = entityId.split("_")[0].replace("page_", ""); long pageId = StringUtils.isNumeric(pageUuid) ? Long.parseLong(pageUuid) : 0; Page page = layoutService.getPage(pageId); return page.getPageKey(); } + private String getUsername(Identity userIdentity) { + return userIdentity == null ? null : userIdentity.getUserId(); + } + }