Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Space Templates Layout - Meeds-io/MIPs#165 #251

Merged
merged 12 commits into from
Nov 4, 2024
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
@@ -0,0 +1,53 @@
/**
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 Meeds Association [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.layout.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import org.exoplatform.portal.config.UserPortalConfigService;
import org.exoplatform.portal.mop.SiteKey;
import org.exoplatform.services.listener.Event;
import org.exoplatform.services.listener.ListenerBase;
import org.exoplatform.services.listener.ListenerService;

import io.meeds.layout.service.PageLayoutService;

import jakarta.annotation.PostConstruct;

@Component
public class SiteCreatedFromTemplateListener implements ListenerBase<SiteKey, SiteKey> {

@Autowired
private ListenerService listenerService;

@Autowired
private PageLayoutService pageLayoutService;

@PostConstruct
public void init() {
listenerService.addListener(UserPortalConfigService.SITE_TEMPLATE_INSTANTIATED, this);
}

@Override
public void onEvent(Event<SiteKey, SiteKey> event) throws Exception {
pageLayoutService.impersonateSite(event.getData());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public interface PortletInstancePreferencePlugin {
* @param preferences current {@link Portlet} preferences
* @return
*/
List<PortletInstancePreference> generatePreferences(Application<Portlet> application, Portlet preferences);
List<PortletInstancePreference> generatePreferences(Application application, Portlet preferences);

}
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public String getContainerName() {
}

@Override
public List<Application<?>> getApplications() {
public List<Application> getApplications() {
return Collections.singletonList(portletInstanceApplicationAdapter);
}

Expand Down
Loading