Bug 31391: (QA follow-up) Fix UseRecalls check in Transfers REST controller

UseRecalls was converted from a YesNo syspref to a Choice preference
("off"/"opac"/"staff"/"opac_and_staff") earlier in this bug, and every
call site was updated from a truthy check to `ne "off"` - except this
one. Since even the string "off" is truthy in Perl, the guard in
Koha::REST::V1::Transfers::cancel was silently defeated: cancelling a
transfer via the REST API always attempted to revert an in-transit
recall, even with recalls disabled.

Test plan:
1) prove t/db_dependent/api/v1/transfers.t - new subtest
   'cancel() - UseRecalls disabled' fails against the old code
   (the in-transit recall gets reverted even though UseRecalls is off)
2) Apply this patch
3) Same test now passes

Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2026-09-15 11:10:58 +01:00 committed by Pedro Amorim
parent 85c37deb77
commit cd30d78c0e
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
2 changed files with 56 additions and 2 deletions

View File

@ -97,7 +97,7 @@ sub cancel {
# Koha::Checkin->cancel_transfer. It really belongs one level down,
# in Koha::Item::Transfer->cancel, so that *every* transfer
# cancellation reverts an in-transit recall regardless of the caller.
if ( C4::Context->preference('UseRecalls') ) {
if ( C4::Context->preference('UseRecalls') ne "off" ) {
my $recall = Koha::Recalls->find( { item_id => $transfer->itemnumber, status => 'in_transit' } );
$recall->revert_transfer if $recall;
}

View File

@ -18,7 +18,7 @@
use Modern::Perl;
use Test::NoWarnings;
use Test::More tests => 4;
use Test::More tests => 5;
use Test::Mojo;
use t::lib::TestBuilder;
@ -277,3 +277,57 @@ subtest 'cancel() - UseRecalls integration' => sub {
$schema->storage->txn_rollback;
};
subtest 'cancel() - UseRecalls disabled' => sub {
plan tests => 3;
$schema->storage->txn_begin;
t::lib::Mocks::mock_preference( 'UseRecalls', 'off' );
my $librarian = $builder->build_object(
{
class => 'Koha::Patrons',
value => { flags => 2**1 } # circulate flag = 1
}
);
my $password = 'thePassword123';
$librarian->set_password( { password => $password, skip_validation => 1 } );
my $userid = $librarian->userid;
my $item = $builder->build_sample_item;
my $transfer = $builder->build_object(
{
class => 'Koha::Item::Transfers',
value => {
itemnumber => $item->itemnumber,
datesent => \'NOW()',
datearrived => undef,
datecancelled => undef,
}
}
);
my $recall = $builder->build_object(
{
class => 'Koha::Recalls',
value => {
item_id => $item->itemnumber,
status => 'in_transit',
}
}
);
$t->post_ok( "//$userid:$password@/api/v1/transfers/"
. $transfer->id
. "/cancellation" => json => { cancellation_reason => 'Manual' } )->status_is(200);
$recall->discard_changes;
is(
$recall->status, 'in_transit',
'The in-transit recall was left untouched when UseRecalls is off'
);
$schema->storage->txn_rollback;
};