diff --git a/component/core/src/main/java/org/exoplatform/social/core/space/impl/SpaceAccessHandler.java b/component/core/src/main/java/org/exoplatform/social/core/space/impl/SpaceAccessHandler.java index 3c3c7104e6c..e457dfc058d 100644 --- a/component/core/src/main/java/org/exoplatform/social/core/space/impl/SpaceAccessHandler.java +++ b/component/core/src/main/java/org/exoplatform/social/core/space/impl/SpaceAccessHandler.java @@ -1,18 +1,20 @@ -/* - * Copyright (C) 2003-2012 eXo Platform SAS. +/** + * This file is part of the Meeds project (https://meeds.io/). * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io * + * 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 Affero General Public License for more details. + * 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 Affero General Public License - * along with this program. If not, see . + * 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 org.exoplatform.social.core.space.impl; @@ -79,7 +81,7 @@ public void onInit(WebAppController controller, ServletConfig sConfig) throws Ex @Override public String getHandlerName() { - return "space-access"; + return PAGE_URI; } @Override @@ -112,35 +114,20 @@ public boolean execute(ControllerContext controllerContext) throws Exception { return false; } - private boolean canAccessSpace(String remoteId, Space space) { - Identity identity = identityRegistry.getIdentity(remoteId); + private boolean canAccessSpace(String username, Space space) { + Identity identity = identityRegistry.getIdentity(username); if (identity == null) { return false; - } else { + } else if (spaceService.isMember(space, username)) { + return true; + } else if (spaceService.canViewSpace(space, username)) { + // Add user as 'member' to Identity if it's absent Collection memberships = identity.getMemberships(); - - boolean isSuperManager = spaceService.isSuperManager(remoteId); - boolean isManager = spaceService.isManager(space, remoteId); - boolean isMember = spaceService.isMember(space, remoteId); - - // add membership's member to Identity if it's absent MembershipEntry memberMembership = new MembershipEntry(space.getGroupId(), SpaceUtils.MEMBER); - boolean canAccessSpace = isMember || isManager || isSuperManager; - if (canAccessSpace) { - memberships.add(memberMembership); - } else { - memberships.remove(memberMembership); - } - - @SuppressWarnings("deprecation") - MembershipEntry managerMembership = new MembershipEntry(space.getGroupId(), SpaceUtils.MANAGER); - // add membership's manager to Identity if it's absent - if (isManager || isSuperManager) { - memberships.add(managerMembership); - } else { - memberships.remove(managerMembership); - } - return canAccessSpace; + memberships.add(memberMembership); + return true; + } else { + return false; } } diff --git a/component/web/src/main/java/io/meeds/social/portlet/SpaceHandler.java b/component/web/src/main/java/io/meeds/social/portlet/SpaceHandler.java new file mode 100644 index 00000000000..36cbaa22c98 --- /dev/null +++ b/component/web/src/main/java/io/meeds/social/portlet/SpaceHandler.java @@ -0,0 +1,107 @@ +/** + * This file is part of the Meeds project (https://meeds.io/). + * + * Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io + * + * 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.social.portlet; + +import static io.meeds.social.permlink.plugin.SpacePermanentLinkPlugin.APPLICATION_URI; +import static io.meeds.social.permlink.plugin.SpacePermanentLinkPlugin.OBJECT_TYPE; + +import java.util.Collections; + +import org.apache.commons.lang3.StringUtils; + +import org.exoplatform.container.PortalContainer; +import org.exoplatform.portal.config.UserPortalConfigService; +import org.exoplatform.social.core.space.model.Space; +import org.exoplatform.social.core.space.spi.SpaceService; +import org.exoplatform.web.ControllerContext; +import org.exoplatform.web.WebAppController; +import org.exoplatform.web.WebRequestHandler; +import org.exoplatform.web.controller.QualifiedName; + +import io.meeds.portal.permlink.model.PermanentLinkObject; +import io.meeds.portal.permlink.service.PermanentLinkService; + +import jakarta.servlet.ServletConfig; + +public class SpaceHandler extends WebRequestHandler { + + public static final QualifiedName REQUEST_SPACE_ID = QualifiedName.create("spaceId"); + + public static final QualifiedName REQUEST_PATH = QualifiedName.create("path"); + + private SpaceService spaceService; + + private UserPortalConfigService portalConfigService; + + private PermanentLinkService permanentLinkService; + + @Override + public void onInit(WebAppController controller, ServletConfig sConfig) throws Exception { + super.onInit(controller, sConfig); + + PortalContainer container = PortalContainer.getInstance(); + this.spaceService = container.getComponentInstanceOfType(SpaceService.class); + this.portalConfigService = container.getComponentInstanceOfType(UserPortalConfigService.class); + this.permanentLinkService = container.getComponentInstanceOfType(PermanentLinkService.class); + } + + @Override + public String getHandlerName() { + return "spaces"; + } + + @Override + protected boolean getRequiresLifeCycle() { + return true; + } + + @Override + public boolean execute(ControllerContext controllerContext) throws Exception { + String username = controllerContext.getRequest().getRemoteUser(); + String spaceId = controllerContext.getParameter(REQUEST_SPACE_ID); + String path = controllerContext.getParameter(REQUEST_PATH); + Space space = spaceService.getSpaceById(spaceId); + if (StringUtils.isBlank(username) + || space == null + || isHiddenSpace(space, username)) { + String pageNotFoundUrl = "/portal/" + getPageNotFoundSite(username) + "/page-not-found"; + controllerContext.getResponse().sendRedirect(pageNotFoundUrl); + } else { + String uri = permanentLinkService.getLink(getPermanentLinkObject(spaceId, path)); + controllerContext.getResponse().sendRedirect(uri); + } + return true; + } + + private String getPageNotFoundSite(String username) { + return StringUtils.isBlank(username) ? "public" : portalConfigService.getMetaPortal(); + } + + private boolean isHiddenSpace(Space space, String username) { + return !spaceService.canViewSpace(space, username) + && Space.HIDDEN.equals(space.getVisibility()); + } + + private PermanentLinkObject getPermanentLinkObject(String spaceId, String path) { + return new PermanentLinkObject(OBJECT_TYPE, + spaceId, + Collections.singletonMap(APPLICATION_URI, path)); + } + +} diff --git a/extension/war/src/main/webapp/WEB-INF/conf/social-extension/social/core-configuration.xml b/extension/war/src/main/webapp/WEB-INF/conf/social-extension/social/core-configuration.xml index e852aef350a..8dd05c9b4e8 100644 --- a/extension/war/src/main/webapp/WEB-INF/conf/social-extension/social/core-configuration.xml +++ b/extension/war/src/main/webapp/WEB-INF/conf/social-extension/social/core-configuration.xml @@ -971,6 +971,11 @@ register org.exoplatform.social.core.space.impl.SpaceAccessHandler + + SpaceHandler + register + io.meeds.social.portlet.SpaceHandler + io.meeds.social.translation.service.TranslationService diff --git a/webapp/portlet/src/main/webapp/WEB-INF/gatein-resources.xml b/webapp/portlet/src/main/webapp/WEB-INF/gatein-resources.xml index 701231168e6..b32654ae988 100644 --- a/webapp/portlet/src/main/webapp/WEB-INF/gatein-resources.xml +++ b/webapp/portlet/src/main/webapp/WEB-INF/gatein-resources.xml @@ -663,6 +663,28 @@ + + SpaceDescription + + + + vue + + + eXoVueI18n + + + commonVueComponents + + + extensionRegistry + + + + Search diff --git a/webapp/portlet/src/main/webapp/WEB-INF/jsp/portlet/profileAboutMe.jsp b/webapp/portlet/src/main/webapp/WEB-INF/jsp/portlet/profileAboutMe.jsp index d458cb2d8c4..22d5a69408b 100644 --- a/webapp/portlet/src/main/webapp/WEB-INF/jsp/portlet/profileAboutMe.jsp +++ b/webapp/portlet/src/main/webapp/WEB-INF/jsp/portlet/profileAboutMe.jsp @@ -4,7 +4,7 @@ %>
+
+
diff --git a/webapp/portlet/src/main/webapp/WEB-INF/jsp/portlet/spaceHeader.jsp b/webapp/portlet/src/main/webapp/WEB-INF/jsp/portlet/spaceHeader.jsp index 3b9ce86c382..b83f40523ee 100644 --- a/webapp/portlet/src/main/webapp/WEB-INF/jsp/portlet/spaceHeader.jsp +++ b/webapp/portlet/src/main/webapp/WEB-INF/jsp/portlet/spaceHeader.jsp @@ -26,7 +26,7 @@