-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement Space Description Portlet - MEED-7473 - Meeds-io/MIPs…
…#151 (#4068) This change will implement a new portlet that will be used in Space Home Page. In addition, a new Handler has been added to get a direct access to a space with its id.
- Loading branch information
Showing
21 changed files
with
364 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [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 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 <http://www.gnu.org/licenses/>. | ||
* 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<MembershipEntry> 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; | ||
} | ||
} | ||
|
||
|
107 changes: 107 additions & 0 deletions
107
component/web/src/main/java/io/meeds/social/portlet/SpaceHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* 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.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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
webapp/portlet/src/main/webapp/WEB-INF/jsp/portlet/spaceDescription.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<%@page import="org.exoplatform.social.core.space.spi.SpaceService"%> | ||
<%@page import="org.exoplatform.container.ExoContainerContext"%> | ||
<%@page import="org.exoplatform.web.PortalHttpServletResponseWrapper"%> | ||
<%@page import="org.exoplatform.social.core.space.model.Space"%> | ||
<%@page import="org.exoplatform.social.core.space.SpaceUtils"%> | ||
<%@page import="org.exoplatform.portal.application.PortalRequestContext"%> | ||
<% | ||
PortalRequestContext rcontext = (PortalRequestContext) PortalRequestContext.getCurrentInstance(); | ||
PortalHttpServletResponseWrapper responseWrapper = (PortalHttpServletResponseWrapper) rcontext.getResponse(); | ||
String activityId = rcontext.getRequest().getParameter("id"); | ||
Space space = SpaceUtils.getSpaceByContext(); | ||
String description = space == null || space.getDescription() == null ? "" : space.getDescription(); | ||
String id = space == null ? "" : space.getId(); | ||
boolean canEdit = space != null | ||
&& request.getRemoteUser() != null | ||
&& ExoContainerContext.getService(SpaceService.class) | ||
.canManageSpace(space, request.getRemoteUser()); | ||
%> | ||
<div class="VuetifyApp"> | ||
<div data-app="true" | ||
class="v-application v-application--is-ltr theme--light" | ||
id="SpaceDescriptionApplication"> | ||
<textarea id="spaceDescriptionContent" class="d-none"><%=description%></textarea> | ||
<script type="text/javascript"> | ||
require(['PORTLET/social-portlet/SpaceDescription'], app => app.init(<%=id%>, <%=canEdit%>, document.getElementById('spaceDescriptionContent').value)); | ||
</script> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.