From 11960d5424ec448523230e54f2ef178c4d2d0027 Mon Sep 17 00:00:00 2001 From: saba_zedginidze Date: Thu, 19 Sep 2024 15:53:34 +0400 Subject: [PATCH] [MODORDERS-1143] Fix filtering for member tenants --- .../java/org/folio/service/pieces/PieceStorageService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/folio/service/pieces/PieceStorageService.java b/src/main/java/org/folio/service/pieces/PieceStorageService.java index fe5b9d101..f03cd2f82 100644 --- a/src/main/java/org/folio/service/pieces/PieceStorageService.java +++ b/src/main/java/org/folio/service/pieces/PieceStorageService.java @@ -25,6 +25,7 @@ import org.folio.rest.jaxrs.model.PieceCollection; import io.vertx.core.Future; +import org.folio.rest.tools.utils.TenantTool; import org.folio.service.consortium.ConsortiumUserTenantsRetriever; import org.folio.service.consortium.ConsortiumConfigurationService; @@ -136,6 +137,7 @@ public Future getAllPieces(int limit, int offset, String query, private Future> filterPiecesByUserTenantsIfNecessary(List pieces, RequestContext requestContext) { return consortiumConfigurationService.getConsortiumConfiguration(requestContext) .compose(consortiumConfiguration -> consortiumConfiguration + .filter(configuration -> shouldFilterPiecesForTenant(configuration.centralTenantId(), requestContext)) .map(configuration -> consortiumUserTenantsRetriever.getUserTenants(configuration.consortiumId(), requestContext) .map(userTenants -> filterPiecesByUserTenants(pieces, userTenants))) .orElse(Future.succeededFuture(pieces))); @@ -185,4 +187,9 @@ private Future> getPieceChunkByLineIds(Collection poLineIds, .map(PieceCollection::getPieces); } + private static boolean shouldFilterPiecesForTenant(String centralTenantId, RequestContext requestContext) { + var requestTenantId = TenantTool.tenantId(requestContext.getHeaders()); + return requestTenantId.equals(centralTenantId); + } + }