From 7c4a68324138f8c818da867512f4778411655ee4 Mon Sep 17 00:00:00 2001 From: erickgonzalez Date: Tue, 12 Dec 2023 12:21:40 -0600 Subject: [PATCH] #26980 include in 23.10.24 --- dotCMS/hotfix_tracking.md | 4 +- .../contentlet/business/HostFactoryImpl.java | 48 +++++++++++++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/dotCMS/hotfix_tracking.md b/dotCMS/hotfix_tracking.md index 02244f3dec9c..1a74469e363f 100644 --- a/dotCMS/hotfix_tracking.md +++ b/dotCMS/hotfix_tracking.md @@ -13,4 +13,6 @@ This maintenance release includes the following code fixes: 7. https://github.com/dotCMS/core/issues/26896 : Avoid Refreshing Properties #26896 8. https://github.com/dotCMS/core/issues/26933 : StorageProvider should load lazily #26933 9. https://github.com/dotCMS/core/issues/26926 : Add left indexes to inode.inode and identifier.id #26926 -10. https://github.com/dotCMS/core/issues/26970 : GraphQL Cache not working #26970 \ No newline at end of file +10. https://github.com/dotCMS/core/issues/26970 : GraphQL Cache not working #26970 +11. https://github.com/dotCMS/core/issues/26931 : Add Cache when getting Versionable info #26931 +12. https://github.com/dotCMS/core/issues/26980: SiteSelector not showing all possible sites for limited user #26980 \ No newline at end of file diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostFactoryImpl.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostFactoryImpl.java index c95c1c80e162..5a5054c4d402 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostFactoryImpl.java @@ -718,6 +718,36 @@ public long count() throws DotDataException { @VisibleForTesting protected Optional> search(final String siteNameFilter, final String condition, final boolean showSystemHost, final int limit, final int offset, final User user, final boolean respectFrontendRoles) { + return search(siteNameFilter,condition,showSystemHost,limit,offset,user,respectFrontendRoles,new ArrayList<>()); + } + + /** + * Returns the list of Sites – with pagination capabilities – that match the specified search criteria. This method + * allows users to specify three search parameters: + *
    + *
  1. {@code filter}: Finds Sites whose name starts with the specified String.
  2. + *
  3. {@code condition}: Determines if live, stopped, or archived Sites are returned in the result set.
  4. + *
  5. {@code showSystemHost}: Determines whether the System Host must be returned or not.
  6. + *
+ * + * @param siteNameFilter The initial part or full name of the Site you need to look up. If not required, set + * as {@code null} or empty. + * @param condition The status of the Site determined via SQL conditions. + * @param showSystemHost If the System Host object must be returned, set to {@code true}. Otherwise, se to + * {@code false}. + * @param limit Limit of results returned in the response, for pagination purposes. If set equal or + * lower than zero, this parameter will be ignored. + * @param offset Expected offset of results in the response, for pagination purposes. If set equal or + * lower than zero, this parameter will be ignored. + * @param user The {@link User} performing this action. + * @param respectFrontendRoles If the User's front-end roles need to be taken into account in order to perform this + * operation, set to {@code true}. Otherwise, set to {@code false}. + * + * @return The list of {@link Host} objects that match the specified search criteria. + */ + @VisibleForTesting + protected Optional> search(final String siteNameFilter, final String condition, final boolean + showSystemHost, final int limit, final int offset, final User user, final boolean respectFrontendRoles, List hostList) { final DotConnect dc = new DotConnect(); final StringBuilder sqlQuery = new StringBuilder().append(SELECT_SITE_INODE); sqlQuery.append(WHERE); @@ -754,12 +784,20 @@ protected Optional> search(final String siteNameFilter, final String try { final List> dbResults = dc.loadResults(); if (dbResults.isEmpty()) { - return Optional.empty(); + return Optional.of(hostList); + } + final List siteList = convertDbResultsToSites(dbResults); + if(user.isAdmin()){ + return Optional.of(siteList); + } + hostList.addAll(APILocator.getPermissionAPI().filterCollection(siteList, PermissionAPI + .PERMISSION_READ, respectFrontendRoles, user)); + hostList = hostList.stream().limit(limit).collect(Collectors.toList()); + if(hostList.size()==limit || siteList.size() < limit){//user is admin or reach the amount of sites requested or there is no anymore sites + return Optional.of(hostList); + }else { + return search(siteNameFilter, condition, showSystemHost, limit, offset + limit, user, respectFrontendRoles, hostList); } - List siteList = convertDbResultsToSites(dbResults); - siteList = APILocator.getPermissionAPI().filterCollection(siteList, PermissionAPI - .PERMISSION_READ, respectFrontendRoles, user); - return Optional.of(siteList); } catch (final Exception e) { Logger.error(this, String.format("An error occurred when searching for Sites based on the following " + "criteria: filter[ %s ], condition[ %s ], showSystemHost [ %s ]: %s", siteNameFilter, condition,