Bugzilla – Attachment 173602 Details for
Bug 38253
REST API: Toggle holds lowest priority via REST API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38253: Add lowest priority REST API endpoint for holds
0001-Bug-38253-Add-lowest-priority-REST-API-endpoint-for-.patch (text/plain), 6.06 KB, created by
Johanna Räisä
on 2024-10-29 06:21:59 UTC
(
hide
)
Description:
Bug 38253: Add lowest priority REST API endpoint for holds
Filename:
MIME Type:
Creator:
Johanna Räisä
Created:
2024-10-29 06:21:59 UTC
Size:
6.06 KB
patch
obsolete
>From ae24e51c8323d5d06220eae63a899b923af1f318 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Johanna=20R=C3=A4is=C3=A4?= <johanna.raisa@gmail.com> >Date: Thu, 24 Oct 2024 11:10:07 +0300 >Subject: [PATCH] Bug 38253: Add lowest priority REST API endpoint for holds > >This patch adds a new endpoint to toggle the lowest priority of a hold via the REST API. > >To test: >1) Apply the patch >2) perl build-resources.PL >3) prove t/db_dependent/api/v1/holds.t > >Sponsored-by: Koha-Suomi Oy >--- > Koha/REST/V1/Holds.pm | 24 +++++++++++++++ > api/v1/swagger/paths/holds.yaml | 51 +++++++++++++++++++++++++++++++ > api/v1/swagger/swagger.yaml | 2 ++ > t/db_dependent/api/v1/holds.t | 54 ++++++++++++++++++++++++++++++++- > 4 files changed, 130 insertions(+), 1 deletion(-) > >diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm >index ac9979e0ba..8d7b1d40a6 100644 >--- a/Koha/REST/V1/Holds.pm >+++ b/Koha/REST/V1/Holds.pm >@@ -554,4 +554,28 @@ sub update_pickup_location { > }; > } > >+=head3 lowest_priority >+ >+Method that handles toggling the lowest priority of a Koha::Hold object >+ >+=cut >+ >+sub lowest_priority { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $hold_id = $c->param('hold_id'); >+ my $hold = Koha::Holds->find($hold_id); >+ >+ return $c->render_resource_not_found("Hold") >+ unless $hold; >+ >+ return try { >+ C4::Reserves::ToggleLowestPriority($hold_id); >+ $hold->discard_changes; # refresh >+ return $c->render( status => 200, openapi => $hold_id ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > 1; >diff --git a/api/v1/swagger/paths/holds.yaml b/api/v1/swagger/paths/holds.yaml >index abf00fd726..dc1d933904 100644 >--- a/api/v1/swagger/paths/holds.yaml >+++ b/api/v1/swagger/paths/holds.yaml >@@ -747,3 +747,54 @@ > x-koha-authorization: > permissions: > reserveforothers: place_holds >+"/holds/{hold_id}/lowest_priority": >+ put: >+ x-mojo-to: Holds#lowest_priority >+ operationId: toggleLowestPriority >+ tags: >+ - holds >+ summary: Toggle holds lowest priority >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/hold_id_pp" >+ - name: body >+ in: body >+ description: An integer representing the new priority to be set for the hold >+ required: false >+ schema: >+ type: integer >+ produces: >+ - application/json >+ responses: >+ "200": >+ description: Toggle the holds lowest priority value >+ schema: >+ type: integer >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Hold not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "409": >+ description: Unable to perform action on hold >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: | >+ Internal server error. Possible `error_code` attribute values: >+ * `internal_server_error` >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ reserveforothers: modify_holds_priority >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index dd72361380..e4d3c751a2 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -391,6 +391,8 @@ paths: > $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1priority" > "/holds/{hold_id}/suspension": > $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1suspension" >+ "/holds/{hold_id}/lowest_priority": >+ $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1lowest_priority" > /ill/backends: > $ref: ./paths/ill_backends.yaml#/~1ill~1backends > "/ill/backends/{ill_backend_id}": >diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t >index 8632c25940..ca1972147f 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 => 14; >+use Test::More tests => 15; > use Test::MockModule; > use Test::Mojo; > use t::lib::TestBuilder; >@@ -1547,3 +1547,55 @@ subtest 'delete() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'PUT /holds/{hold_id}/lowest_priority tests' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $password = 'AbcdEFG123'; >+ >+ my $library_1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); >+ >+ 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 => 'modify_holds_priority', >+ }, >+ } >+ ); >+ >+ # Disable logging >+ t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); >+ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+ my $biblio = $builder->build_sample_biblio; >+ >+ # biblio-level hold >+ my $hold = Koha::Holds->find( >+ AddReserve( >+ { >+ branchcode => $library_1->branchcode, >+ borrowernumber => $patron->borrowernumber, >+ biblionumber => $biblio->biblionumber, >+ priority => 1, >+ itemnumber => undef, >+ } >+ ) >+ ); >+ >+ $t->put_ok( "//$userid:$password@/api/v1/holds/0" . "/lowest_priority" )->status_is(404); >+ >+ $t->put_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/lowest_priority" )->status_is(200); >+ >+ is( $hold->discard_changes->lowest_priority, 1, 'Priority set to lowest' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.34.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 38253
:
173260
|
173279
|
173602
|
173852
|
173857