From ff80b5bc65298e5ce4be48ef9e1c4fa0f518e43e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 8 Feb 2022 12:12:22 +0100 Subject: [PATCH] Bug 30045: (bug 29543 follow-up) Fix SCO print slip Certainly since bug 29543 and bug 29914. We should do the same authentication check than sco-main.pl, and also make sure to generate the checkout history only for the logged in patron (the OPAC one, not staff member) Test plan: Use the different combinations of the SCO config (AutoSelfCheckAllowed, SelfCheckoutByLogin and WebBasedSelfCheck) and confirm that this patch fixes the SCO print slip feature. Signed-off-by: Marcel de Rooy Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall (cherry picked from commit 72fa33490b71d91658c32493c687b1c5a37dc1df) Signed-off-by: Andrew Fuerste-Henry (cherry picked from commit 26cbc70d1981a1ee3d1c658a0b96fb504d65e177) Signed-off-by: Victor Grousset/tuxayo (cherry picked from commit 9416f10fa5f41be46aa794fa112027b37d59267f) Signed-off-by: Wainui Witika-Park --- .../bootstrap/en/modules/sco/sco-main.tt | 2 +- opac/sco/printslip.pl | 44 ++++++++++++++----- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt index 65912102f7..d91fcc3ba0 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt @@ -485,7 +485,7 @@ var confirmStart = Date.now(); confirmModal("", _("Would you like to print a receipt?"), _("Print receipt and end session"), _("End session"), function(result) { if ( result && (Date.now() - confirmStart) < [% SelfCheckTimeout | html %] ) { - var win = window.open("/cgi-bin/koha/sco/printslip.pl?borrowernumber=[% borrowernumber | html %]&print=qslip"); + var win = window.open("/cgi-bin/koha/sco/printslip.pl?print=qslip"); location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout'; } else { location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout'; diff --git a/opac/sco/printslip.pl b/opac/sco/printslip.pl index 98ded2a5c6..4a6ffbe0a3 100755 --- a/opac/sco/printslip.pl +++ b/opac/sco/printslip.pl @@ -34,38 +34,60 @@ use C4::Output; use C4::Members; use C4::Koha; -my $input = new CGI; -unless ( in_iprange(C4::Context->preference('SelfCheckAllowByIPRanges')) ) { - print $input->header(status => '403 Forbidden - functionality not available from your location'); +my $input = CGI->new; +unless (C4::Context->preference('WebBasedSelfCheck')) { + # redirect to OPAC home if self-check is not enabled + print $input->redirect("/cgi-bin/koha/opac-main.pl"); exit; } -my $sessionID = $input->cookie("CGISESSID"); -my $session = get_session($sessionID); +unless ( in_iprange(C4::Context->preference('SelfCheckAllowByIPRanges')) ) { + # redirect to OPAC home if self-checkout not permitted from current IP + print $input->redirect("/cgi-bin/koha/opac-main.pl"); + exit; +} -my $print = $input->param('print'); -my $error = $input->param('error'); +if (C4::Context->preference('AutoSelfCheckAllowed')) +{ + my $AutoSelfCheckID = C4::Context->preference('AutoSelfCheckID'); + my $AutoSelfCheckPass = C4::Context->preference('AutoSelfCheckPass'); + $input->param(-name=>'userid',-values=>[$AutoSelfCheckID]); + $input->param(-name=>'password',-values=>[$AutoSelfCheckPass]); + $input->param(-name=>'koha_login_context',-values=>['sco']); +} +$input->param(-name=>'sco_user_login',-values=>[1]); # patrons still need to be able to print receipts my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "sco/printslip.tt", + flagsrequired => { self_check => "self_checkout_module" }, query => $input, type => "opac", } ); -my $borrowernumber = $input->param('borrowernumber'); -my $branch=C4::Context->userenv->{'branch'}; +my $jwt = $input->cookie('JWT'); +my $patronid = $jwt ? Koha::Token->new->decode_jwt({ token => $jwt }) : undef; +my $patron = $patronid ? Koha::Patrons->find( { cardnumber => $patronid } ) : undef; + +unless ( $patron ) { + print $input->header(-type => 'text/plain', -status => '403 Forbidden'); + exit; +} + +my $print = $input->param('print'); +my $error = $input->param('error'); + my ($slip, $is_html); -if (my $letter = IssueSlip ($session->param('branch') || $branch, $borrowernumber, $print eq "qslip")) { +if (my $letter = IssueSlip ($patron->branchcode, $patron->borrowernumber, $print eq "qslip")) { $slip = $letter->{content}; $is_html = $letter->{is_html}; } $template->{VARS}->{slip} = $slip; $template->{VARS}->{plain} = !$is_html; -$template->{VARS}->{borrowernumber} = $borrowernumber; +$template->{VARS}->{borrowernumber} = $patron->borrowernumber; $template->{VARS}->{stylesheet} = C4::Context->preference("SlipCSS"); $template->{VARS}->{error} = $error; -- 2.39.5