From 018316fe2856d432f3a393758f7bfd8e28e0badf Mon Sep 17 00:00:00 2001 From: BKadirkhodjaev Date: Mon, 2 Dec 2024 22:42:36 +0500 Subject: [PATCH 1/5] [EUREKA-561-2]. (ECS) Can open/unopen order with PO line locations from tenant in which user does not have affiliation --- ramls/acq-models | 2 +- src/main/java/org/folio/helper/PurchaseOrderLineHelper.java | 4 ++++ src/main/java/org/folio/service/ProtectionService.java | 3 +++ .../service/consortium/ConsortiumConfigurationService.java | 4 ++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ramls/acq-models b/ramls/acq-models index c0c72775d..308fa7ac5 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit c0c72775d08c28a77d1475df435497e8b0020667 +Subproject commit 308fa7ac549d4ffe2bbf187c4401027507cf342b diff --git a/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java b/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java index 5ea8e94f5..4dcdda703 100644 --- a/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java +++ b/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java @@ -736,13 +736,16 @@ 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); if (!SetUtils.isEqualSet(storageUnaffiliatedLocations, updatedUnaffiliatedLocations)) { + logger.info("validateUserUnaffiliatedLocationUpdates:: User is not affiliated with all locations on the POL"); return Future.failedFuture(new HttpException(422, ErrorCodes.LOCATION_UPDATE_WITHOUT_AFFILIATION)); } + logger.info("validateUserUnaffiliatedLocationUpdates:: User is affiliated with all locations on the POL"); return Future.succeededFuture(); }); } @@ -829,6 +832,7 @@ private Future verifyDeleteAllowed(PoLine line, RequestContext requestCont } private Future createShadowInstanceIfNeeded(CompositePoLine compositePoLine, RequestContext requestContext) { + logger.info("createShadowInstanceIfNeeded:: Creating shadow instance if needed"); String instanceId = compositePoLine.getInstanceId(); if (Boolean.TRUE.equals(compositePoLine.getIsPackage()) || Objects.isNull(instanceId)) { 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..78a9c4af3 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:: No desired permissions found"); 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.info("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(); } From fa60b1144b13e0bd21334475d4bf4640bfd5422a Mon Sep 17 00:00:00 2001 From: BKadirkhodjaev Date: Mon, 2 Dec 2024 22:45:15 +0500 Subject: [PATCH 2/5] [EUREKA-561-2]. Update acq-models --- ramls/acq-models | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ramls/acq-models b/ramls/acq-models index c0c72775d..308fa7ac5 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit c0c72775d08c28a77d1475df435497e8b0020667 +Subproject commit 308fa7ac549d4ffe2bbf187c4401027507cf342b From 0aac228af130fff52939ebbdd3b5c8ce9674c8e4 Mon Sep 17 00:00:00 2001 From: BKadirkhodjaev Date: Mon, 2 Dec 2024 22:50:02 +0500 Subject: [PATCH 3/5] [EUREKA-561-2]. Update acq-models --- ramls/acq-models | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ramls/acq-models b/ramls/acq-models index 308fa7ac5..c0c72775d 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit 308fa7ac549d4ffe2bbf187c4401027507cf342b +Subproject commit c0c72775d08c28a77d1475df435497e8b0020667 From 8a009c153b3b6a506f5f0c876ac634826c66869f Mon Sep 17 00:00:00 2001 From: BKadirkhodjaev Date: Tue, 3 Dec 2024 12:36:13 +0500 Subject: [PATCH 4/5] [EUREKA-561-2]. Update logs --- src/main/java/org/folio/helper/PurchaseOrderLineHelper.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java b/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java index 4dcdda703..163532062 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; @@ -741,6 +742,9 @@ private Future validateUserUnaffiliatedLocationUpdates(CompositePoLine upd } var storageUnaffiliatedLocations = extractUnaffiliatedLocations(storedPoLine.getLocations(), userTenants); var updatedUnaffiliatedLocations = extractUnaffiliatedLocations(updatedPoLine.getLocations(), userTenants); + logger.info("validateUserUnaffiliatedLocationUpdates:: Found unaffiliated location tenant ids: stored: '{}', updated: '{}'", + storageUnaffiliatedLocations.stream().map(Location::getTenantId).toList(), + updatedUnaffiliatedLocations.stream().map(Location::getTenantId).toList()); if (!SetUtils.isEqualSet(storageUnaffiliatedLocations, updatedUnaffiliatedLocations)) { logger.info("validateUserUnaffiliatedLocationUpdates:: User is not affiliated with all locations on the POL"); return Future.failedFuture(new HttpException(422, ErrorCodes.LOCATION_UPDATE_WITHOUT_AFFILIATION)); From 59e2b3c13b22581ed8838763bb709c780e0463b2 Mon Sep 17 00:00:00 2001 From: BKadirkhodjaev Date: Tue, 3 Dec 2024 13:53:04 +0500 Subject: [PATCH 5/5] [EUREKA-561-2]. Apply recommendations --- .../org/folio/helper/PurchaseOrderLineHelper.java | 14 ++++++++------ .../java/org/folio/service/ProtectionService.java | 6 +++--- .../consortium/ConsortiumConfigurationService.java | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java b/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java index 163532062..ee2cb4824 100644 --- a/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java +++ b/src/main/java/org/folio/helper/PurchaseOrderLineHelper.java @@ -742,14 +742,17 @@ private Future validateUserUnaffiliatedLocationUpdates(CompositePoLine upd } var storageUnaffiliatedLocations = extractUnaffiliatedLocations(storedPoLine.getLocations(), userTenants); var updatedUnaffiliatedLocations = extractUnaffiliatedLocations(updatedPoLine.getLocations(), userTenants); - logger.info("validateUserUnaffiliatedLocationUpdates:: Found unaffiliated location tenant ids: stored: '{}', updated: '{}'", - storageUnaffiliatedLocations.stream().map(Location::getTenantId).toList(), - updatedUnaffiliatedLocations.stream().map(Location::getTenantId).toList()); + 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"); + 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"); + logger.info("validateUserUnaffiliatedLocationUpdates:: User is affiliated with all locations on the POL, poLineId: '{}'", + updatedPoLine.getId()); return Future.succeededFuture(); }); } @@ -836,7 +839,6 @@ private Future verifyDeleteAllowed(PoLine line, RequestContext requestCont } private Future createShadowInstanceIfNeeded(CompositePoLine compositePoLine, RequestContext requestContext) { - logger.info("createShadowInstanceIfNeeded:: Creating shadow instance if needed"); String instanceId = compositePoLine.getInstanceId(); if (Boolean.TRUE.equals(compositePoLine.getIsPackage()) || Objects.isNull(instanceId)) { return Future.succeededFuture(); diff --git a/src/main/java/org/folio/service/ProtectionService.java b/src/main/java/org/folio/service/ProtectionService.java index 78a9c4af3..a8ede907e 100644 --- a/src/main/java/org/folio/service/ProtectionService.java +++ b/src/main/java/org/folio/service/ProtectionService.java @@ -69,7 +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:: No desired permissions found"); + log.info("isOperationRestricted:: Bypassing checking acq units"); return Future.succeededFuture(); } if (CollectionUtils.isNotEmpty(unitIds)) { @@ -82,7 +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.info("getConsortiumConfigurationFromRemote:: 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);