From 0a17e7181e928c80d53d7aebaaa16c9f71a57c45 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 --- 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 3d4c46ec7b..bc1f2c945e 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -495,35 +495,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 { @@ -1235,12 +1235,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 d551e6a15d..dffaaadd49 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -736,7 +736,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 84e9439bd6..60c68e11c9 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 f50740e189..c0f4fc5ae7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt @@ -158,7 +158,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 e9cb979085..ce7c7cffa9 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