Skip to content

Commit

Permalink
Fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
azayati committed Sep 4, 2023
1 parent d60ed59 commit d60ba46
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 395 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
package org.exoplatform.social.rest.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;

import org.exoplatform.portal.mop.SiteType;
import org.exoplatform.portal.mop.rest.model.UserNodeRestEntity;

import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
Expand All @@ -46,7 +47,7 @@ public class SiteEntity {

private int displayOrder;

private boolean isDefaultSite;
private boolean metaSite;

List<UserNodeRestEntity> siteNavigations;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2023 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 org.exoplatform.social.rest.impl.site;

import java.util.List;

import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.SiteFilter;
import org.exoplatform.portal.mop.SiteType;
import org.exoplatform.portal.mop.service.LayoutService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.resource.ResourceContainer;
import org.exoplatform.social.rest.api.EntityBuilder;
import org.exoplatform.social.service.rest.api.VersionResources;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

@Path(VersionResources.VERSION_ONE + "/social/sites")
@Tag(name = VersionResources.VERSION_ONE + "/social/sites", description = "Manage sites")
public class SiteRest implements ResourceContainer {

private static final Log LOG = ExoLogger.getLogger(SiteRest.class);

private LayoutService layoutService;

public SiteRest(LayoutService layoutService) {
this.layoutService = layoutService;
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("users")
@Operation(summary = "Gets sites", description = "Gets sites", method = "GET")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Request fulfilled"),
@ApiResponse(responseCode = "500", description = "Internal server error"), })
public Response getSites(@Context
HttpServletRequest request,
@Parameter(description = "Portal site type, possible values: PORTAL, GROUP or USER", required = true)
@QueryParam("siteType")
String siteTypeName,
@Parameter(description = "Site name to be excluded")
@QueryParam("excludedSiteName")
String excludedSiteName,
@Parameter(description = "to include empty site in results in portal type case")
@DefaultValue("true")
@QueryParam("includeEmpty")
boolean includeEmpty,
@Parameter(description = "to expand site navigations nodes")
@DefaultValue("false")
@QueryParam("expandNavigations")
boolean expandNavigations,
@Parameter(description = "to retrieve sites with its displayed status")
@DefaultValue("false")
@QueryParam("displayed")
boolean displayed,
@Parameter(description = "to retrieve all sites")
@DefaultValue("true")
@QueryParam("allSites")
boolean allSites,
@Parameter(description = "to filter sites by view/edit permissions")
@DefaultValue("false")
@QueryParam("filterByPermissions")
boolean filterByPermission,
@Parameter(description = "Offset of results to retrieve")
@QueryParam("offset")
@DefaultValue("0")
int offset,
@Parameter(description = "Limit of results to retrieve")
@QueryParam("limit")
@DefaultValue("0")
int limit) {
try {
SiteFilter siteFilter = new SiteFilter();
if (siteTypeName != null) {
siteFilter.setSiteType(SiteType.valueOf(siteTypeName.toUpperCase()));
}
siteFilter.setExcludedSiteName(excludedSiteName);
siteFilter.setIncludeEmpty(includeEmpty);
siteFilter.setDisplayed(displayed);
siteFilter.setAllSites(allSites);
siteFilter.setExpandNavigations(expandNavigations);
siteFilter.setFilterByPermission(filterByPermission);
siteFilter.setLimit(limit);
siteFilter.setOffset(offset);
List<PortalConfig> sites = layoutService.getSites(siteFilter);
return Response.ok(EntityBuilder.buildSiteEntities(sites, request, siteFilter)).build();
} catch (Exception e) {
LOG.warn("Error while retrieving sites", e);
return Response.serverError().build();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2023 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 org.exoplatform.social.rest.impl.site;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.junit.Before;
import org.junit.Test;

import org.exoplatform.portal.mop.SiteType;
import org.exoplatform.portal.mop.dao.SiteDAO;
import org.exoplatform.portal.rest.services.BaseRestServicesTestCase;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.impl.EnvironmentContext;
import org.exoplatform.services.test.mock.MockHttpServletRequest;
import org.exoplatform.social.rest.entity.SiteEntity;
import org.junit.Before;
import org.junit.Test;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import org.exoplatform.portal.rest.services.BaseRestServicesTestCase;

public class SiteRestServiceTest extends BaseRestServicesTestCase {
public class SiteRestTest extends BaseRestServicesTestCase {
private SiteDAO siteDAO;

@Before
Expand All @@ -33,7 +51,7 @@ public void tearDown() throws Exception {

@Override
protected Class<?> getComponentClass() {
return SiteRestService.class;
return SiteRest.class;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<type>org.exoplatform.social.rest.impl.tag.TagRest</type>
</component>
<component>
<type>org.exoplatform.social.rest.impl.site.SiteRestService</type>
<type>org.exoplatform.social.rest.impl.site.SiteRest</type>
</component>
<component>
<type>io.meeds.social.translation.rest.TranslationRest</type>
Expand Down
25 changes: 25 additions & 0 deletions webapp/portlet/src/main/webapp/vue-apps/common/js/SiteService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export function getSites(siteType, displayed, allSites, excludedSiteName, expandNavigations, filterByPermission) {
const formData = new FormData();
if (siteType) {
formData.append('siteType', siteType);
}
formData.append('displayed', displayed);
formData.append('allSites', allSites);
formData.append('filterByPermission', filterByPermission);
if (excludedSiteName) {
formData.append('excludedSiteName', excludedSiteName);
}
formData.append('expandNavigations', expandNavigations);
const params = new URLSearchParams(formData).toString();

return fetch(`${eXo.env.portal.context}/${eXo.env.portal.rest}/v1/social/sites?${params}`, {
method: 'GET',
credentials: 'include',
}).then(resp => {
if (resp?.ok) {
return resp.json();
} else {
throw new Error('Error while getting sites');
}
});
}
Loading

0 comments on commit d60ba46

Please sign in to comment.