From 29d4cfbdb8c448db81338d301733d5b13fa353ec Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 21 Dec 2020 11:05:26 +0100 Subject: [PATCH] Bug 27004: Prevent claim resolution to fail If the account of the patron who created a claim is removed, then the claim won't be resolvable. Trying to resolve the claim will result in a 500: [2020/12/21 10:05:55] [ERROR] PUT /api/v1/return_claims/1/resolve: unhandled exception (Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy)<<[created_by is mandatory]>> Koha::REST::Plugin::Exceptions::__ANON We should not check if created_by exist when we update an existing hold, only when we create it. Test plan: - Login with patron A - set a value to syspref ClaimReturnedLostValue - Check an item out - Claim returned it - Login with patron B - Delete patron A - Resolve the claim - ERROR in api-error.log an UI never confirming the resolution - apply patch & restart services - Resolve the claim - it works Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart (cherry picked from commit 92dbe809021ea1f7ee44e51387b48d9ffbda1fea) Signed-off-by: Fridolin Somers (cherry picked from commit 8e3f33e5d6e79d2df1a5077e4dc68364867566c9) Signed-off-by: Andrew Fuerste-Henry (cherry picked from commit a5c20fc188c634fc8c7b6d00f542dc7589d2e9a8) Signed-off-by: Victor Grousset/tuxayo --- Koha/Checkouts/ReturnClaim.pm | 2 +- t/db_dependent/api/v1/return_claims.t | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Koha/Checkouts/ReturnClaim.pm b/Koha/Checkouts/ReturnClaim.pm index 9c49bbf8c4..cb0c12556d 100644 --- a/Koha/Checkouts/ReturnClaim.pm +++ b/Koha/Checkouts/ReturnClaim.pm @@ -48,7 +48,7 @@ exceptions as needed. sub store { my ( $self ) = @_; - unless ( $self->created_by ) { + unless ( $self->in_storage || $self->created_by ) { Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy->throw(); } diff --git a/t/db_dependent/api/v1/return_claims.t b/t/db_dependent/api/v1/return_claims.t index 382248a548..883fbd65c2 100644 --- a/t/db_dependent/api/v1/return_claims.t +++ b/t/db_dependent/api/v1/return_claims.t @@ -204,6 +204,8 @@ subtest 'resolve_claim() tests' => sub { my $claim_id = $claim->id; + $claim->created_by(undef)->store; # resolve the claim must work even if the created_by patron has been removed + # Resolve a claim $t->put_ok( "//$userid:$password@/api/v1/return_claims/$claim_id/resolve" => json => { -- 2.39.5