From 04f8b047b3413e0e053b0662d6c0d4307f47e19f Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Tue, 13 Dec 2022 20:59:50 +0000 Subject: [PATCH] Bug 30624: Add loggedinlibrary permission and DB update --- C4/Auth.pm | 3 ++- .../atomicupdate/bug_30624_add_userflag.pl | 20 +++++++++++++++++++ installer/data/mysql/mandatory/userflags.sql | 3 ++- .../prog/en/includes/circ-nav.inc | 3 +-- .../intranet-tmpl/prog/en/includes/header.inc | 2 +- .../prog/en/includes/permissions.inc | 3 +++ .../prog/en/modules/circ/circulation-home.tt | 2 +- .../prog/en/modules/circ/set-library.tt | 2 +- 8 files changed, 31 insertions(+), 7 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_30624_add_userflag.pl diff --git a/C4/Auth.pm b/C4/Auth.pm index d8ddb170985..f6127fe8e38 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1154,7 +1154,8 @@ sub checkauth { my $ip = $ENV{'REMOTE_ADDR'}; # if they specify at login, use that - if ( $query->param('branch') ) { + my $patron = Koha::Patrons->find({userid => $userid}); + if ( $query->param('branch') && ( haspermission($userid, { 'loggedinlibrary'=> 1 }) || $patron->is_superlibrarian ) ) { $branchcode = $query->param('branch'); my $library = Koha::Libraries->find($branchcode); $branchname = $library? $library->branchname: ''; diff --git a/installer/data/mysql/atomicupdate/bug_30624_add_userflag.pl b/installer/data/mysql/atomicupdate/bug_30624_add_userflag.pl new file mode 100755 index 00000000000..38735f1f997 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_30624_add_userflag.pl @@ -0,0 +1,20 @@ +use Modern::Perl; + +return { + bug_number => "30624", + description => "Add loggedinlibrary permission", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + $dbh->do(q{ + INSERT IGNORE INTO userflags (bit, flag, flagdesc, defaulton) VALUES (29, 'loggedinlibrary', 'Allow staff to change logged in library', 0) + }); + + my $IndependentBranches = C4::Context->preference('IndependentBranches'); + unless ( $IndependentBranches ) { + $dbh->do(q{ + UPDATE borrowers SET flags = flags + (2<<28) WHERE flags & 4; + }); + } + }, +}; diff --git a/installer/data/mysql/mandatory/userflags.sql b/installer/data/mysql/mandatory/userflags.sql index 137612f14cd..b9905e2f5e7 100644 --- a/installer/data/mysql/mandatory/userflags.sql +++ b/installer/data/mysql/mandatory/userflags.sql @@ -25,5 +25,6 @@ INSERT INTO userflags (bit, flag, flagdesc, defaulton) VALUES (25, 'cash_management', 'Cash management', 0), (26, 'problem_reports', 'Manage problem reports', 0), (27, 'recalls', 'Recalls', 0), -(28, 'erm', 'Manage electronic resources', 0) +(28, 'erm', 'Manage electronic resources', 0), +(29, 'loggedinlibrary', 'Change logged in library', 0) ; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc index 61d82953b47..122741c569d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc @@ -2,7 +2,6 @@ [% USE Branches %]