Bugzilla – Attachment 114311 Details for
Bug 18729
Librarian unable to update hold pickup library from patron pages without "modify_holds_priority" permission
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18729: Add PUT /holds/{hold_id}/pickup_priority
Bug-18729-Add-PUT-holdsholdidpickuppriority.patch (text/plain), 7.50 KB, created by
Jonathan Druart
on 2020-12-10 15:25:41 UTC
(
hide
)
Description:
Bug 18729: Add PUT /holds/{hold_id}/pickup_priority
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-12-10 15:25:41 UTC
Size:
7.50 KB
patch
obsolete
>From d25c8b2521b0b9f34e8a79bdb7d7c8691d5372db Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 1 Dec 2020 12:29:38 +0100 >Subject: [PATCH] Bug 18729: Add PUT /holds/{hold_id}/pickup_priority > >Bug 18729: Fix return type >--- > Koha/REST/V1/Holds.pm | 32 +++++++++++ > api/v1/swagger/paths.json | 3 + > api/v1/swagger/paths/holds.json | 73 ++++++++++++++++++++++++ > koha-tmpl/intranet-tmpl/prog/js/holds.js | 5 +- > t/db_dependent/api/v1/holds.t | 53 ++++++++++++++++- > 5 files changed, 162 insertions(+), 4 deletions(-) > >diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm >index 30579caa40..8d9d30c06d 100644 >--- a/Koha/REST/V1/Holds.pm >+++ b/Koha/REST/V1/Holds.pm >@@ -433,4 +433,36 @@ sub pickup_locations { > }; > } > >+=head3 update_pickup_location >+ >+Method that handles modifying the pickup location of a Koha::Hold object >+ >+=cut >+ >+sub update_pickup_location { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $hold_id = $c->validation->param('hold_id'); >+ my $hold = Koha::Holds->find($hold_id); >+ >+ unless ($hold) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Hold not found" } >+ ); >+ } >+ >+ return try { >+ my $pickup_location = $c->req->json; >+ >+ $hold->branchcode($pickup_location)->store; >+ >+ return $c->render( status => 200, openapi => $pickup_location ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+ > 1; >diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json >index 3b5dc352d5..c5e9c7d367 100644 >--- a/api/v1/swagger/paths.json >+++ b/api/v1/swagger/paths.json >@@ -62,6 +62,9 @@ > "/holds/{hold_id}/pickup_locations": { > "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_locations" > }, >+ "/holds/{hold_id}/pickup_location": { >+ "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_location" >+ }, > "/items": { > "$ref": "paths/items.json#/~1items" > }, >diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json >index 386b4a9470..da58afc650 100644 >--- a/api/v1/swagger/paths/holds.json >+++ b/api/v1/swagger/paths/holds.json >@@ -676,5 +676,78 @@ > } > } > } >+ }, >+ "/holds/{hold_id}/pickup_location": { >+ "put": { >+ "x-mojo-to": "Holds#update_pickup_location", >+ "operationId": "updateHoldPickupLocation", >+ "tags": ["holds"], >+ "parameters": [ >+ { >+ "$ref": "../parameters.json#/hold_id_pp" >+ }, >+ { >+ "name": "body", >+ "in": "body", >+ "description": "Pickup location", >+ "required": true, >+ "schema": { >+ "type": "string" >+ } >+ } >+ ], >+ "produces": [ >+ "application/json" >+ ], >+ "responses": { >+ "200": { >+ "description": "The new pickup location value for the hold", >+ "schema": { >+ "type": "string" >+ } >+ }, >+ "401": { >+ "description": "Authentication required", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "403": { >+ "description": "Access forbidden", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "404": { >+ "description": "Hold not found", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "409": { >+ "description": "Unable to perform action on hold", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "500": { >+ "description": "Internal error", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "503": { >+ "description": "Under maintenance", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ } >+ }, >+ "x-koha-authorization": { >+ "permissions": { >+ "reserveforothers": "place_holds" >+ } >+ } >+ } > } > } >diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js >index 66dd265a14..ff5767036b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/holds.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js >@@ -224,12 +224,11 @@ $(document).ready(function() { > var cur_select = $(this); > var res_id = $(this).attr('reserve_id'); > $(this).after('<div id="updating_reserveno'+res_id+'" class="waiting"><img src="/intranet-tmpl/prog/img/spinner-small.gif" alt="" /><span class="waiting_msg"></span></div>'); >- var api_url = '/api/v1/holds/'+res_id; >- var update_info = JSON.stringify({ pickup_library_id: $(this).val(), priority: parseInt($(this).attr("priority"),10) }); >+ var api_url = '/api/v1/holds/' + encodeURIComponent(res_id) + '/pickup_location'; > $.ajax({ > method: "PUT", > url: api_url, >- data: update_info , >+ data: $(this).val(), > success: function( data ){ holdsTable.api().ajax.reload(); }, > error: function( jqXHR, textStatus, errorThrown) { > alert('There was an error:'+textStatus+" "+errorThrown); >diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t >index f9a4819d0c..cb683fd819 100755 >--- a/t/db_dependent/api/v1/holds.t >+++ b/t/db_dependent/api/v1/holds.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 10; >+use Test::More tests => 11; > use Test::MockModule; > use Test::Mojo; > use t::lib::TestBuilder; >@@ -787,3 +787,54 @@ subtest 'pickup_locations() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $password = 'AbcdEFG123'; >+ >+ my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); >+ >+ my $patron = $builder->build_object( >+ { class => 'Koha::Patrons', value => { flags => 0 } } ); >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $patron->userid; >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ module_bit => 6, >+ code => 'place_holds', >+ }, >+ } >+ ); >+ >+ # Disable logging >+ t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); >+ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $hold = Koha::Holds->find( >+ AddReserve( >+ { >+ branchcode => $library_1->branchcode, >+ borrowernumber => $patron->borrowernumber, >+ biblionumber => $biblio->biblionumber, >+ priority => 1, >+ } >+ ) >+ ); >+ >+ $t->put_ok( "//$userid:$password@/api/v1/holds/" >+ . $hold->id >+ . "/pickup_location" => json => $library_2->branchcode )->status_is(200)->json_is($library_2->branchcode); >+ >+ is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18729
:
114067
|
114311
|
114337
|
114388
|
114389
|
114390
|
114391
|
114393
|
114394
|
114395
|
114396
|
117656
|
117657
|
117658
|
117659
|
119711
|
119712
|
119713
|
119714