From 4fc7f1bfeff59d4cd2b06daab179c9413b3c8d1b Mon Sep 17 00:00:00 2001 From: Boburbek Kadirkhodjaev Date: Tue, 3 Dec 2024 14:06:41 +0500 Subject: [PATCH] [EUREKA-561-2]. (ECS) Can open/unopen order with PO line locations from tenant in which user does not have affiliation (#1057) * [EUREKA-561-2]. (ECS) Can open/unopen order with PO line locations from tenant in which user does not have affiliation * [EUREKA-561-2]. Update acq-models * [EUREKA-561-2]. Update acq-models * [EUREKA-561-2]. Update logs * [EUREKA-561-2]. Apply recommendations --- .../java/org/folio/helper/PurchaseOrderLineHelper.java | 10 ++++++++++ src/main/java/org/folio/service/ProtectionService.java | 3 +++ .../consortium/ConsortiumConfigurationService.java | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java b/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java index 5ea8e94f5..ee2cb4824 100644 --- a/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java +++ b/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java @@ -70,6 +70,7 @@ import org.folio.rest.jaxrs.model.Error; import org.folio.rest.jaxrs.model.Errors; import org.folio.rest.jaxrs.model.FundDistribution; +import org.folio.rest.jaxrs.model.Location; import org.folio.rest.jaxrs.model.Physical; import org.folio.rest.jaxrs.model.PoLine; import org.folio.rest.jaxrs.model.PoLineCollection; @@ -736,13 +737,22 @@ private Future validateUserUnaffiliatedLocationUpdates(CompositePoLine upd return getUserTenantsIfNeeded(requestContext) .compose(userTenants -> { if (CollectionUtils.isEmpty(userTenants)) { + logger.info("validateUserUnaffiliatedLocationUpdates:: User tenants is empty"); return Future.succeededFuture(); } var storageUnaffiliatedLocations = extractUnaffiliatedLocations(storedPoLine.getLocations(), userTenants); var updatedUnaffiliatedLocations = extractUnaffiliatedLocations(updatedPoLine.getLocations(), userTenants); + logger.info("validateUserUnaffiliatedLocationUpdates:: Found unaffiliated POL location tenant ids, poLineId: '{}', stored: '{}', updated: '{}'", + updatedPoLine.getId(), + storageUnaffiliatedLocations.stream().map(Location::getTenantId).distinct().toList(), + updatedUnaffiliatedLocations.stream().map(Location::getTenantId).distinct().toList()); if (!SetUtils.isEqualSet(storageUnaffiliatedLocations, updatedUnaffiliatedLocations)) { + logger.info("validateUserUnaffiliatedLocationUpdates:: User is not affiliated with all locations on the POL, poLineId: '{}'", + updatedPoLine.getId()); return Future.failedFuture(new HttpException(422, ErrorCodes.LOCATION_UPDATE_WITHOUT_AFFILIATION)); } + logger.info("validateUserUnaffiliatedLocationUpdates:: User is affiliated with all locations on the POL, poLineId: '{}'", + updatedPoLine.getId()); return Future.succeededFuture(); }); } diff --git a/src/main/java/org/folio/service/ProtectionService.java b/src/main/java/org/folio/service/ProtectionService.java index 2984f531b..a8ede907e 100644 --- a/src/main/java/org/folio/service/ProtectionService.java +++ b/src/main/java/org/folio/service/ProtectionService.java @@ -69,6 +69,7 @@ public Future isOperationRestricted(List unitIds, ProtectedOperati */ public Future isOperationRestricted(List unitIds, Set operations, RequestContext requestContext) { if (userHasDesiredPermission(BYPASS_ACQ_UNITS, requestContext)) { + log.info("isOperationRestricted:: Bypassing checking acq units"); return Future.succeededFuture(); } if (CollectionUtils.isNotEmpty(unitIds)) { @@ -81,6 +82,7 @@ public Future isOperationRestricted(List unitIds, Set isOperationRestricted(List unitIds, Set> getConsortiumConfig .map(jsonObject -> jsonObject.getJsonArray(USER_TENANTS_ARRAY_IDENTIFIER)) .map(userTenants -> { if (userTenants.isEmpty()) { - logger.debug("Central tenant and consortium id not found"); + logger.debug("getConsortiumConfigurationFromRemote:: Central tenant and consortium id not found"); return Optional.empty(); } String consortiumId = userTenants.getJsonObject(0).getString(CONSORTIUM_ID_FIELD); String centralTenantId = userTenants.getJsonObject(0).getString(CENTRAL_TENANT_ID_FIELD); - logger.debug("Found centralTenantId: {} and consortiumId: {}", centralTenantId, consortiumId); + logger.info("getConsortiumConfigurationFromRemote:: Found centralTenantId: {} and consortiumId: {}", centralTenantId, consortiumId); return Optional.of(new ConsortiumConfiguration(centralTenantId, consortiumId)); }).toCompletionStage().toCompletableFuture(); }