Skip to content

Commit

Permalink
feat: Add Site Layout Editor Portlet - MEED-8194 - Meeds-io/MIPs#175 (#…
Browse files Browse the repository at this point in the history
…303)

This change will initiate a new porllet to allow site layout edition.
  • Loading branch information
boubaker authored Jan 22, 2025
1 parent bd7767a commit eda454d
Show file tree
Hide file tree
Showing 98 changed files with 3,314 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public LayoutModel updatePageLayout(
LayoutModel layoutModel) {
try {
pageLayoutService.updatePageLayout(pageRef,
RestEntityBuilder.fromLayoutModel(layoutModel),
layoutModel.toPage(),
publish.orElse(false).booleanValue(),
request.getRemoteUser());
return getPageLayout(request, pageRef, 0, false, expand);
Expand Down
211 changes: 161 additions & 50 deletions layout-service/src/main/java/io/meeds/layout/rest/SiteLayoutRest.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
import org.exoplatform.portal.config.model.ModelObject;
import org.exoplatform.portal.config.model.ModelStyle;
import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PageBody;
import org.exoplatform.portal.config.model.PersistentApplicationState;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.config.model.TransientApplicationState;
import org.exoplatform.portal.mop.page.PageKey;
import org.exoplatform.portal.pom.spi.portlet.Portlet;
Expand All @@ -57,6 +59,8 @@
@JsonInclude(value = Include.NON_EMPTY)
public class LayoutModel {

private static final String PAGE_BODY_TEMPLATE = "PageBody";

protected String id;

protected String storageId;
Expand Down Expand Up @@ -240,7 +244,11 @@ private void init(ModelObject model) { // NOSONAR
this.textSubtitleFontStyle = cssStyle.getTextSubtitleFontStyle();
}

if (model instanceof Container container) {
if (model instanceof PageBody pageBody) {
this.storageId = pageBody.getStorageId();
this.storageName = pageBody.getStorageName();
this.template = PAGE_BODY_TEMPLATE;
} else if (model instanceof Container container) {
this.id = container.getId();
this.storageId = container.getStorageId();
this.storageName = container.getStorageName();
Expand Down Expand Up @@ -328,10 +336,32 @@ public Page toPage() {
return page;
}

public PortalConfig toSite() {
PortalConfig site = new PortalConfig(storageId);
ModelObject modelObject = this.children == null ? new PageBody() :
this.children.stream()
.map(LayoutModel::toModelObject)
.findFirst()
.orElse(null);
if (modelObject instanceof Container container) {
site.setPortalLayout(container);
} else {
Container container = new Container();
container.setChildren(new ArrayList<>());
container.getChildren().add(modelObject);
site.setPortalLayout(container);
}
return site;
}

public static ModelObject toModelObject(LayoutModel layoutModel) { // NOSONAR
ModelStyle cssStyle = mapToStyle(layoutModel);

if (StringUtils.isNotBlank(layoutModel.template)) {
if (StringUtils.equals(layoutModel.template, PAGE_BODY_TEMPLATE)) {
PageBody pageBody = new PageBody(layoutModel.getStorageId());
pageBody.setStorageName(layoutModel.getStorageName());
return pageBody;
} else if (StringUtils.isNotBlank(layoutModel.template)) {
Container container = new Container(layoutModel.getStorageId());
container.setId(layoutModel.getId());
container.setStorageName(layoutModel.getStorageName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.exoplatform.portal.config.model.Application;
import org.exoplatform.portal.config.model.Container;
import org.exoplatform.portal.config.model.ModelObject;
import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.service.LayoutService;
import org.exoplatform.social.rest.api.EntityBuilder;
Expand All @@ -53,7 +52,7 @@ public static SiteEntity toSiteEntity(PortalConfig site,
request,
true,
null,
true,
false,
false,
false,
locale);
Expand Down Expand Up @@ -105,8 +104,4 @@ private static void applyApplicationContentId(List<LayoutModel> children,
}
}

public static Page fromLayoutModel(LayoutModel layoutModel) {
return layoutModel.toPage();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ public Page getPageLayout(PageKey pageKey) {
}

@SneakyThrows
public PageContext createPage(PageCreateModel pageModel,
String username) throws ObjectNotFoundException,
IllegalAccessException,
IllegalArgumentException {
public PageContext createPage(PageCreateModel pageModel, String username) throws ObjectNotFoundException,
IllegalAccessException,
IllegalArgumentException {
SiteKey siteKey = new SiteKey(pageModel.getPageSiteType(), pageModel.getPageSiteName());
PortalConfig portalConfig = layoutService.getPortalConfig(siteKey);
if (portalConfig == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.exoplatform.commons.exception.ObjectNotFoundException;
import org.exoplatform.portal.config.UserPortalConfig;
import org.exoplatform.portal.config.UserPortalConfigService;
import org.exoplatform.portal.config.model.ModelObject;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.SiteKey;
import org.exoplatform.portal.mop.SiteType;
Expand All @@ -53,6 +54,8 @@
@Service
public class SiteLayoutService {

private static final String SITE_DOESNT_EXIST_MSG = "Site %s doesn't exist";

@Autowired
private LayoutService layoutService;

Expand Down Expand Up @@ -82,6 +85,11 @@ public PortalConfig getSite(long siteId, String username) throws ObjectNotFoundE
return portalConfig;
}

public ModelObject getSiteLayout(SiteKey siteKey, String username) throws ObjectNotFoundException, IllegalAccessException {
PortalConfig site = getSite(siteKey, username);
return site.getPortalLayout();
}

public PortalConfig getSite(SiteKey siteKey, String username) throws ObjectNotFoundException, IllegalAccessException {
PortalConfig portalConfig = layoutService.getPortalConfig(siteKey);
if (portalConfig == null) {
Expand Down Expand Up @@ -136,6 +144,26 @@ public PortalConfig createSite(SiteCreateModel createModel, String username) thr
return createdPortalConfig;
}

public SiteKey createDraftSite(SiteKey siteKey, String username) throws ObjectNotFoundException, IllegalAccessException {
if (!aclService.canEditSite(siteKey, username)) {
throw new IllegalAccessException(String.format("Not allowed to edit site %s", siteKey));
}
PortalConfig site = getSite(siteKey, username);

String clonedSiteName = site.getType() + "_" + site.getName() + "_draft_" + username;

PortalConfig draftPortalConfig = site.clone();
draftPortalConfig.setType(PortalConfig.DRAFT);
draftPortalConfig.setName(clonedSiteName);
draftPortalConfig.resetStorage();
SiteKey draftSiteKey = new SiteKey(draftPortalConfig.getType(), draftPortalConfig.getName());
if (layoutService.getPortalConfig(draftSiteKey) != null) {
layoutService.remove(draftPortalConfig);
}
layoutService.create(draftPortalConfig);
return draftSiteKey;
}

public void updateSite(SiteUpdateModel updateModel, String username) throws IllegalAccessException,
ObjectNotFoundException {
SiteKey siteKey = new SiteKey(updateModel.getSiteType(), updateModel.getSiteName());
Expand Down Expand Up @@ -176,7 +204,7 @@ public void updateSitePermissions(PermissionUpdateModel permissionUpdateModel,
SiteKey siteKey = new SiteKey(permissionUpdateModel.getSiteType(), permissionUpdateModel.getSiteName());
PortalConfig portalConfig = layoutService.getPortalConfig(siteKey);
if (portalConfig == null) {
throw new ObjectNotFoundException(String.format("Site %s doesn't exist", siteKey));
throw new ObjectNotFoundException(String.format(SITE_DOESNT_EXIST_MSG, siteKey));
} else if (!aclService.canEditSite(siteKey, username)) {
throw new IllegalAccessException(String.format("Site permissions with key %s can't be edited by user %s",
siteKey,
Expand All @@ -191,6 +219,21 @@ public void updateSitePermissions(PermissionUpdateModel permissionUpdateModel,
layoutService.save(portalConfig);
}

public void updateSiteLayout(SiteKey siteKey,
PortalConfig site,
String username) throws IllegalAccessException, ObjectNotFoundException {
PortalConfig portalConfig = layoutService.getPortalConfig(siteKey);
if (portalConfig == null) {
throw new ObjectNotFoundException(String.format(SITE_DOESNT_EXIST_MSG, siteKey));
} else if (!aclService.canEditSite(siteKey, username)) {
throw new IllegalAccessException(String.format("Site layout with key %s can't be edited by user %s",
siteKey,
username));
}
portalConfig.setPortalLayout(site.getPortalLayout());
layoutService.save(portalConfig);
}

public NodeLabel getSiteLabels(Long siteId, String username) throws ObjectNotFoundException, IllegalAccessException {
return getSiteLabel(siteId, username, true);
}
Expand Down
Loading

0 comments on commit eda454d

Please sign in to comment.