diff --git a/component/service/src/main/java/org/exoplatform/social/rest/api/EntityBuilder.java b/component/service/src/main/java/org/exoplatform/social/rest/api/EntityBuilder.java index 2db97203db2..474d90f2d28 100644 --- a/component/service/src/main/java/org/exoplatform/social/rest/api/EntityBuilder.java +++ b/component/service/src/main/java/org/exoplatform/social/rest/api/EntityBuilder.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -64,6 +65,7 @@ import org.exoplatform.portal.mop.SiteKey; import org.exoplatform.portal.mop.SiteType; import org.exoplatform.portal.mop.navigation.Scope; +import org.exoplatform.portal.mop.rest.model.UserNodeRestEntity; import org.exoplatform.portal.mop.service.LayoutService; import org.exoplatform.portal.mop.user.HttpUserPortalContext; import org.exoplatform.portal.mop.user.UserNavigation; @@ -1766,14 +1768,29 @@ public static RelationshipManager getRelationshipManager() { public static List buildSiteEntities(List sites, HttpServletRequest request, - boolean expandNavigations) { - return sites.stream().map(site -> buildSiteEntity(site, request, expandNavigations)).filter(Objects::nonNull).toList(); - } - - public static SiteEntity buildSiteEntity(PortalConfig site, HttpServletRequest request, boolean expandNavigations) { - if (site == null) { - return null; - } + boolean expandNavigations, + boolean excludeEmptyNavigationSites, + boolean filterByPermission, + boolean sortByDisplayOrder) { + List filteredByPermissionSites = sites; + if (filterByPermission) { + filteredByPermissionSites = sites.stream().filter(getUserACL()::hasPermission).toList(); + } + List siteEntities = filteredByPermissionSites.stream() + .map(site -> buildSiteEntity(site, + request, + expandNavigations, + excludeEmptyNavigationSites)) + .filter(Objects::nonNull) + .toList(); + return sortByDisplayOrder ? siteEntities + : siteEntities.stream().sorted(Comparator.comparing(SiteEntity::getDisplayName, String.CASE_INSENSITIVE_ORDER)).toList(); + } + + public static SiteEntity buildSiteEntity(PortalConfig site, + HttpServletRequest request, + boolean expandNavigations, + boolean excludeEmptyNavigationSites) { SiteType siteType = SiteType.valueOf(site.getType().toUpperCase()); String displayName = site.getLabel(); org.exoplatform.services.security.Identity userIdentity = ConversationState.getCurrent().getIdentity(); @@ -1793,24 +1810,34 @@ public static SiteEntity buildSiteEntity(PortalConfig site, HttpServletRequest r Map editPermission = computePermission(site.getEditPermission()); UserNode rootNode = null; - if (expandNavigations) { - String currentUser = userIdentity.getUserId(); - try { - HttpUserPortalContext userPortalContext = new HttpUserPortalContext(request); - UserPortalConfig userPortalConfig = - getUserPortalConfigService().getUserPortalConfig(siteType != SiteType.PORTAL ? getUserPortalConfigService().getDefaultPortal() - : site.getName(), - currentUser, - userPortalContext); - - UserPortal userPortal = userPortalConfig.getUserPortal(); - UserNavigation navigation = userPortal.getNavigation(new SiteKey(siteType.getName(), site.getName())); - if (navigation != null) { - rootNode = userPortal.getNode(navigation, Scope.ALL, UserNodeFilterConfig.builder().withReadWriteCheck().build(), null); - } - } catch (Exception e) { - LOG.error("Error while getting site {} navigations for user {}", site.getName(), currentUser, e); + String currentUser = userIdentity.getUserId(); + try { + HttpUserPortalContext userPortalContext = new HttpUserPortalContext(request); + UserPortalConfig userPortalConfig = + getUserPortalConfigService().getUserPortalConfig(siteType != SiteType.PORTAL ? getUserPortalConfigService().getDefaultPortal() + : site.getName(), + currentUser, + userPortalContext); + + UserPortal userPortal = userPortalConfig.getUserPortal(); + UserNavigation navigation = userPortal.getNavigation(new SiteKey(siteType.getName(), site.getName())); + if (navigation != null) { + rootNode = userPortal.getNode(navigation, Scope.ALL, UserNodeFilterConfig.builder().withReadWriteCheck().build(), null); } + } catch (Exception e) { + LOG.error("Error while getting site {} navigations for user {}", site.getName(), currentUser, e); + } + + if (excludeEmptyNavigationSites && (rootNode == null || rootNode.getChildren().isEmpty())) { + return null; + } + List siteNavigations = null; + if (expandNavigations && rootNode != null) { + siteNavigations = toUserNodeRestEntity(rootNode.getChildren(), + true, + getOrganizationService(), + getLayoutService(), + getUserACL()); } return new SiteEntity(siteType, site.getName(), @@ -1821,14 +1848,8 @@ public static SiteEntity buildSiteEntity(PortalConfig site, HttpServletRequest r site.isDisplayed(), site.getDisplayOrder(), isMetaSite(site.getName()), - rootNode == null ? null - : toUserNodeRestEntity(rootNode.getChildren(), - true, - getOrganizationService(), - getLayoutService(), - getUserACL()), + siteNavigations, getUserACL().hasPermission(site.getEditPermission())); - } private static List> computePermissions(String[] permissions) { diff --git a/component/service/src/main/java/org/exoplatform/social/rest/impl/site/SiteRest.java b/component/service/src/main/java/org/exoplatform/social/rest/impl/site/SiteRest.java index 7580dce3ea8..c0070e54229 100644 --- a/component/service/src/main/java/org/exoplatform/social/rest/impl/site/SiteRest.java +++ b/component/service/src/main/java/org/exoplatform/social/rest/impl/site/SiteRest.java @@ -65,24 +65,39 @@ public SiteRest(LayoutService layoutService) { @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) + @Parameter(description = "Portal site types, possible values: PORTAL, GROUP or USER", required = true) @QueryParam("siteType") - String siteTypeName, + String siteType, + @Parameter(description = "Site type to be excluded") + @QueryParam("excludedSiteType") + String excludedSiteType, @Parameter(description = "Site name to be excluded") @QueryParam("excludedSiteName") String excludedSiteName, + @Parameter(description = "to exclude space sites") + @DefaultValue("false") + @QueryParam("excludeSpaceSites") + boolean excludeSpaceSites, + @Parameter(description = "to exclude sites with empty navigation") + @DefaultValue("false") + @QueryParam("excludeEmptyNavigationSites") + boolean excludeEmptyNavigationSites, @Parameter(description = "to expand site navigations nodes") @DefaultValue("false") @QueryParam("expandNavigations") boolean expandNavigations, - @Parameter(description = "to retrieve sites with its displayed status") + @Parameter(description = "to sort with display order") + @DefaultValue("false") + @QueryParam("sortByDisplayOrder") + boolean sortByDisplayOrder, + @Parameter(description = "to filter sites by displayed status") + @DefaultValue("false") + @QueryParam("filterByDisplayed") + boolean filterByDisplayed, + @Parameter(description = "to retrieve sites with displayed status") @DefaultValue("false") @QueryParam("displayed") - Boolean displayed, - @Parameter(description = "to retrieve all sites") - @DefaultValue("true") - @QueryParam("allSites") - boolean allSites, + boolean displayed, @Parameter(description = "to filter sites by view/edit permissions") @DefaultValue("false") @QueryParam("filterByPermissions") @@ -97,21 +112,25 @@ public Response getSites(@Context int limit) { try { SiteFilter siteFilter = new SiteFilter(); - if (siteTypeName != null) { - siteFilter.setSiteType(SiteType.valueOf(siteTypeName.toUpperCase())); + if (siteType != null) { + siteFilter.setSiteType(SiteType.valueOf(siteType.toUpperCase())); + } + if (excludedSiteType != null) { + siteFilter.setExcludedSiteType(SiteType.valueOf(excludedSiteType.toUpperCase())); } if (excludedSiteName != null) { siteFilter.setExcludedSiteName(excludedSiteName); } - if (displayed != null) { + siteFilter.setExcludeSpaceSites(excludeSpaceSites); + siteFilter.setSortByDisplayOrder(sortByDisplayOrder); + if (filterByDisplayed) { + siteFilter.setFilterByDisplayed(filterByDisplayed); siteFilter.setDisplayed(displayed); } - siteFilter.setAllSites(allSites); - siteFilter.setFilterByPermission(filterByPermission); siteFilter.setLimit(limit); siteFilter.setOffset(offset); List sites = layoutService.getSites(siteFilter); - return Response.ok(EntityBuilder.buildSiteEntities(sites, request, expandNavigations)).build(); + return Response.ok(EntityBuilder.buildSiteEntities(sites, request, expandNavigations, excludeEmptyNavigationSites, filterByPermission, sortByDisplayOrder)).build(); } catch (Exception e) { LOG.warn("Error while retrieving sites", e); return Response.serverError().build(); diff --git a/webapp/portlet/src/main/webapp/vue-apps/common/js/SiteService.js b/webapp/portlet/src/main/webapp/vue-apps/common/js/SiteService.js index 80c5cd54294..dee1f0b40e8 100644 --- a/webapp/portlet/src/main/webapp/vue-apps/common/js/SiteService.js +++ b/webapp/portlet/src/main/webapp/vue-apps/common/js/SiteService.js @@ -1,16 +1,22 @@ -export function getSites(siteType, excludedSiteName, expandNavigations, displayed, allSites, filterByPermissions) { +export function getSites(siteType, excludedSiteType, excludedSiteName, excludeEmptyNavigationSites, excludeSpaceSites, expandNavigations, filterByDisplayed, sortByDisplayOrder, displayed, filterByPermissions) { const formData = new FormData(); if (siteType) { formData.append('siteType', siteType); } + if (excludedSiteType) { + formData.append('excludedSiteType', excludedSiteType); + } if (excludedSiteName) { formData.append('excludedSiteName', excludedSiteName); } + formData.append('excludeEmptyNavigationSites', excludeEmptyNavigationSites); + formData.append('excludeSpaceSites', excludeSpaceSites); formData.append('expandNavigations', expandNavigations); - if (displayed) { + formData.append('filterByDisplayed', filterByDisplayed); + formData.append('sortByDisplayOrder', sortByDisplayOrder); + if (filterByDisplayed) { formData.append('displayed', displayed); } - formData.append('allSites', allSites); formData.append('filterByPermissions', filterByPermissions); const params = new URLSearchParams(formData).toString(); diff --git a/webapp/portlet/src/main/webapp/vue-apps/hamburger-menu/components/HamburgerMenuNavigation.vue b/webapp/portlet/src/main/webapp/vue-apps/hamburger-menu/components/HamburgerMenuNavigation.vue index 0dd00b1f2a0..556d88edfff 100644 --- a/webapp/portlet/src/main/webapp/vue-apps/hamburger-menu/components/HamburgerMenuNavigation.vue +++ b/webapp/portlet/src/main/webapp/vue-apps/hamburger-menu/components/HamburgerMenuNavigation.vue @@ -312,7 +312,7 @@ export default { }, retrieveSites(){ if (eXo.env.portal.newLeftNavigationDrawer) { - return this.$siteService.getSites('PORTAL', 'global', true, true, false, true) + return this.$siteService.getSites('PORTAL', null, 'global', true, true, true, true, true, true, true) .then(data => this.sites = data || []); } },