View | Details | Raw Unified | Return to bug 36665
Collapse All | Expand All

(-)a/C4/Auth.pm (-1 / +8 lines)
Lines 1234-1240 sub checkauth { Link Here
1234
                        }
1234
                        }
1235
                    }
1235
                    }
1236
1236
1237
                    if ( C4::Context->preference('AutoLocation') && $auth_state ne 'failed' ) {
1237
                    if (
1238
                        (
1239
                              !C4::Context->preference('AutoLocation')
1240
                            && C4::Context->preference('StaffLoginBranchBasedOnIP')
1241
                        )
1242
                        || ( C4::Context->preference('AutoLocation') && $auth_state ne 'failed' )
1243
                        )
1244
                    {
1238
                        foreach my $br ( uniq( $branchcode, keys %$branches ) ) {
1245
                        foreach my $br ( uniq( $branchcode, keys %$branches ) ) {
1239
1246
1240
                            #     now we work with the treatment of ip
1247
                            #     now we work with the treatment of ip
(-)a/installer/data/mysql/atomicupdate/bug_36665.pl (+21 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
3
4
return {
5
    bug_number  => "36665",
6
    description => "Add StaffLoginBranchBasedOnIP",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        # Do you stuffs here
12
        $dbh->do(
13
            q{
14
            INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
15
            ('StaffLoginBranchBasedOnIP', '0','', 'Set the logged in branch for the user based on their current IP','YesNo')
16
        }
17
        );
18
19
        say $out "Added new system preference 'StaffLoginBranchBasedOnIP'";
20
    },
21
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 737-742 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
737
('StaffHighlightedWords','1','','Highlight search terms on staff interface','YesNo'),
737
('StaffHighlightedWords','1','','Highlight search terms on staff interface','YesNo'),
738
('StaffLangSelectorMode','footer','top|both|footer','Select the location to display the language selector in staff interface','Choice'),
738
('StaffLangSelectorMode','footer','top|both|footer','Select the location to display the language selector in staff interface','Choice'),
739
('StaffLoginInstructions', '', NULL, 'HTML to go into the login box for the staff interface','Free'),
739
('StaffLoginInstructions', '', NULL, 'HTML to go into the login box for the staff interface','Free'),
740
('StaffLoginBranchBasedOnIP', '0','', 'Set the logged in branch for the user based on their current IP','YesNo'),
740
('StaffSearchResultsDisplayBranch','holdingbranch','holdingbranch|homebranch','Controls the display of the home or holding branch for staff search results','Choice'),
741
('StaffSearchResultsDisplayBranch','holdingbranch','holdingbranch|homebranch','Controls the display of the home or holding branch for staff search results','Choice'),
741
('StaffSerialIssueDisplayCount','3','','Number of serial issues to display per subscription in the staff interface','Integer'),
742
('StaffSerialIssueDisplayCount','3','','Number of serial issues to display per subscription in the staff interface','Integer'),
742
('staffShibOnly','0','','If ON enables shibboleth only authentication for the staff client','YesNo'),
743
('staffShibOnly','0','','If ON enables shibboleth only authentication for the staff client','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (+10 lines)
Lines 98-103 Administration: Link Here
98
                  1: "Yes"
98
                  1: "Yes"
99
                  0: "No"
99
                  0: "No"
100
            - <a href="/cgi-bin/koha/admin/branches.pl">Link to library administration</a>
100
            - <a href="/cgi-bin/koha/admin/branches.pl">Link to library administration</a>
101
            - 'This setting will override the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=StaffLoginBranchBasedOnIP">StaffLoginBranchBasedOnIP</a> system preference.'
101
        -
102
        -
102
            - "Enable check for change in remote IP address for session security: "
103
            - "Enable check for change in remote IP address for session security: "
103
            - pref: SessionRestrictionByIP
104
            - pref: SessionRestrictionByIP
Lines 106-111 Administration: Link Here
106
                  1: "Yes"
107
                  1: "Yes"
107
                  0: "No"
108
                  0: "No"
108
            - (Disable only when remote IP address changes frequently.)
109
            - (Disable only when remote IP address changes frequently.)
110
        -
111
            - "Set the logged in branch for staff based on their current branch: "
112
            - pref: StaffLoginBranchBasedOnIP
113
              default: 0
114
              choices:
115
                  1: "Yes"
116
                  0: "No"
117
            - "Note: If IPs overlap, the first found match will be used."
118
            - 'This setting will be overridden by <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=AutoLocation">AutoLocation</a> system preference.'
109
        # PostgreSQL is supported by CGI::Session but not by Koha.
119
        # PostgreSQL is supported by CGI::Session but not by Koha.
110
        -
120
        -
111
            - "Storage of login session information: "
121
            - "Storage of login session information: "
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt (+3 lines)
Lines 158-163 Link Here
158
            [% IF Koha.Preference('ForceLibrarySelection') %]
158
            [% IF Koha.Preference('ForceLibrarySelection') %]
159
                <span class="required">Required</span>
159
                <span class="required">Required</span>
160
            [% END %]
160
            [% END %]
161
            [% IF Koha.Preference('StaffLoginBranchBasedOnIP')%]
162
                <span class="warning">Note: Your selection may be overridden if your current IP matches a specified IP for a branch in Koha</span>
163
            [% END %]
161
        </p>
164
        </p>
162
165
163
        [% IF Koha.Preference('UseCirculationDesks') && Desks.all %]
166
        [% IF Koha.Preference('UseCirculationDesks') && Desks.all %]
(-)a/t/db_dependent/Auth.t (-2 / +51 lines)
Lines 7-13 use CGI qw ( -utf8 ); Link Here
7
use Test::MockObject;
7
use Test::MockObject;
8
use Test::MockModule;
8
use Test::MockModule;
9
use List::MoreUtils qw/all any none/;
9
use List::MoreUtils qw/all any none/;
10
use Test::More tests => 21;
10
use Test::More tests => 22;
11
use Test::Warn;
11
use Test::Warn;
12
use t::lib::Mocks;
12
use t::lib::Mocks;
13
use t::lib::TestBuilder;
13
use t::lib::TestBuilder;
Lines 1292-1297 subtest 'checkpw() return values tests' => sub { Link Here
1292
    };
1292
    };
1293
};
1293
};
1294
1294
1295
subtest 'StaffLoginBranchBasedOnIP' => sub {
1296
1297
    plan tests => 5;
1298
1299
    $schema->storage->txn_begin;
1300
1301
    t::lib::Mocks::mock_preference( 'AutoLocation',              0 );
1302
    t::lib::Mocks::mock_preference( 'StaffLoginBranchBasedOnIP', 0 );
1303
1304
    my $patron   = $builder->build_object( { class => 'Koha::Patrons',   value => { flags    => 1 } } );
1305
    my $branch   = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => "127.0.0.1" } } );
1306
    my $password = 'password';
1307
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
1308
    $patron->set_password( { password => $password } );
1309
1310
    my $cgi_mock = Test::MockModule->new('CGI');
1311
    $cgi_mock->mock( 'request_method', sub { return 'POST' } );
1312
    my $cgi  = CGI->new;
1313
    my $auth = Test::MockModule->new('C4::Auth');
1314
1315
    # Simulating the login form submission
1316
    $cgi->param( 'login_userid',   $patron->userid );
1317
    $cgi->param( 'login_password', $password );
1318
1319
    $ENV{REMOTE_ADDR} = '127.0.0.1';
1320
    my ( $userid, $cookie, $sessionID, $flags ) =
1321
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1322
    is( $userid, $patron->userid, "User successfully logged in" );
1323
    my $session = C4::Auth::get_session($sessionID);
1324
    is( $session->param('branch'), $patron->branchcode, "Logged in branch is set to the patron's branchcode" );
1325
1326
    my $template;
1327
    t::lib::Mocks::mock_preference( 'StaffLoginBranchBasedOnIP', 1 );
1328
1329
    ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1330
    is( $userid, $patron->userid, "User successfully logged in" );
1331
    $session = C4::Auth::get_session($sessionID);
1332
    is( $session->param('branch'), $branch->branchcode, "Logged in branch is set based on the IP from REMOTE_ADDR " );
1333
1334
    # AutoLocation overrides StaffLoginBranchBasedOnIP
1335
    t::lib::Mocks::mock_preference( 'AutoLocation', 1 );
1336
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1337
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
1338
    is(
1339
        $template->{VARS}->{wrongip}, 1,
1340
        "AutoLocation prevents StaffLoginBranchBasedOnIP from logging user in to another branch"
1341
    );
1342
1343
};
1344
1295
subtest 'AutoLocation' => sub {
1345
subtest 'AutoLocation' => sub {
1296
1346
1297
    plan tests => 7;
1347
    plan tests => 7;
1298
- 

Return to bug 36665