From 601dc30695d5bc16e9df97fd5b20acb58614c7c3 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 7 Dec 2021 04:08:18 +0000 Subject: [PATCH] Bug 24194: (follow-up) Throw an error if expiration date used --- C4/ILSDI/Services.pm | 8 ++++++-- C4/Reserves.pm | 6 +++++- Koha/Club/Hold.pm | 6 +++++- Koha/Exceptions/Hold.pm | 6 +++++- Koha/REST/V1/Clubs/Holds.pm | 9 ++++++++- Koha/REST/V1/Holds.pm | 9 ++++++++- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index b29e8033e6..13a196281a 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -779,8 +779,12 @@ sub HoldTitle { } my $expdate; - if ( C4::Context->preference('ReserveExpiration') and $cgi->param('expiry_date') ) { - $expdate = $cgi->param('expiry_date'); + if ( C4::Context->preference('ReserveExpiration') ) { + if ( $cgi->param('expiry_date') ) { + $expdate = $cgi->param('expiry_date'); + } + } else { + return { code => 'expirationDateDisabled' }; } # Add the reserve diff --git a/C4/Reserves.pm b/C4/Reserves.pm index f55b98e26d..86d0c7f845 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -185,7 +185,7 @@ sub AddReserve { my $biblionumber = $params->{biblionumber}; my $priority = $params->{priority}; my $resdate = $params->{reservation_date}; - my $expdate = C4::Context->preference('ReserveExpiration') ? $params->{expiration_date} : undef; + my $expdate = $params->{expiration_date}; my $notes = $params->{notes}; my $title = $params->{title}; my $checkitem = $params->{itemnumber}; @@ -193,6 +193,10 @@ sub AddReserve { my $itemtype = $params->{itemtype}; my $non_priority = $params->{non_priority}; + if ( !C4::Context->preference('ReserveExpiration') and $params->{expiration_date} ) { + Koha::Exceptions::Hold::ExpirationDateDisabled->throw; + } + $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' }) or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' }); diff --git a/Koha/Club/Hold.pm b/Koha/Club/Hold.pm index 63a0eef74b..baa37d8cda 100644 --- a/Koha/Club/Hold.pm +++ b/Koha/Club/Hold.pm @@ -69,6 +69,10 @@ sub add { Koha::Exceptions::ClubHold::NoPatrons->throw() unless scalar @enrollments; + if ( !C4::Context->preference('ReserveExpiration') and $params->{expiration_date} ) { + Koha::Exceptions::Hold::ExpirationDateDisabled->throw; + } + my $biblio = Koha::Biblios->find($params->{biblio_id}); my $club_params = { @@ -123,7 +127,7 @@ sub add { borrowernumber => $patron_id, biblionumber => $params->{biblio_id}, priority => $priority, - expiration_date => C4::Context->preference('ReserveExpiration') ? $params->{expiration_date} : undef, + expiration_date => $params->{expiration_date}, notes => $params->{notes}, title => $biblio->title, itemnumber => $params->{item_id}, diff --git a/Koha/Exceptions/Hold.pm b/Koha/Exceptions/Hold.pm index 65d7b9d9a9..bdb9bab2e6 100644 --- a/Koha/Exceptions/Hold.pm +++ b/Koha/Exceptions/Hold.pm @@ -31,7 +31,11 @@ use Exception::Class ( 'Koha::Exceptions::Hold::InvalidPickupLocation' => { isa => 'Koha::Exceptions::Hold', description => 'The supplied pickup location is not valid' - } + }, + 'Koha::Exceptions::Hold::ExpirationDateDisabled' => [ + isa => 'Koha::Exceptions::Hold', + description => 'Expiration date not allowed' + }, ); sub full_message { diff --git a/Koha/REST/V1/Clubs/Holds.pm b/Koha/REST/V1/Clubs/Holds.pm index 57f396135b..9050858956 100644 --- a/Koha/REST/V1/Clubs/Holds.pm +++ b/Koha/REST/V1/Clubs/Holds.pm @@ -54,7 +54,7 @@ sub add { my $pickup_library_id = $body->{pickup_library_id}; my $item_id = $body->{item_id}; my $item_type = $body->{item_type}; - my $expiration_date = C4::Context->preference('ReserveExpiration') ? $body->{expiration_date} : undef; + my $expiration_date = $body->{expiration_date}; my $notes = $body->{notes}; my $default_patron_home = $body->{default_patron_home}; @@ -103,6 +103,13 @@ sub add { ); } + if ( !C4::Context->preference('ReserveExpiration') and $expiration_date ) { + return $c->render( + status => 400, + openapi => { error => "Expiration date not allowed" } + ); + } + # AddReserve expects date to be in syspref format if ($expiration_date) { $expiration_date = output_pref( dt_from_string( $expiration_date, 'rfc3339' ) ); diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index ec4becf8ad..06910e8e08 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -74,7 +74,7 @@ sub add { my $item_id = $body->{item_id}; my $patron_id = $body->{patron_id}; my $item_type = $body->{item_type}; - my $expiration_date = C4::Context->preference('ReserveExpiration') ? $body->{expiration_date} : undef; + my $expiration_date = $body->{expiration_date}; my $notes = $body->{notes}; my $hold_date = $body->{hold_date}; my $non_priority = $body->{non_priority}; @@ -89,6 +89,13 @@ sub add { ); } + if ( !C4::Context->preference('ReserveExpiration') and $expiration_date ) { + return $c->render( + status => 400, + openapi => { error => "Expiration date not allowed" } + ); + } + if ( $item_id and $biblio_id ) { # check they are consistent -- 2.11.0