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 1242-1248 sub checkauth { Link Here
1242
                            || ( C4::Context->preference('AutoLocation') && $auth_state ne 'failed' )
1242
                            || ( C4::Context->preference('AutoLocation') && $auth_state ne 'failed' )
1243
                            )
1243
                            )
1244
                        {
1244
                        {
1245
                            foreach my $br ( uniq( $branchcode, keys %$branches ) ) {
1245
                            my @branchcodes = sort { lc $a cmp lc $b } keys %$branches;
1246
                            foreach my $br ( uniq( $branchcode, @branchcodes ) ) {
1246
1247
1247
                                #     now we work with the treatment of ip
1248
                                #     now we work with the treatment of ip
1248
                                my $domain = $branches->{$br}->{'branchip'};
1249
                                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 (-5 / +13 lines)
Lines 1341-1351 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
        { class => 'Koha::Libraries', value => { branchip => "127.0.0.1", branchcode => "z" . $branch->branchcode } } );
1345
    ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1346
    ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' );
1346
    is( $userid, $patron->userid, "User successfully logged in" );
1347
    is( $userid, $patron->userid, "User successfully logged in" );
1347
    $session = C4::Auth::get_session($sessionID);
1348
    $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?" );
1349
    is(
1350
        $session->param('branch'), $branch->branchcode,
1351
        "Logged in branch is set based which branch when two libraries have same IP?"
1352
    );
1349
1353
1350
};
1354
};
1351
1355
Lines 1427-1434 subtest 'AutoLocation' => sub { Link Here
1427
    $ENV{REMOTE_ADDR} = '129.0.0.1';          # Set current IP to match other_branch
1431
    $ENV{REMOTE_ADDR} = '129.0.0.1';          # Set current IP to match other_branch
1428
    $cgi->param( 'branch', undef );           # Do not pass a branch
1432
    $cgi->param( 'branch', undef );           # Do not pass a branch
1429
    $patron->library->branchip('')->store;    # Unset user branch IP, to allow IP matching on any branch
1433
    $patron->library->branchip('')->store;    # Unset user branch IP, to allow IP matching on any branch
1430
    # Add a second branch with same IP
1434
                                              # Add a second branch with same IP
1431
    my $another_library = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => '129.0.0.1' } } );
1435
    my $another_library = $builder->build_object(
1436
        {
1437
            class => 'Koha::Libraries',
1438
            value => { branchip => '129.0.0.1', branchcode => "z" . $other_library->branchcode }
1439
        }
1440
    );
1432
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1441
    ( $userid, $cookie, $sessionID, $flags, $template ) =
1433
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
1442
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
1434
    $session = C4::Auth::get_session($sessionID);
1443
    $session = C4::Auth::get_session($sessionID);
1435
- 

Return to bug 36908