Skip to content

Commit

Permalink
#26980 include in 23.10.24
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Dec 12, 2023
1 parent 98d4e5e commit 7c4a683
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
4 changes: 3 additions & 1 deletion dotCMS/hotfix_tracking.md
Expand Up @@ -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
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
Expand Up @@ -718,6 +718,36 @@ public long count() throws DotDataException {
@VisibleForTesting
protected Optional<List<Host>> 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:
* <ol>
* <li>{@code filter}: Finds Sites whose name starts with the specified String.</li>
* <li>{@code condition}: Determines if live, stopped, or archived Sites are returned in the result set.</li>
* <li>{@code showSystemHost}: Determines whether the System Host must be returned or not.</li>
* </ol>
*
* @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<List<Host>> search(final String siteNameFilter, final String condition, final boolean
showSystemHost, final int limit, final int offset, final User user, final boolean respectFrontendRoles, List<Host> hostList) {
final DotConnect dc = new DotConnect();
final StringBuilder sqlQuery = new StringBuilder().append(SELECT_SITE_INODE);
sqlQuery.append(WHERE);
Expand Down Expand Up @@ -754,12 +784,20 @@ protected Optional<List<Host>> search(final String siteNameFilter, final String
try {
final List<Map<String, String>> dbResults = dc.loadResults();
if (dbResults.isEmpty()) {
return Optional.empty();
return Optional.of(hostList);
}
final List<Host> 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<Host> 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,
Expand Down

0 comments on commit 7c4a683

Please sign in to comment.