Skip to content

Commit

Permalink
[EUREKA-561-2]. (ECS) Can open/unopen order with PO line locations fr…
Browse files Browse the repository at this point in the history
…om 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

(cherry picked from commit 4fc7f1b)
  • Loading branch information
BKadirkhodjaev authored and SerhiiNosko committed Dec 10, 2024
1 parent beb2e66 commit ab12cdc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/folio/helper/PurchaseOrderLineHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -736,13 +737,22 @@ private Future<Void> 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();
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/folio/service/ProtectionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Future<Void> isOperationRestricted(List<String> unitIds, ProtectedOperati
*/
public Future<Void> isOperationRestricted(List<String> unitIds, Set<ProtectedOperationType> operations, RequestContext requestContext) {
if (userHasDesiredPermission(BYPASS_ACQ_UNITS, requestContext)) {
log.info("isOperationRestricted:: Bypassing checking acq units");
return Future.succeededFuture();
}
if (CollectionUtils.isNotEmpty(unitIds)) {
Expand All @@ -81,6 +82,7 @@ public Future<Void> isOperationRestricted(List<String> unitIds, Set<ProtectedOpe
.collect(Collectors.toList());

if (!activeUnits.isEmpty() && applyMergingStrategy(activeUnits, operations)) {
log.info("isOperationRestricted:: Acq unit ids are merged");
return verifyUserIsMemberOfOrdersUnits(extractUnitIds(activeUnits), requestContext);
}
return Future.succeededFuture();
Expand All @@ -90,6 +92,7 @@ public Future<Void> isOperationRestricted(List<String> unitIds, Set<ProtectedOpe
}
});
} else {
log.info("isOperationRestricted:: Acq unit ids are empty");
return Future.succeededFuture();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ private CompletableFuture<Optional<ConsortiumConfiguration>> 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.<ConsortiumConfiguration>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();
}
Expand Down

0 comments on commit ab12cdc

Please sign in to comment.