Bugzilla – Attachment 119927 Details for
Bug 28157
Add the ability to set a library from which an API request pretends to come from
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28157: Add handling for the x-koha-library header
Bug-28157-Add-handling-for-the-x-koha-library-head.patch (text/plain), 2.92 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-04-20 17:32:22 UTC
(
hide
)
Description:
Bug 28157: Add handling for the x-koha-library header
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-04-20 17:32:22 UTC
Size:
2.92 KB
patch
obsolete
>From 5a7cff5d8ed07f8da6ba29129eb76a2712133ae0 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 20 Apr 2021 14:23:36 -0300 >Subject: [PATCH] Bug 28157: Add handling for the x-koha-library header > >This patch introduces a new header handling. The key idea is that on >Koha's base classes there's broad usage of C4::Context->userenv to >determine the current library and make decisions based on that. > >API requests, on the other hand, might not be tied to sessions >(stateless) which is the way current library is retrieved. So we need a >way to properly specify what library the request is trying to act as >coming from. > >To test: >1. Apply this patchset >2. Run: > $ kshell > k$ prove t/db_dependent/api/v1/auth_authenticate_api_request.t >=> SUCCESS: Tests pass! >3- Sign off :-D >--- > Koha/REST/V1/Auth.pm | 33 ++++++++++++++++++++++----------- > 1 file changed, 22 insertions(+), 11 deletions(-) > >diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm >index a28fb5920c3..3b5ab4c9a22 100644 >--- a/Koha/REST/V1/Auth.pm >+++ b/Koha/REST/V1/Auth.pm >@@ -28,6 +28,7 @@ use Koha::ApiKeys; > use Koha::Account::Lines; > use Koha::Checkouts; > use Koha::Holds; >+use Koha::Libraries; > use Koha::OAuth; > use Koha::OAuthAccessTokens; > use Koha::Old::Checkouts; >@@ -310,7 +311,6 @@ sub validate_query_parameters { > ) if @errors; > } > >- > =head3 allow_owner > > Allows access to object for its owner. >@@ -500,19 +500,30 @@ Internal method that sets C4::Context->userenv > sub _set_userenv { > my ( $c, $patron ) = @_; > >- my $library = $patron->library; >+ my $passed_library_id = $c->req->headers->header('x-koha-library'); >+ my $THE_library; >+ >+ if ( $passed_library_id ) { >+ $THE_library = Koha::Libraries->find( $passed_library_id ); >+ Koha::Exceptions::Authorization::Unauthorized->throw( >+ "Unauthorized attempt to set library to $passed_library_id" >+ ) unless $THE_library and $patron->can_log_into($THE_library); >+ } >+ else { >+ $THE_library = $patron->library; >+ } > > C4::Context->_new_userenv( $patron->borrowernumber ); > C4::Context->set_userenv( >- $patron->borrowernumber, # number, >- $patron->userid, # userid, >- $patron->cardnumber, # cardnumber >- $patron->firstname, # firstname >- $patron->surname, # surname >- $library->branchcode, # branch >- $library->branchname, # branchname >- $patron->flags, # flags, >- $patron->email, # emailaddress >+ $patron->borrowernumber, # number, >+ $patron->userid, # userid, >+ $patron->cardnumber, # cardnumber >+ $patron->firstname, # firstname >+ $patron->surname, # surname >+ $THE_library->branchcode, # branch >+ $THE_library->branchname, # branchname >+ $patron->flags, # flags, >+ $patron->email, # emailaddress > ); > > return $c; >-- >2.31.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 28157
:
119925
|
119926
|
119927
|
119930
|
119931
|
119932
|
119959