From 1e859de4c0ad0b890b344548b3c49b12000c8bc6 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 10 Aug 2017 12:31:43 +0300 Subject: [PATCH] Bug 19072: Toggle suspend for /api/v1/holds This patch adds ability to toggle suspend for a hold. To test: 1. prove t/db_dependent/api/v1/holds.t 2. Send a PUT request to suspended hold with suspend_until parameter as null 3. Observe that hold is now resumed --- Koha/REST/V1/Hold.pm | 8 +++++++- api/v1/swagger/paths/holds.json | 4 ++++ t/db_dependent/api/v1/holds.t | 24 ++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1/Hold.pm b/Koha/REST/V1/Hold.pm index 1be1d75..b124a5b 100644 --- a/Koha/REST/V1/Hold.pm +++ b/Koha/REST/V1/Hold.pm @@ -141,10 +141,16 @@ sub edit { reserve_id => $reserve_id, branchcode => $branchcode, rank => $priority, - suspend_until => $suspend_until, }; C4::Reserves::ModReserve($params); + + my $borrowernumber = $reserve->{borrowernumber}; + if (C4::Reserves::CanReserveBeCanceledFromOpac($reserve_id, $borrowernumber)){ + C4::Reserves::ToggleSuspend( $reserve_id, $suspend_until ) if + (defined $body->{suspend} || $suspend_until); + } + $reserve = Koha::Holds->find($reserve_id); return $c->render( status => 200, openapi => $reserve ); diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json index b2f542a..71f7c7d 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -273,6 +273,10 @@ "description": "Pickup location", "type": "string" }, + "suspend": { + "description": "Suspend hold", + "type": "boolean" + }, "suspend_until": { "description": "Suspend until", "type": "string", diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index d1f7978..721444a 100644 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -186,7 +186,7 @@ subtest "Test endpoints without permission" => sub { ->status_is(403); }; subtest "Test endpoints without permission, but accessing own object" => sub { - plan tests => 15; + plan tests => 25; my $borrno_tmp = $post_data->{'borrowernumber'}; $post_data->{'borrowernumber'} = int $nopermission->{'borrowernumber'}; @@ -210,11 +210,31 @@ subtest "Test endpoints without permission, but accessing own object" => sub { my $reserve_id3 = Koha::Holds->find({ borrowernumber => $nopermission->{borrowernumber} })->reserve_id; $tx = $t->ua->build_tx(PUT => "/api/v1/holds/$reserve_id3" => json => $put_data); $tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); - $t->request_ok($tx) # create hold to myself + $t->request_ok($tx) ->status_is(200) ->json_is('/reserve_id', $reserve_id3) ->json_is('/suspend_until', $suspend_until . ' 00:00:00') ->json_is('/priority', 2); + + $tx = $t->ua->build_tx(PUT => "/api/v1/holds/$reserve_id3" => json => { + suspend => Mojo::JSON->false + }); + $tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); + $t->request_ok($tx) + ->status_is(200) + ->json_is('/reserve_id', $reserve_id3) + ->json_is('/suspend', Mojo::JSON->false) + ->json_is('/suspend_until', undef); + + $tx = $t->ua->build_tx(PUT => "/api/v1/holds/$reserve_id3" => json => { + suspend_until => $suspend_until + }); + $tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); + $t->request_ok($tx) + ->status_is(200) + ->json_is('/reserve_id', $reserve_id3) + ->json_is('/suspend', Mojo::JSON->true) + ->json_like('/suspend_until', qr/^$suspend_until/); }; subtest "Test endpoints with permission" => sub { -- 2.7.4