Bug 22379: Fix checks not made by ILS-DI method CancelHold

Disable the possibility for a borrower to cancel a reservation
which is either in a Transit or Waiting state.
This reproduce the behaviour seen on the OPAC.
Also replaces previous checks on the borrowernumber
since CanReserveBeCanceledFromOpac already checks this.

--------------------------------

Test plan (before patch) :
-Put a reserve for a borrower
-Try to cancel the reserve providing another borrowernumber as argument
	-> Should fail and reply "RecordNotFound"
	-> Reserve still appears in the list of holds.

-Try to cancel the reserve providing the borrowernumber the reserve is
for.
	-> Should succeed, reply with "Canceled"
	-> Reserve do not show up in the list of holds for the borrower

-Put a new reserve with a pickup branch != from the homebranch
-Transfer the item to the pickup branch (reserve status = Transit)
-Try to cancel the reserve (with proper borrowernumber)
	-> Should succeed, reply with "Canceled"
	-> Reserve do not show up in the list of holds for the borrower

-Checkout the reserved item in the pickup branch (reserve status =
Waiting)
-Try to cancel the reserve (with proper borrowernumber)
	-> Should succeed, reply with "Canceled"
	-> Reserve do not show up in the list of holds for the borrower

--------------------------------

Test plan (after patch) :
-Put a reserve for a borrower
-Try to cancel the reserve providing another borrowernumber as argument
	-> Should fail and reply "BorrowerCannotCancelHold"
	-> Reserve still appears in the list of holds.

-Try to cancel the reserve providing the borrowernumber the reserve is
for.
	-> Should succeed, reply with "Canceled"
	-> Reserve do not show up in the list of holds for the borrower

-Put a new reserve with a pickup branch != from the homebranch
-Transfer the item to the pickup branch (reserve status = Transit)
-Try to cancel the reserve (with proper borrowernumber)
	-> Should fail and reply "BorrowerCannotCancelHold"
	-> Reserve still appears in the list of holds.

-Checkout the reserved item in the pickup branch (reserve status =
Waiting)
-Try to cancel the reserve (with proper borrowernumber)
	-> Should fail and reply "BorrowerCannotCancelHold"
	-> Reserve still appears in the list of holds.

Signed-off-by: Laurence Rault <laurence.rault@biblibre.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Arthur Suzuki 2019-02-20 21:15:44 +01:00 committed by Fridolin Somers
parent 8df782ddba
commit c29eeea109
1 changed files with 4 additions and 2 deletions

View File

@ -25,7 +25,7 @@ use C4::Items qw( get_hostitemnumbers_of );
use C4::Circulation qw( CanBookBeRenewed barcodedecode CanBookBeIssued AddRenewal );
use C4::Accounts;
use C4::Biblio qw( GetMarcBiblio );
use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved );
use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved CanReserveBeCanceledFromOpac);
use C4::Context;
use C4::Auth;
use CGI qw ( -utf8 );
@ -937,7 +937,9 @@ sub CancelHold {
my $reserve_id = $cgi->param('item_id');
my $hold = Koha::Holds->find( $reserve_id );
return { code => 'RecordNotFound' } unless $hold;
return { code => 'RecordNotFound' } unless ($hold->borrowernumber == $borrowernumber);
# Check if reserve belongs to the borrower and if it is in a state which allows cancellation
return { code => 'BorrowerCannotCancelHold' } unless CanReserveBeCanceledFromOpac( $reserve_id, $borrowernumber );
$hold->cancel;