Skip to content

Commit

Permalink
feat: Implement Space Description Portlet - MEED-7473 - Meeds-io/MIPs…
Browse files Browse the repository at this point in the history
…#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
boubaker authored Sep 26, 2024
1 parent c0e89ed commit 7a50e23
Show file tree
Hide file tree
Showing 21 changed files with 364 additions and 49 deletions.
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;

Expand Down Expand Up @@ -79,7 +81,7 @@ public void onInit(WebAppController controller, ServletConfig sConfig) throws Ex

@Override
public String getHandlerName() {
return "space-access";
return PAGE_URI;
}

@Override
Expand Down Expand Up @@ -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;
}
}

Expand Down
107 changes: 107 additions & 0 deletions component/web/src/main/java/io/meeds/social/portlet/SpaceHandler.java
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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,11 @@
<set-method>register</set-method>
<type>org.exoplatform.social.core.space.impl.SpaceAccessHandler</type>
</component-plugin>
<component-plugin>
<name>SpaceHandler</name>
<set-method>register</set-method>
<type>io.meeds.social.portlet.SpaceHandler</type>
</component-plugin>
</external-component-plugins>
<external-component-plugins>
<target-component>io.meeds.social.translation.service.TranslationService</target-component>
Expand Down
22 changes: 22 additions & 0 deletions webapp/portlet/src/main/webapp/WEB-INF/gatein-resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,28 @@
</module>
</portlet>

<portlet>
<name>SpaceDescription</name>
<module>
<script>
<minify>false</minify>
<path>/js/spaceDescription.bundle.js</path>
</script>
<depends>
<module>vue</module>
</depends>
<depends>
<module>eXoVueI18n</module>
</depends>
<depends>
<module>commonVueComponents</module>
</depends>
<depends>
<module>extensionRegistry</module>
</depends>
</module>
</portlet>

<portlet>
<name>Search</name>
<module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%>
<div class="VuetifyApp">
<div data-app="true"
class="v-application white v-application--is-ltr theme--light profileAboutMe"
class="v-application v-application--is-ltr theme--light profileAboutMe"
id="ProfileAboutMe">
<v-cacheable-dom-app cache-id="ProfileAboutMe_<%=profileOwnerId%>"></v-cacheable-dom-app>
<script type="text/javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
%>
<div class="VuetifyApp">
<div data-app="true"
class="v-application white v-application--is-ltr theme--light profileContactInformation"
class="v-application v-application--is-ltr theme--light profileContactInformation"
id="ProfileContactInformation">
<textarea id="imTypesDefault" class="hidden"><%=jsonImTypes%></textarea>
<textarea id="imTypesDefault" class="d-none"><%=jsonImTypes%></textarea>
<script type="text/javascript">
require(['PORTLET/social-portlet/ProfileContactInformation'],
app => app.init(<%=maxUploadSize%>, JSON.parse(document.getElementById('imTypesDefault').value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%>
<div class="VuetifyApp">
<div data-app="true"
class="v-application white v-application--is-ltr theme--light profileWorkExperience"
class="v-application v-application--is-ltr theme--light profileWorkExperience"
id="ProfileWorkExperience">
<v-cacheable-dom-app cache-id="ProfileWorkExperience_<%=profileOwnerId%>"></v-cacheable-dom-app>
<script type="text/javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
%>
<div class="VuetifyApp">
<div data-app="true"
class="v-application spaceMenuParent white v-application--is-ltr theme--light"
class="v-application spaceMenuParent v-application--is-ltr theme--light"
id="SpaceHeader">
<v-cacheable-dom-app cache-id="SpaceHeader_<%=space == null ? "0" : space.getId()%>"></v-cacheable-dom-app>
<script type="text/javascript">
Expand Down
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>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<div class="VuetifyApp">
<div data-app="true"
class="v-application spaceMenuParent white v-application--is-ltr theme--light <%= navigations != null ? "hasNavigations" : ""%>"
class="v-application spaceMenuParent v-application--is-ltr theme--light <%= navigations != null ? "hasNavigations" : ""%>"
id="SpaceHeader">
<v-cacheable-dom-app cache-id="SpaceHeader_<%=space.getId()%>"></v-cacheable-dom-app>
<%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (navigations != null) {
%>
<div class="VuetifyApp">
<div data-app="true"
class="v-application spaceMenuParent white v-application--is-ltr theme--light"
class="v-application spaceMenuParent v-application--is-ltr theme--light"
id="SpaceMenu">
<v-cacheable-dom-app cache-id="SpaceMenu_<%=spaceId%>"></v-cacheable-dom-app>
<textarea id="SpaceMenuNavigationsValue" class="hidden">{
Expand Down
18 changes: 18 additions & 0 deletions webapp/portlet/src/main/webapp/WEB-INF/portlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,24 @@
</portlet-info>
</portlet>

<portlet>
<portlet-name>SpaceDescription</portlet-name>
<portlet-class>org.exoplatform.commons.api.portlet.GenericDispatchedViewPortlet</portlet-class>
<init-param>
<name>portlet-view-dispatched-file-path</name>
<value>/WEB-INF/jsp/portlet/spaceDescription.jsp</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
</supports>
<supported-locale>en</supported-locale>
<resource-bundle>locale.portlet.social.SpaceInfosPortlet</resource-bundle>
<portlet-info>
<title>Space Description</title>
<keywords>Space Homepage Description</keywords>
</portlet-info>
</portlet>

<portlet>
<description>Members Portlet</description>
<portlet-name>MembersPortlet</portlet-name>
Expand Down
Loading

0 comments on commit 7a50e23

Please sign in to comment.