From fb03963bfc21956fe38cbbc6a88167c9e66f5681 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 | 7 ++++++- api/v1/swagger/paths/holds.json | 2 +- t/db_dependent/api/v1/holds.t | 22 +++++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1/Hold.pm b/Koha/REST/V1/Hold.pm index b282f07..90bd961 100644 --- a/Koha/REST/V1/Hold.pm +++ b/Koha/REST/V1/Hold.pm @@ -153,10 +153,15 @@ 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 ); + } + $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 55f1763..59c7dd9 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -275,7 +275,7 @@ }, "suspend_until": { "description": "Suspend until", - "type": "string", + "type": ["string", "null"], "format": "date" } } diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index 03ba478..f6e735e 100644 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -225,7 +225,7 @@ subtest "Test endpoints without permission" => sub { ->status_is(403); }; subtest "Test endpoints without permission, but accessing own object" => sub { - plan tests => 26; + plan tests => 36; my $reserve_id3 = C4::Reserves::AddReserve($branchcode, $nopermission->{'borrowernumber'}, $biblionumber, undef, 2, undef, undef, undef, '', $itemnumber, 'W'); @@ -319,6 +319,26 @@ subtest "Test endpoints without permission, but accessing own object" => sub { ->status_is(200) ->json_is('/reserve_id', $reserve_id3) ->json_is('/branchcode', $branchcode2); + + $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) # create hold to myself + ->status_is(200) + ->json_is('/reserve_id', $reserve_id3) + ->json_is('/suspend', Mojo::JSON->true) + ->json_like('/suspend_until', qr/^$suspend_until/); + + $tx = $t->ua->build_tx(PUT => "/api/v1/holds/$reserve_id3" => json => { + suspend_until => undef + }); + $tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); + $t->request_ok($tx) # create hold to myself + ->status_is(200) + ->json_is('/reserve_id', $reserve_id3) + ->json_is('/suspend', Mojo::JSON->false) + ->json_is('/suspend_until', undef); }; subtest "Test endpoints with permission" => sub { -- 2.7.4