From 8546b117032c07f1a25f3a384e73040e5de87edb Mon Sep 17 00:00:00 2001 From: Ryan Eby Date: Thu, 15 Aug 2019 10:13:42 -0400 Subject: [PATCH 1/3] fail if asset copy not found --- iNCIPit.cgi | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/iNCIPit.cgi b/iNCIPit.cgi index cecd146..97fc5fa 100644 --- a/iNCIPit.cgi +++ b/iNCIPit.cgi @@ -517,10 +517,19 @@ sub item_cancelled { } else { # we are the item agency unless ( $conf->{behavior}->{no_item_agency_holds} =~ m/^y/i ) { + # Make sure the copy exists! + my $copy = copy_from_barcode($barcode); + # If copy does not exist, return failure + if (ref($copy) eq "HASH") { + if ($copy->{textcode} eq 'ASSET_COPY_NOT_FOUND') { + staff_log( $taidValue, $faidValue, "Bad Barcode Requested: ". $barcode ); + fail("cancel request on non-existent item"); + exit; + } + } # remove hold! my $r = cancel_hold($barcode); - # TODO: check for any errors or unexpected return values in $r - my $copy = copy_from_barcode($barcode); + fail( $copy->{textcode} . " $barcode" ) unless ( blessed $copy); $r = update_copy( $copy, 7 ); # set to reshelving (for wiggle room) # TODO: check for any errors or unexpected return values in $r From a016ffdd9d13ce31ea8ccb0cc104290e7ad67c04 Mon Sep 17 00:00:00 2001 From: Ryan Eby Date: Thu, 15 Aug 2019 10:17:52 -0400 Subject: [PATCH 2/3] additional check in copy_from_barcode --- iNCIPit.cgi | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/iNCIPit.cgi b/iNCIPit.cgi index 97fc5fa..94c67a3 100644 --- a/iNCIPit.cgi +++ b/iNCIPit.cgi @@ -1412,7 +1412,11 @@ sub copy_from_barcode { OpenSRF::AppSession->create('open-ils.search') ->request( 'open-ils.search.asset.copy.find_by_barcode', $barcode ) ->gather(1); - return $response; + if (ref($response) eq 'HASH') { + return undef; + } else { + return $response; + } } sub locid_from_barcode { From 5a9bc0d7a5cee03d14b7cf7293edbc41da41e546 Mon Sep 17 00:00:00 2001 From: Ryan Eby Date: Thu, 15 Aug 2019 10:25:05 -0400 Subject: [PATCH 3/3] do the checks in the item_cancelled sub for better log information --- iNCIPit.cgi | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/iNCIPit.cgi b/iNCIPit.cgi index 94c67a3..1fbf06b 100644 --- a/iNCIPit.cgi +++ b/iNCIPit.cgi @@ -511,6 +511,13 @@ sub item_cancelled { # we are the user agency $barcode .= $faidValue; my $copy = copy_from_barcode($barcode); + if (ref($copy) eq "HASH") { + if ($copy->{textcode} eq 'ASSET_COPY_NOT_FOUND') { + staff_log( $taidValue, $faidValue, "Bad Barcode Requested: ". $barcode ); + fail("cancel request on non-existent item"); + exit; + } + } fail( $copy->{textcode} . " $barcode" ) unless ( blessed $copy); my $r = cancel_hold($barcode); $r = delete_copy($copy); @@ -1412,11 +1419,7 @@ sub copy_from_barcode { OpenSRF::AppSession->create('open-ils.search') ->request( 'open-ils.search.asset.copy.find_by_barcode', $barcode ) ->gather(1); - if (ref($response) eq 'HASH') { - return undef; - } else { - return $response; - } + return $response; } sub locid_from_barcode {