Bugzilla – Attachment 182832 Details for
Bug 40023
Allow embedding `patron` when validating credentials
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40023: Add option to embed patron object on password validation response
Bug-40023-Add-option-to-embed-patron-object-on-pas.patch (text/plain), 3.06 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-05-28 19:24:56 UTC
(
hide
)
Description:
Bug 40023: Add option to embed patron object on password validation response
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-05-28 19:24:56 UTC
Size:
3.06 KB
patch
obsolete
>From e5030a7b818d59b5ba92c057da7c6df23aeccc4f Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 28 May 2025 16:21:03 -0300 >Subject: [PATCH] Bug 40023: Add option to embed patron object on password > validation response > >This patch adds the option to embed the patron object on a successful >password validation. > >It does so by > >* Adding a new embed in the spec >* Manually handling the embed in the controller >* Calling `$c->objects->to_api` on the already available `$patron` > object. > >To test: >1. Apply the unit tests >2. Run: > $ ktd --shell > k$ prove t/db_dependent/api/v1/password_validation.t >=> FAIL: Embedding is not allowed by the spec, or implemented at all. >3. Apply this patch >4. Rebuild the bundled spec: > k$ yarn api:bundle >5. Repeat 2 >=> SUCCESS: Tests pass! >6. You can also play with your favourite REST tool (Postman is mine) >7. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/REST/V1/Auth/Password.pm | 10 ++++++++++ > api/v1/swagger/paths/auth.yaml | 15 +++++++++++++++ > 2 files changed, 25 insertions(+) > >diff --git a/Koha/REST/V1/Auth/Password.pm b/Koha/REST/V1/Auth/Password.pm >index d1af05f962b..102a2d1d42c 100644 >--- a/Koha/REST/V1/Auth/Password.pm >+++ b/Koha/REST/V1/Auth/Password.pm >@@ -45,6 +45,15 @@ sub validate { > my $identifier = $body->{identifier}; > my $userid = $body->{userid}; > >+ my $embeds = $c->stash('koha.embed'); >+ my $embed_patron; >+ $embed_patron = 1 >+ if $embeds && exists $embeds->{patron}; >+ >+ # fake embed as the basis is not a Koha::Object-derived class >+ # remove it so $c->objects->to_api doesn't try to embed 'patron'. >+ delete $embeds->{patron}; >+ > unless ( defined $identifier or defined $userid ) { > return $c->render( > status => 400, >@@ -86,6 +95,7 @@ sub validate { > cardnumber => $patron->cardnumber, > patron_id => $patron->id, > userid => $patron->userid, >+ ( $embed_patron ? ( patron => $c->objects->to_api($patron) ) : () ), > } > ); > } catch { >diff --git a/api/v1/swagger/paths/auth.yaml b/api/v1/swagger/paths/auth.yaml >index 052565e4de6..5bc90fc2678 100644 >--- a/api/v1/swagger/paths/auth.yaml >+++ b/api/v1/swagger/paths/auth.yaml >@@ -1112,6 +1112,16 @@ > - patrons > summary: Check validity of username and password > parameters: >+ - name: x-koha-embed >+ in: header >+ required: false >+ description: Embed list sent as a request header >+ type: array >+ items: >+ type: string >+ enum: >+ - patron >+ collectionFormat: csv > - name: body > in: body > description: | >@@ -1157,6 +1167,11 @@ > userid: > type: string > description: userid for the validated patron >+ patron: >+ type: >+ - object >+ - "null" >+ description: The related patron object (x-koha-embed) > additionalProperties: false > "400": > description: Bad request >-- >2.49.0
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 40023
:
182831
| 182832