Bugzilla – Attachment 150883 Details for
Bug 30979
Add ability for OPAC users to checkout to themselves
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30979: Add public endpoints
Bug-30979-Add-public-endpoints.patch (text/plain), 8.19 KB, created by
Martin Renvoize (ashimema)
on 2023-05-09 14:52:16 UTC
(
hide
)
Description:
Bug 30979: Add public endpoints
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-05-09 14:52:16 UTC
Size:
8.19 KB
patch
obsolete
>From db519c9776acd8b26b9c8ac4f613077e9ad453b3 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 5 May 2023 15:56:27 +0100 >Subject: [PATCH] Bug 30979: Add public endpoints > >This patch expands the checkouts endpoints to allow for a public workflow. > >We add the availability endpoint under `/public/checkouts/availability` >and restrict the information we send back to only those fields a public >user should be allowed to see. > >We also add a new checkout endpoint at `/patrons/{patron_id}/checkouts` >that allows for users to checkout to themselves and accepts the same POST >request with checkout details including item_id and a confirmation token >in the body that the staff client endpoints accept. > >Signed-off-by: Helen Oliver <HOliver@tavi-port.ac.uk> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/REST/V1/Checkouts.pm | 24 +++++++++- > api/v1/swagger/paths/checkouts.yaml | 40 ++++++++++++++-- > api/v1/swagger/paths/public_patrons.yaml | 60 ++++++++++++++++++++++++ > api/v1/swagger/swagger.yaml | 4 ++ > 4 files changed, 123 insertions(+), 5 deletions(-) > >diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm >index e77cb3502d..ec95aca3ff 100644 >--- a/Koha/REST/V1/Checkouts.pm >+++ b/Koha/REST/V1/Checkouts.pm >@@ -102,7 +102,7 @@ sub get { > }; > } > >-=head3 get_availablity >+=head3 get_availability > > Controller function that handles retrieval of Checkout availability > >@@ -123,6 +123,17 @@ sub get_availability { > C4::Circulation::CanBookBeIssued( $patron, undef, undef, $inprocess, $ignore_reserves, > $params ); > >+ # Upgrade some confirmations to blockers if public >+ if ( $c->stash('is_public') ) { >+ my @should_block = qw/TOO_MANY ISSUED_TO_ANOTHER RESERVED RESERVED_WAITING TRANSFERRED PROCESSING AGE_RESTRICTION/; >+ for my $block ( @should_block ) { >+ if ( exists($confirmation->{$block}) ) { >+ $impossible->{$block} = $confirmation->{$block}; >+ delete $confirmation->{$block}; >+ } >+ } >+ } >+ > my $token; > if (keys %{$confirmation}) { > my $claims = { map { $_ => 1 } keys %{$confirmation} }; >@@ -131,6 +142,17 @@ sub get_availability { > $token = Mojo::JWT->new( claims => $claims, secret => $secret )->encode; > } > >+ # Remove any non-public info that's returned by CanBookBeIssued >+ if ( $c->stash('is_public') ) { >+ my @restricted_keys = qw/issued_borrowernumber issued_cardnumber issued_firstname issued_surname resborrowernumber resbranchcode rescardnumber reserve_id resfirstname resreservedate ressurname item_notforloan/; >+ for my $key (@restricted_keys) { >+ delete $confirmation->{$key}; >+ delete $impossible->{$key}; >+ delete $alerts->{$key}; >+ delete $messages->{$key}; >+ } >+ } >+ > my $response = { > blockers => $impossible, > confirms => $confirmation, >diff --git a/api/v1/swagger/paths/checkouts.yaml b/api/v1/swagger/paths/checkouts.yaml >index afe6e5660c..e324b61c52 100644 >--- a/api/v1/swagger/paths/checkouts.yaml >+++ b/api/v1/swagger/paths/checkouts.yaml >@@ -89,13 +89,13 @@ > description: Created checkout > schema: > $ref: "../swagger.yaml#/definitions/checkout" >- "400": >+ "400": > description: Missing or wrong parameters >- schema: >+ schema: > $ref: "../swagger.yaml#/definitions/error" >- "401": >+ "401": > description: Authentication required >- schema: >+ schema: > $ref: "../swagger.yaml#/definitions/error" > "403": > description: Cannot create checkout >@@ -370,3 +370,35 @@ > x-koha-authorization: > permissions: > circulate: circulate_remaining_permissions >+"/public/checkouts/availability": >+ get: >+ x-mojo-to: Checkouts#get_availability >+ operationId: availabilityCheckoutsPublic >+ tags: >+ - checkouts >+ summary: Get checkout availability >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/patron_id_qp" >+ - $ref: "../swagger.yaml#/parameters/item_id_qp" >+ produces: >+ - application/json >+ responses: >+ "200": >+ description: Availability >+ schema: >+ type: "object" >+ "403": >+ description: Access forbidden >+ 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" >diff --git a/api/v1/swagger/paths/public_patrons.yaml b/api/v1/swagger/paths/public_patrons.yaml >index 2f92f6751b..c4041b8c64 100644 >--- a/api/v1/swagger/paths/public_patrons.yaml >+++ b/api/v1/swagger/paths/public_patrons.yaml >@@ -62,6 +62,66 @@ > $ref: "../swagger.yaml#/definitions/error" > x-koha-authorization: > allow-owner: true >+"/public/patrons/{patron_id}/checkouts": >+ post: >+ x-mojo-to: Checkouts#add >+ operationId: addCheckoutPublic >+ tags: >+ - checkouts >+ - patrons >+ summary: Add a new checkout >+ parameters: >+ - name: body >+ in: body >+ description: A JSON object containing information about the new checkout >+ required: true >+ schema: >+ $ref: "../swagger.yaml#/definitions/checkout" >+ - name: confirmation >+ in: query >+ description: A JWT confirmation token >+ required: false >+ type: string >+ produces: >+ - application/json >+ responses: >+ "201": >+ description: Created checkout >+ schema: >+ $ref: "../swagger.yaml#/definitions/checkout" >+ "400": >+ description: Missing or wrong parameters >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Cannot create checkout >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "409": >+ description: Conflict in creating checkout >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "412": >+ description: Precondition failed >+ 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: >+ allow-owner: true > "/public/patrons/{patron_id}/guarantors/can_see_charges": > put: > x-mojo-to: Patrons#guarantors_can_see_charges >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index d0aca025d0..31901be804 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -305,6 +305,8 @@ paths: > $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date" > "/public/biblios/{biblio_id}": > $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}" >+ "/public/checkouts/availability": >+ $ref: ./paths/checkouts.yaml#/~1public~1checkouts~1availability > "/public/items": > $ref: "./paths/items.yaml#/~1public~1items" > "/public/biblios/{biblio_id}/items": >@@ -319,6 +321,8 @@ paths: > $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface} > "/public/patrons/{patron_id}/article_requests/{article_request_id}": > $ref: "./paths/article_requests.yaml#/~1public~1patrons~1{patron_id}~1article_requests~1{article_request_id}" >+ "/public/patrons/{patron_id}/checkouts": >+ $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1checkouts" > "/public/patrons/{patron_id}/guarantors/can_see_charges": > $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_charges" > "/public/patrons/{patron_id}/guarantors/can_see_checkouts": >-- >2.40.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 30979
:
139131
|
139132
|
139133
|
139134
|
141274
|
141275
|
141276
|
141277
|
141278
|
141279
|
141300
|
145264
|
145265
|
145266
|
145267
|
145268
|
145277
|
145280
|
145281
|
145282
|
145283
|
145284
|
145285
|
145620
|
145621
|
145622
|
145623
|
145624
|
145625
|
145626
|
145627
|
145628
|
145629
|
145630
|
150867
|
150868
|
150869
|
150870
|
150871
|
150872
|
150873
|
150874
|
150875
|
150876
|
150877
|
150878
|
150879
|
150880
|
150881
|
150882
|
150883
|
150884
|
150885
|
150886
|
150887
|
150888
|
150889
|
150967
|
150968
|
150969
|
150970
|
150971
|
150972
|
150973
|
150974
|
151254
|
151255
|
151256
|
151257
|
151258
|
151259
|
151260
|
151261
|
151358
|
151359
|
151360
|
151361
|
151362
|
151363
|
151364
|
151365
|
151368
|
151369
|
151370
|
151371
|
151372
|
151373
|
151374
|
151375
|
151376
|
152789
|
152790
|
152791
|
152792
|
152793
|
152794
|
152795
|
152796
|
152797
|
153459
|
153460
|
153461
|
153462
|
153463
|
153464
|
153465
|
153466
|
153467
|
153500
|
153501
|
153502
|
153503