From b3189e33692fa5f7be90464dbac673aaa8458401 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 Signed-off-by: Martin Renvoize Signed-off-by: Aleisha Amohia --- 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 66a5e24c38..c94d651494 100644 --- a/Koha/REST/V1/Auth.pm +++ b/Koha/REST/V1/Auth.pm @@ -245,8 +245,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 @@ -486,4 +485,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.39.5