From 38708ffc8006e7f6c8aeb6829cddd1f6e1d6c86b Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 17 Apr 2025 13:05:16 +0000 Subject: [PATCH] Bug 38441: (QA follow-up): Only look for matchin requests if patron Previous commit 'HistoryCheck now only considers same patron' added the following regression: HistoryCheck is performed and shown in the OPAC even if no user is authenticated (using ILLOpacUnauthenticatedRequest). This fixes that. History check is skipped unless a user exists. Signed-off-by: Tomas Cohen Arazi --- Koha/ILL/Request/Workflow/HistoryCheck.pm | 4 +++- t/db_dependent/Koha/ILL/Request/Workflow/HistoryCheck.t | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Koha/ILL/Request/Workflow/HistoryCheck.pm b/Koha/ILL/Request/Workflow/HistoryCheck.pm index 5a3eefbddf4..818f2f4c742 100644 --- a/Koha/ILL/Request/Workflow/HistoryCheck.pm +++ b/Koha/ILL/Request/Workflow/HistoryCheck.pm @@ -195,8 +195,10 @@ sub _find_matching_requests { my $patron = Koha::Patrons->find( { cardnumber => $self->{metadata}->{cardnumber} } ); + return 0 unless $patron; + my $query; - $query->{'-and'} = [ { 'me.borrowernumber' => $patron->borrowernumber } ] if $patron; + $query->{'-and'} = [ { 'me.borrowernumber' => $patron->borrowernumber } ]; foreach my $id_field (@existing_id_fields) { push @{ $query->{'-or'} }, { 'illrequestattributes.type' => $id_field, diff --git a/t/db_dependent/Koha/ILL/Request/Workflow/HistoryCheck.t b/t/db_dependent/Koha/ILL/Request/Workflow/HistoryCheck.t index e1f7a3a2fef..873ea4c30b1 100755 --- a/t/db_dependent/Koha/ILL/Request/Workflow/HistoryCheck.t +++ b/t/db_dependent/Koha/ILL/Request/Workflow/HistoryCheck.t @@ -126,14 +126,16 @@ subtest 'after_request_created' => sub { my $fake_cardnumber = '123456789'; my $metadata = { - title => 'This is a title', - author => 'This is an author', - isbn => $isbn + title => 'This is a title', + author => 'This is an author', + isbn => $isbn, + cardnumber => $fake_cardnumber, }; my $authenticated_patron = $builder->build_object( { class => 'Koha::Patrons', + value => { cardnumber => $fake_cardnumber } } ); -- 2.39.5