From 60564519b0e84b9bc911dc2cab55a5a2a76a502e Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 11 Apr 2024 08:38:04 +0000 Subject: [PATCH] Bug 36572: Fix and clean-up set library To test: 1. Have 3 staff accounts to test: -STAFF A: superlibrarian -STAFF B: loggedinlibrary permission -STAFF C: no loggedinlibrary or superlibrarian permission 2. Enable 'UseCirculationDesks' and create some desks. (Admin > Circulation desks) 3. Enable 'UseCashRegisters' and create some registers ( Admin > Cash registers) 4. Use STAFF A ( superlibrarian ) and make sure you can change branch, desk and register. 5. Use STAFF B ( loggedinlibrary permission ) and make sure you can change branch, desk and register. 6. Use STAFF C ( no loggedinlibrary or superlibrarian permission ) and make sure you can change branch, desk and register. 7. Each time you change you should be redirected to the page you were previously on. Signed-off-by: Owen Leonard Signed-off-by: Tomas Cohen Arazi Signed-off-by: Katrin Fischer --- circ/set-library.pl | 86 +++----- .../prog/en/modules/circ/set-library.tt | 196 +++++++----------- 2 files changed, 103 insertions(+), 179 deletions(-) diff --git a/circ/set-library.pl b/circ/set-library.pl index b370245bd3..c840f0f198 100755 --- a/circ/set-library.pl +++ b/circ/set-library.pl @@ -47,11 +47,10 @@ my $register_id = $query->param('register_id'); my $userenv_branch = C4::Context->userenv->{'branch'} || ''; my $userenv_desk = C4::Context->userenv->{'desk_id'} || ''; my $userenv_register_id = C4::Context->userenv->{'register_id'} || ''; -my @updated; +my $updated; my $library = Koha::Libraries->find($branch); # $session lines here are doing the updating -## Please see file perltidy.ERR if ( $op eq 'cud-set-library' && $library @@ -63,76 +62,49 @@ if ( my $branchname = $library->branchname; $session->param( 'branchname', $branchname ); # update sesssion in DB $session->param( 'branch', $branch ); # update sesssion in DB - push @updated, { - updated_branch => 1, - old_branch => $userenv_branch, - new_branch => $branch, - }; - } # else branch the same, no update -} elsif ( $op eq 'cud-set-library' && $library ) { - if ( $desk_id && ( !$userenv_desk or $userenv_desk ne $desk_id ) ) { - my $desk = Koha::Desks->find( { desk_id => $desk_id } ); - my $old_desk_name = ''; - if ($userenv_desk) { - $old_desk_name = Koha::Desks->find( { desk_id => $userenv_desk } )->desk_name; - } - $template->param( LoginDeskname => $desk->desk_name ); - $template->param( LoginDeskid => $desk->desk_id ); - $session->param( desk_name => $desk->desk_name ); - $session->param( desk_id => $desk->desk_id ); - $session->flush(); - push @updated, { - updated_desk => 1, - old_desk => $old_desk_name, - }; + $updated = 1; } - if ( defined($register_id) - && ( $userenv_register_id ne $register_id ) ) - { - my $old_register_name = C4::Context->userenv->{'register_name'} || ''; - my $register = Koha::Cash::Registers->find($register_id); - $session->param( 'register_id', $register_id ); - $session->param( 'register_name', $register ? $register->name : '' ); - push @updated, - { - updated_register => 1, - old_register => $old_register_name - }; +} else { + $branch = $userenv_branch; # fallback value +} + +if ( $desk_id && ( !$userenv_desk or $userenv_desk ne $desk_id ) ) { + my $desk = Koha::Desks->find( { desk_id => $desk_id } ); + my $old_desk_name = ''; + if ($userenv_desk) { + $old_desk_name = Koha::Desks->find( { desk_id => $userenv_desk } )->desk_name; } - $session->flush(); + $session->param( desk_name => $desk->desk_name ); + $session->param( desk_id => $desk->desk_id ); + $updated = 1; } else { - $branch = $userenv_branch; # fallback value $desk_id = $userenv_desk; } -$template->param(updated => \@updated) if (scalar @updated); - -my @recycle_loop; -foreach my $param ($query->param()) { - $param or next; # disclude blanks - $param eq "branch" and next; # disclude branch - $param eq "desk_id" and next; # disclude desk_id - $param eq "register_id" and next; # disclude register - $param eq "oldreferer" and next; # disclude oldreferer - push @recycle_loop, { - param => $param, - value => scalar $query->param($param), - }; +if ( defined($register_id) + && ( $userenv_register_id ne $register_id ) ) +{ + my $old_register_name = C4::Context->userenv->{'register_name'} || ''; + my $register = Koha::Cash::Registers->find($register_id); + $session->param( 'register_id', $register_id ); + $session->param( 'register_name', $register ? $register->name : '' ); + $updated = 1; +} else { + $register_id = $userenv_register_id; } -my $referer = $query->param('oldreferer') || $ENV{HTTP_REFERER} || ''; -$referer =~ /set-library\.pl/ and undef $referer; # avoid sending them back to this same page. +$session->flush(); -if (scalar @updated and not scalar @recycle_loop) { - # we updated something, and there were no extra params to POST: quick redirect - print $query->redirect($referer || '/cgi-bin/koha/circ/circulation.pl'); + +my $referer = $query->param('oldreferer') || $ENV{HTTP_REFERER} || ''; +if ( $updated ) { + print $query->redirect($referer || '/cgi-bin/koha/mainpage.pl'); } $template->param( referer => $referer, branch => $branch, desk_id => $desk_id, - recycle_loop=> \@recycle_loop, ); # Checking if there is a Fast Cataloging Framework diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt index 5834f2cfa5..a2fa68078d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt @@ -42,131 +42,83 @@
- - [% IF Koha.Preference('CircSidebar') %] -
- [% ELSE %] -
- [% END %] - [% INCLUDE 'messages.inc' %] -

Set library

- -[% IF ( updated ) %] - -

Update succeeded

-Updated:
    - [% FOREACH update IN updated %] - [% IF ( update.updated_branch || update.updated_desk || update.updated_register ) %] - [% IF ( update.updated_branch ) %] -
  • Library: [% update.old_branch or "?" | html %] ⇒ [% update.new_branch or "?" | html %]
  • - [% END %] - [% IF ( update.updated_desk ) %] -
  • Desk: [% update.old_desk or "?" | html %] ⇒ [% LoginDeskname or "?" | html %]
  • - [% END %] - [% IF ( updated.updated_register ) %] -
  • Register: [% updated.old_register or "?" | html %] ⇒ [% Registers.session_register_name or "?" | html %]
  • - [% END %] - [% ELSE %] -
  • ERROR - unknown
  • - [% END %] - [% END %] -
-
- [% INCLUDE 'csrf-token.inc' %] -
- [% FOREACH recycle_loo IN recycle_loop %] - [% SET param = recycle_loo.param %] - [% NEXT IF param == 'op' %] - [% NEXT IF param == 'csrf_token' %] - [% IF param == 'original_op' %][% param = 'op' %][% END %] - - [% IF param == 'op' %][% SET has_op = 1 %][% END %] - [% END %] - [% UNLESS has_op %] - [%# Trick to pass anti-CSRF requirements %] - [% END %] -
- -
- -[% ELSE %] - -
- [% INCLUDE 'csrf-token.inc' %] - -[% IF ( CAN_user_superlibrarian || CAN_user_loggedinlibrary ) %] -
- Set library -
    -
  1. -
  2. -
-
-[% ELSE %] - -[% END %] - -[% IF Koha.Preference('UseCirculationDesks') && Desks.all %] -
- Set desk -
    -
  1. -
  2. -
-
-[% END %] - -[% IF Koha.Preference('UseCashRegisters') %] -
- Set cash register -
    -
  1. - - -
  2. -
-
-[% END %] - -
- - Cancel -
-
- [% FOREACH recycle_loo IN recycle_loop %] - [% SET param = recycle_loo.param %] - [% IF param == 'op' %][% param = 'original_op' %][% END %] - - [% END %] - -
-
- -[% END %] - [% IF Koha.Preference('CircSidebar') %] -
-
- -
-
+
+ [% ELSE %] +
[% END %] + [% INCLUDE 'messages.inc' %] +

Set library

+
+ [% INCLUDE 'csrf-token.inc' %] + + [% IF ( CAN_user_superlibrarian || CAN_user_loggedinlibrary ) %] +
+ Set library +
    +
  1. +
  2. +
+
+ [% ELSE %] + + [% END %] -
-
- - + [% IF Koha.Preference('UseCirculationDesks') && Desks.all %] +
+ Set desk +
    +
  1. +
  2. +
+
+ [% IF Koha.Preference('UseCashRegisters') %] +
+ Set cash register +
    +
  1. + + +
  2. +
+
+ [% END %] +
+ + Cancel +
+
+ [% FOREACH recycle_loo IN recycle_loop %] + [% SET param = recycle_loo.param %] + [% IF param == 'op' %][% param = 'original_op' %][% END %] + + [% END %] + +
+ + + [% END %] + [% IF Koha.Preference('CircSidebar') %] + +
+ +
+ + [% END %] + + + [% MACRO jsinclude BLOCK %] [% Asset.js("js/desk_selection.js") | $raw %] [% Asset.js("js/register_selection.js") | $raw %] -- 2.39.5