Bug 33470: Don't calculate overridden hold limits

This patch can largely be checked in the code to ensure it makes sense, it
moves a conditional up one level for the two different checks that could prevent holds

To test:
1 - Attempt to place a hold via the REST API with an invalid pickup location
    Set pickup location as no in branches to make this easy
2 - Confirm you get an error
3 - Attempt again with header (bug 27760):
    x-koha-override: any
4 - Hold is placed
5 - Repeat 1-4 above but with an item that cannot be held
6 - Apply patch
7 - Repeat 1-4 above
8 - Results should be the same

Signed-off-by: Emily Lamancusa <emily.lamancusa@montgomerycountymd.gov>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2023-04-09 18:25:41 +00:00 committed by Tomas Cohen Arazi
parent e074ffa6be
commit e3c31212df
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -143,43 +143,46 @@ sub add {
);
}
# Validate pickup location
my $valid_pickup_location;
if ($item) { # item-level hold
$valid_pickup_location =
any { $_->branchcode eq $pickup_library_id }
$item->pickup_locations(
{ patron => $patron } )->as_list;
}
else {
$valid_pickup_location =
any { $_->branchcode eq $pickup_library_id }
$biblio->pickup_locations(
{ patron => $patron } )->as_list;
}
return $c->render(
status => 400,
openapi => {
error => 'The supplied pickup location is not valid'
# If the hold is being forced, no need to validate
unless( $can_override ){
# Validate pickup location
my $valid_pickup_location;
if ($item) { # item-level hold
$valid_pickup_location =
any { $_->branchcode eq $pickup_library_id }
$item->pickup_locations(
{ patron => $patron } )->as_list;
}
else {
$valid_pickup_location =
any { $_->branchcode eq $pickup_library_id }
$biblio->pickup_locations(
{ patron => $patron } )->as_list;
}
) unless $valid_pickup_location || $can_override;
my $can_place_hold
= $item
? C4::Reserves::CanItemBeReserved( $patron, $item )
: C4::Reserves::CanBookBeReserved( $patron_id, $biblio_id );
if ( C4::Context->preference('maxreserves') && $patron->holds->count + 1 > C4::Context->preference('maxreserves') ) {
$can_place_hold->{status} = 'tooManyReserves';
}
unless ( $can_override || $can_place_hold->{status} eq 'OK' ) {
return $c->render(
status => 403,
openapi =>
{ error => "Hold cannot be placed. Reason: " . $can_place_hold->{status} }
);
status => 400,
openapi => {
error => 'The supplied pickup location is not valid'
}
) unless $valid_pickup_location;
my $can_place_hold
= $item
? C4::Reserves::CanItemBeReserved( $patron, $item )
: C4::Reserves::CanBookBeReserved( $patron_id, $biblio_id );
if ( C4::Context->preference('maxreserves') && $patron->holds->count + 1 > C4::Context->preference('maxreserves') ) {
$can_place_hold->{status} = 'tooManyReserves';
}
unless ( $can_place_hold->{status} eq 'OK' ) {
return $c->render(
status => 403,
openapi =>
{ error => "Hold cannot be placed. Reason: " . $can_place_hold->{status} }
);
}
}
my $priority = C4::Reserves::CalculatePriority($biblio_id);