Skip to content

Commit

Permalink
feat: Allow to display Application and Section Backgrounds retrieved …
Browse files Browse the repository at this point in the history
…from Space templates - MEED-7684 - Meeds-io/MIPs#165

This change will give access permission to Page, Section and Application Background images attached in Spaces Site Template Pages.
  • Loading branch information
boubaker committed Oct 29, 2024
1 parent 74ed2c0 commit 622129d
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();
}

}

0 comments on commit 622129d

Please sign in to comment.