From 90d5708abdb057b8a703dc7d68260ca960159231 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 9 Jun 2020 12:40:32 -0300 Subject: [PATCH] Bug 24003: (follow-up) Add all userenv parameters This patch makes the API set more userenv params than just the borrowernumber. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/auth_* => SUCCESS: All tests pass 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/Auth.pm | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm index 8e9336a9e0a..9f137af35b4 100644 --- a/Koha/REST/V1/Auth.pm +++ b/Koha/REST/V1/Auth.pm @@ -249,8 +249,7 @@ sub authenticate_api_request { C4::Context->interface('api'); if ( $user and !$cookie_auth ) { # cookie-auth sets this and more, don't mess with that - C4::Context->_new_userenv( $user->borrowernumber ); - C4::Context->set_userenv( $user->borrowernumber ); + $c->_set_userenv( $user ); } if ( !$authorization and @@ -490,4 +489,33 @@ sub _basic_auth { return Koha::Patrons->find({ userid => $user_id }); } +=head3 _set_userenv + + $c->_set_userenv( $patron ); + +Internal method that sets C4::Context->userenv + +=cut + +sub _set_userenv { + my ( $c, $patron ) = @_; + + my $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 + ); + + return $c; +} + 1; -- 2.27.0