From 810e766638064e1c1d59ed21fbdc5c97a4ca9e0c Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 18 Mar 2024 11:35:48 +0000 Subject: [PATCH] Bug 10060: POC This patch adds a stanza to the SetEnv middleware which checks for a branchcode in the SCO url and captures it. We then use that branchcode in checkauth to set the userenv to the specified branch (if it is a real branch) The regex could probably be improved, and the change needs test coverage, but this might be a valid approach to seeting the branch from the URL. Feedback appreciated --- C4/Auth.pm | 4 ++++ Koha/Middleware/SetEnv.pm | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/C4/Auth.pm b/C4/Auth.pm index a8c21740f00..bcd941dcfee 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1243,6 +1243,10 @@ sub checkauth { my $is_sco_user = 0; if ( $query->param('sco_user_login') && ( $query->param('sco_user_login') eq '1' ) ){ $is_sco_user = 1; + my $sco_branch = $ENV{'URL_BRANCH'}; + if( defined $branches->{$sco_branch} ){ + $branchcode = $branches->{$sco_branch}->{'branchcode'}; + $branchname = $branches->{$sco_branch}->{'branchname'}; } $session->param( 'number', $borrowernumber ); diff --git a/Koha/Middleware/SetEnv.pm b/Koha/Middleware/SetEnv.pm index b0e42d09359..ed66ee7c545 100644 --- a/Koha/Middleware/SetEnv.pm +++ b/Koha/Middleware/SetEnv.pm @@ -76,6 +76,10 @@ my $allowed_setenvs = qr/^( sub call { my ( $self, $env ) = @_; my $req = Plack::Request->new($env); + if( $env->{PATH_INFO} =~ /(\/opac\/sco)\/(.*)\/(.*)/ ){ + $env->{PATH_INFO} = "$1/$3"; + $env->{URL_BRANCH} = $2; + } # First, we split the result only on unescaped commas. my @setenv_headers = split /(?header('X-Koha-SetEnv') || ''; -- 2.30.2