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

[EUREKA-561-2]. (ECS) Can open/unopen order with PO line locations from tenant in which user does not have affiliation #1057

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 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,19 @@ 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 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");
SerhiiNosko marked this conversation as resolved.
Show resolved Hide resolved
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();
});
}
Expand Down Expand Up @@ -829,6 +836,7 @@ private Future<Void> verifyDeleteAllowed(PoLine line, RequestContext requestCont
}

private Future<Void> createShadowInstanceIfNeeded(CompositePoLine compositePoLine, RequestContext requestContext) {
logger.info("createShadowInstanceIfNeeded:: Creating shadow instance if needed");
SerhiiNosko marked this conversation as resolved.
Show resolved Hide resolved
String instanceId = compositePoLine.getInstanceId();
if (Boolean.TRUE.equals(compositePoLine.getIsPackage()) || Objects.isNull(instanceId)) {
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:: No desired permissions found");
SerhiiNosko marked this conversation as resolved.
Show resolved Hide resolved
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:: 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:: 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.info("getConsortiumConfigurationFromRemote:: Central tenant and consortium id not found");
SerhiiNosko marked this conversation as resolved.
Show resolved Hide resolved
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