From d926f3a8d639c8f589e646e15c6643bb934809d2 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 23 May 2024 10:54:08 +0100 Subject: [PATCH] Bug 26176: (QA follow-up) Also rename StaffLoginBranchBasedOnIP This patch also renames StaffLoginBranchBasedOnIP to StaffLoginLibraryBasedOnIP to be consistent with our terminology guidelines Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer (cherry picked from commit 0a17e7181e928c80d53d7aebaaa16c9f71a57c45) Signed-off-by: Fridolin Somers --- C4/Auth.pm | 61 ++++++++++--------- .../data/mysql/atomicupdate/bug_26176.pl | 17 +++++- installer/data/mysql/mandatory/sysprefs.sql | 2 +- .../en/modules/admin/preferences/admin.pref | 4 +- .../intranet-tmpl/prog/en/modules/auth.tt | 2 +- t/db_dependent/Auth.t | 10 +-- 6 files changed, 55 insertions(+), 41 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index ea766c1a04..0bf0612be8 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -477,35 +477,35 @@ sub get_template_and_user { if ( $in->{'type'} eq "intranet" ) { $template->param( - advancedMARCEditor => C4::Context->preference("advancedMARCEditor"), - AllowMultipleCovers => C4::Context->preference('AllowMultipleCovers'), - AmazonCoverImages => C4::Context->preference("AmazonCoverImages"), + advancedMARCEditor => C4::Context->preference("advancedMARCEditor"), + AllowMultipleCovers => C4::Context->preference('AllowMultipleCovers'), + AmazonCoverImages => C4::Context->preference("AmazonCoverImages"), StaffLoginRestrictLibraryByIP => C4::Context->preference("StaffLoginRestrictLibraryByIP"), - can_see_cataloguing_module => haspermission( $user, get_cataloguing_page_permissions() ) ? 1 : 0, - canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'), - EasyAnalyticalRecords => C4::Context->preference('EasyAnalyticalRecords'), - EnableBorrowerFiles => C4::Context->preference('EnableBorrowerFiles'), - FRBRizeEditions => C4::Context->preference("FRBRizeEditions"), - IndependentBranches => C4::Context->preference("IndependentBranches"), - intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), - IntranetFavicon => C4::Context->preference("IntranetFavicon"), - IntranetmainUserblock => C4::Context->preference("IntranetmainUserblock"), - IntranetNav => C4::Context->preference("IntranetNav"), - intranetreadinghistory => C4::Context->preference("intranetreadinghistory"), - IntranetReadingHistoryHolds => C4::Context->preference("IntranetReadingHistoryHolds"), - intranetstylesheet => C4::Context->preference("intranetstylesheet"), - IntranetUserCSS => C4::Context->preference("IntranetUserCSS"), - IntranetUserJS => C4::Context->preference("IntranetUserJS"), - LibraryName => C4::Context->preference("LibraryName"), - LocalCoverImages => C4::Context->preference('LocalCoverImages'), - OPACLocalCoverImages => C4::Context->preference('OPACLocalCoverImages'), - PatronAutoComplete => C4::Context->preference("PatronAutoComplete"), - pending_checkout_notes => Koha::Checkouts->search( { noteseen => 0 } ), - plugins_enabled => C4::Context->config("enable_plugins"), - StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"), - UseCourseReserves => C4::Context->preference("UseCourseReserves"), - useDischarge => C4::Context->preference('useDischarge'), - virtualshelves => C4::Context->preference("virtualshelves"), + can_see_cataloguing_module => haspermission( $user, get_cataloguing_page_permissions() ) ? 1 : 0, + canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'), + EasyAnalyticalRecords => C4::Context->preference('EasyAnalyticalRecords'), + EnableBorrowerFiles => C4::Context->preference('EnableBorrowerFiles'), + FRBRizeEditions => C4::Context->preference("FRBRizeEditions"), + IndependentBranches => C4::Context->preference("IndependentBranches"), + intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), + IntranetFavicon => C4::Context->preference("IntranetFavicon"), + IntranetmainUserblock => C4::Context->preference("IntranetmainUserblock"), + IntranetNav => C4::Context->preference("IntranetNav"), + intranetreadinghistory => C4::Context->preference("intranetreadinghistory"), + IntranetReadingHistoryHolds => C4::Context->preference("IntranetReadingHistoryHolds"), + intranetstylesheet => C4::Context->preference("intranetstylesheet"), + IntranetUserCSS => C4::Context->preference("IntranetUserCSS"), + IntranetUserJS => C4::Context->preference("IntranetUserJS"), + LibraryName => C4::Context->preference("LibraryName"), + LocalCoverImages => C4::Context->preference('LocalCoverImages'), + OPACLocalCoverImages => C4::Context->preference('OPACLocalCoverImages'), + PatronAutoComplete => C4::Context->preference("PatronAutoComplete"), + pending_checkout_notes => Koha::Checkouts->search( { noteseen => 0 } ), + plugins_enabled => C4::Context->config("enable_plugins"), + StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"), + UseCourseReserves => C4::Context->preference("UseCourseReserves"), + useDischarge => C4::Context->preference('useDischarge'), + virtualshelves => C4::Context->preference("virtualshelves"), ); } else { @@ -1215,12 +1215,13 @@ sub checkauth { } if ( - # If StaffLoginBranchBasedOnIP is enabled we will try to find a branch + # If StaffLoginLibraryBasedOnIP is enabled we will try to find a branch # matching your ip, regardless of the choice you have passed in ( !C4::Context->preference('StaffLoginRestrictLibraryByIP') - && C4::Context->preference('StaffLoginBranchBasedOnIP') + && C4::Context->preference('StaffLoginLibraryBasedOnIP') ) + # When StaffLoginRestrictLibraryByIP is enabled we will not choose a branch matching IP # if your selected branch has no IP set || ( C4::Context->preference('StaffLoginRestrictLibraryByIP') diff --git a/installer/data/mysql/atomicupdate/bug_26176.pl b/installer/data/mysql/atomicupdate/bug_26176.pl index 784c569351..cc7fb4e5a7 100755 --- a/installer/data/mysql/atomicupdate/bug_26176.pl +++ b/installer/data/mysql/atomicupdate/bug_26176.pl @@ -3,7 +3,7 @@ use Koha::Installer::Output qw(say_warning say_failure say_success say_info); return { bug_number => "26176", - description => "Rename AutoLocation to StaffLoginRestrictLibraryByIP", + description => "Rename AutoLocation and StaffLoginBranchBasedOnIP", up => sub { my ($args) = @_; my ( $dbh, $out ) = @$args{qw(dbh out)}; @@ -15,6 +15,19 @@ return { } ); - say $out "Renamed system preference 'AutoLocation' to 'StaffLoginRestrictLibraryByIP'"; + say_success( $out, "Renamed system preference 'AutoLocation' to 'StaffLoginRestrictLibraryByIP'" ); + + $dbh->do( + q{ + UPDATE systempreferences SET variable = "StaffLoginRestrictLibraryByIP" + WHERE variable = "StaffLoginLibraryBasedOnIP" + } + ); + + say_success( + $out, + "Renamed system preference 'StaffLoginLibraryBasedOnIP' to 'StaffLoginRestrictLibraryByIP'" + ); + }, }; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index eb8862d273..a23d375322 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -723,7 +723,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('StaffHighlightedWords','1','','Highlight search terms on staff interface','YesNo'), ('StaffLangSelectorMode','footer','top|both|footer','Select the location to display the language selector in staff interface','Choice'), ('StaffLoginInstructions', '', NULL, 'HTML to go into the login box for the staff interface','Free'), -('StaffLoginBranchBasedOnIP', '1','', 'Set the logged in library for the user based on their current IP','YesNo'), +('StaffLoginLibraryBasedOnIP', '1','', 'Set the logged in library for the user based on their current IP','YesNo'), ('StaffLoginRestrictLibraryByIP','0',NULL,'If ON, IP authentication is enabled, blocking access to the staff interface from unauthorized IP addresses based on branch','YesNo'), ('StaffSearchResultsDisplayBranch','holdingbranch','holdingbranch|homebranch','Controls the display of the home or holding branch for staff search results','Choice'), ('StaffSerialIssueDisplayCount','3','','Number of serial issues to display per subscription in the staff interface','Integer'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref index 2d3e6d5cd0..27f46631a7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -98,7 +98,7 @@ Administration: 1: "Yes" 0: "No" - Link to library administration - - 'Staff can only choose their library at login if they have the "loggedinlibrary" permission. This setting will override the StaffLoginBranchBasedOnIP system preference. In the event of multiple libraries with matching IPs, branchcode (alphabetically) will be the tie breaker.' + - 'Staff can only choose their library at login if they have the "loggedinlibrary" permission. This setting will override the StaffLoginLibraryBasedOnIP system preference. In the event of multiple libraries with matching IPs, branchcode (alphabetically) will be the tie breaker.' - - "Enable check for change in remote IP address for session security: " - pref: SessionRestrictionByIP @@ -109,7 +109,7 @@ Administration: - (Disable only when remote IP address changes frequently.) - - "Set logged in library for staff by matching their current IP to the library configuration: " - - pref: StaffLoginBranchBasedOnIP + - pref: StaffLoginLibraryBasedOnIP default: 0 choices: 1: "Yes" diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt index a65a96fa3d..784463b43c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt @@ -154,7 +154,7 @@ [% IF Koha.Preference('ForceLibrarySelection') %] Required [% END %] - [% IF Koha.Preference('StaffLoginBranchBasedOnIP')%] + [% IF Koha.Preference('StaffLoginLibraryBasedOnIP')%] Note: Your selection may be overridden if your current IP matches a specified IP for a branch in Koha [% END %]

diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t index 2faf3e5f8e..5b0b771ca6 100755 --- a/t/db_dependent/Auth.t +++ b/t/db_dependent/Auth.t @@ -1292,14 +1292,14 @@ subtest 'checkpw() return values tests' => sub { }; }; -subtest 'StaffLoginBranchBasedOnIP' => sub { +subtest 'StaffLoginLibraryBasedOnIP' => sub { plan tests => 7; $schema->storage->txn_begin; t::lib::Mocks::mock_preference( 'StaffLoginRestrictLibraryByIP', 0 ); - t::lib::Mocks::mock_preference( 'StaffLoginBranchBasedOnIP', 0 ); + t::lib::Mocks::mock_preference( 'StaffLoginLibraryBasedOnIP', 0 ); my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); my $branch = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => "127.0.0.1" } } ); @@ -1324,20 +1324,20 @@ subtest 'StaffLoginBranchBasedOnIP' => sub { is( $session->param('branch'), $patron->branchcode, "Logged in branch is set to the patron's branchcode" ); my $template; - t::lib::Mocks::mock_preference( 'StaffLoginBranchBasedOnIP', 1 ); + t::lib::Mocks::mock_preference( 'StaffLoginLibraryBasedOnIP', 1 ); ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); is( $userid, $patron->userid, "User successfully logged in" ); $session = C4::Auth::get_session($sessionID); is( $session->param('branch'), $branch->branchcode, "Logged in branch is set based on the IP from REMOTE_ADDR " ); - # StaffLoginRestrictLibraryByIP overrides StaffLoginBranchBasedOnIP + # StaffLoginRestrictLibraryByIP overrides StaffLoginLibraryBasedOnIP t::lib::Mocks::mock_preference( 'StaffLoginRestrictLibraryByIP', 1 ); ( $userid, $cookie, $sessionID, $flags, $template ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); is( $template->{VARS}->{wrongip}, 1, - "StaffLoginRestrictLibraryByIP prevents StaffLoginBranchBasedOnIP from logging user in to another branch" + "StaffLoginRestrictLibraryByIP prevents StaffLoginLibraryBasedOnIP from logging user in to another branch" ); t::lib::Mocks::mock_preference( 'StaffLoginRestrictLibraryByIP', 0 ); -- 2.39.5