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

(-)a/C4/Auth.pm (-2 / +3 lines)
Lines 1214-1221 sub checkauth { Link Here
1214
                        $register_id   = $register->id   if ($register);
1214
                        $register_id   = $register->id   if ($register);
1215
                        $register_name = $register->name if ($register);
1215
                        $register_name = $register->name if ($register);
1216
                    }
1216
                    }
1217
                    my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search->as_list };
1218
                    if ( $type ne 'opac' ) {
1217
                    if ( $type ne 'opac' ) {
1218
                        my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search->as_list };
1219
                        if ( C4::Context->preference('AutoLocation') ) {
1219
                        if ( C4::Context->preference('AutoLocation') ) {
1220
                            # we have to check they are coming from the right ip range
1220
                            # we have to check they are coming from the right ip range
1221
                            my $domain = $branches->{$branchcode}->{'branchip'};
1221
                            my $domain = $branches->{$branchcode}->{'branchip'};
Lines 1248-1254 sub checkauth { Link Here
1248
                                && $branches->{$branchcode}->{'branchip'} )
1248
                                && $branches->{$branchcode}->{'branchip'} )
1249
                            )
1249
                            )
1250
                        {
1250
                        {
1251
                            foreach my $br ( uniq( $branchcode, keys %$branches ) ) {
1251
                            my @branchcodes = sort { lc $a cmp lc $b } keys %$branches;
1252
                            foreach my $br ( uniq( $branchcode, @branchcodes ) ) {
1252
1253
1253
                                #     now we work with the treatment of ip
1254
                                #     now we work with the treatment of ip
1254
                                my $domain = $branches->{$br}->{'branchip'};
1255
                                my $domain = $branches->{$br}->{'branchip'};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (-3 / +3 lines)
Lines 91-104 Administration: Link Here
91
              class: integer
91
              class: integer
92
            - Adding d will specify it in days, e.g. 1d is timeout of one day.
92
            - Adding d will specify it in days, e.g. 1d is timeout of one day.
93
        -
93
        -
94
            - "Require staff to log in from a computer in the IP address range specified by their library (if any): "
94
            - "Require staff to log in from a computer in the IP address range specified by their library or the branch chosen at login (if any): "
95
            - pref: AutoLocation
95
            - pref: AutoLocation
96
              default: 0
96
              default: 0
97
              choices:
97
              choices:
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
            - 'Staff can only choose thier branch on login if they have "loggedinlibrary" permission. This setting will override the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=StaffLoginBranchBasedOnIP">StaffLoginBranchBasedOnIP</a> system preference. In the event of multiple branches with matching IPs, branchcode (alphabetically) will be the tie breaker.'
102
        -
102
        -
103
            - "Enable check for change in remote IP address for session security: "
103
            - "Enable check for change in remote IP address for session security: "
104
            - pref: SessionRestrictionByIP
104
            - pref: SessionRestrictionByIP
Lines 115-121 Administration: Link Here
115
                  1: "Yes"
115
                  1: "Yes"
116
                  0: "No"
116
                  0: "No"
117
            - "Note: If IPs overlap, the first found match will be used."
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.'
118
            - 'This setting will be overridden by <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=AutoLocation">AutoLocation</a> system preference. In the event of multiple branches with matching IPs, branchcode (alphabetically) will be the tie breaker.'
119
        # PostgreSQL is supported by CGI::Session but not by Koha.
119
        # PostgreSQL is supported by CGI::Session but not by Koha.
120
        -
120
        -
121
            - "Storage of login session information: "
121
            - "Storage of login session information: "
(-)a/t/db_dependent/Auth.t (-10 / +35 lines)
Lines 1341-1357 subtest 'StaffLoginBranchBasedOnIP' => sub { Link Here
1341
    );
1341
    );
1342
1342
1343
    t::lib::Mocks::mock_preference( 'AutoLocation', 0 );
1343
    t::lib::Mocks::mock_preference( 'AutoLocation', 0 );
1344
    my $other_branch   = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => "127.0.0.1" } } );
1344
    my $other_branch = $builder->build_object(
1345
        {
1346
            class => 'Koha::Libraries',
1347
            value => { branchip => "127.0.0.1", branchcode => substr( "z" . $branch->branchcode, 0, 10 ) }
1348
        }
1349
    );
1345
    ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1350
    ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1346
    is( $userid, $patron->userid, "User successfully logged in" );
1351
    is( $userid, $patron->userid, "User successfully logged in" );
1347
    $session = C4::Auth::get_session($sessionID);
1352
    $session = C4::Auth::get_session($sessionID);
1348
    is( $session->param('branch'), $branch->branchcode, "Logged in branch is set based which branch when two libraries have same IP?" );
1353
    is(
1354
        $session->param('branch'), $branch->branchcode,
1355
        "Logged in branch is set based which branch when two libraries have same IP?"
1356
    );
1349
1357
1350
};
1358
};
1351
1359
1352
subtest 'AutoLocation' => sub {
1360
subtest 'AutoLocation' => sub {
1353
1361
1354
    plan tests => 11;
1362
    plan tests => 12;
1355
1363
1356
    $schema->storage->txn_begin;
1364
    $schema->storage->txn_begin;
1357
1365
Lines 1428-1446 subtest 'AutoLocation' => sub { Link Here
1428
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1436
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1429
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1437
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1430
    $session = C4::Auth::get_session($sessionID);
1438
    $session = C4::Auth::get_session($sessionID);
1431
    is( $session->param('branch'), $noip_library->branchcode, "When a branch with no IP set is chosen, we respect the choice regardless of current IP" );
1439
    is(
1440
        $session->param('branch'), $noip_library->branchcode,
1441
        "When a branch with no IP set is chosen, we respect the choice regardless of current IP"
1442
    );
1432
1443
1433
    $ENV{REMOTE_ADDR} = '129.0.0.1';          # Set current IP to match other_branch
1444
    $ENV{REMOTE_ADDR} = '129.0.0.1';          # Set current IP to match other_branch
1434
    $cgi->param( 'branch', undef );           # Do not pass a branch
1445
    $cgi->param( 'branch', '' );              # Do not pass a branch
1435
    $patron->library->branchip('')->store;    # Unset user branch IP, to allow IP matching on any branch
1446
    $patron->library->branchip('')->store;    # Unset user branch IP, to allow IP matching on any branch
1436
    # Add a second branch with same IP
1447
                                              # Add a second branch with same IP
1437
    my $another_library = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => '129.0.0.1' } } );
1448
    my $another_library = $builder->build_object(
1449
        {
1450
            class => 'Koha::Libraries',
1451
            value => { branchip => "129.0.0.1", branchcode => substr( "z" . $other_library->branchcode, 0, 10 ) }
1452
        }
1453
    );
1438
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1454
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1439
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
1455
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
1440
    $session = C4::Auth::get_session($sessionID);
1456
    $session = C4::Auth::get_session($sessionID);
1441
    is(
1457
    is(
1442
        $session->param('branch'), $other_library->branchcode,
1458
        $session->param('branch'), $patron->library->branchcode,
1443
        "Which branch is chosen when home branch has no IP and more than 1 library matches?"
1459
        "When user branch has no IP, and no branch chosen, user is logged in to their homebranch"
1460
    );
1461
1462
    $cgi->param( 'branch', $another_library->branchcode )
1463
        ;    # Choose branch with duplicate IP and alphabetically later branchcode
1464
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1465
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
1466
    $session = C4::Auth::get_session($sessionID);
1467
    is(
1468
        $session->param('branch'), $another_library->branchcode,
1469
        "When there is an IP conflict, we use the chosen branch if it matches"
1444
    );
1470
    );
1445
1471
1446
    $schema->storage->txn_rollback;
1472
    $schema->storage->txn_rollback;
1447
- 

Return to bug 36908