Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Adding support for listing templates across multiple sites #31086

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,26 @@ public final Response list(@Context final HttpServletRequest httpRequest,
final InitDataObject initData = new WebResource.InitBuilder(webResource)
.requestAndResponse(httpRequest, httpResponse).rejectWhenNoUser(true).init();
final User user = initData.getUser();
final Lazy<String> lazyCurrentHost = Lazy.of(() -> Try.of(() -> Host.class.cast(httpRequest.getSession().getAttribute(WebKeys.CURRENT_HOST)).getIdentifier()).getOrNull());
final Optional<String> checkedHostId = Optional.ofNullable(Try.of(()-> APILocator.getHostAPI()
.find(hostId, user, false).getIdentifier()).getOrElse(lazyCurrentHost.get()));


Logger.debug(this, ()-> "Getting the List of templates");

final Map<String, Object> extraParams = new HashMap<>();
extraParams.put(ARCHIVE_PARAM, archive);
checkedHostId.ifPresent(checkedHostIdentifier -> extraParams.put(ContainerPaginator.HOST_PARAMETER_ID, checkedHostIdentifier));

//In case we need to get the list of templates across multiple sites, we don't set the TemplatePaginator.HOST_PARAMETER_ID
if (null == hostId || !StringPool.STAR.equals(hostId)) {
final Lazy<String> lazyCurrentHost = Lazy.of(() -> Try.of(() -> Host.class.cast(
httpRequest.getSession().getAttribute(WebKeys.CURRENT_HOST)).getIdentifier())
.getOrNull());
final Optional<String> checkedHostId = Optional.ofNullable(
Try.of(() -> APILocator.getHostAPI()
.find(hostId, user, false).getIdentifier())
.getOrElse(lazyCurrentHost.get()));
checkedHostId.ifPresent(
checkedHostIdentifier -> extraParams.put(TemplatePaginator.HOST_PARAMETER_ID,
checkedHostIdentifier));
}
return this.paginationUtil.getPage(httpRequest, user, filter, page, perPage, orderBy, OrderDirection.valueOf(direction),
extraParams);
}
Expand Down
Loading