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

(-)a/C4/Auth.pm (-4 / +4 lines)
Lines 952-958 sub checkauth { Link Here
952
        }
952
        }
953
953
954
        $sessionID = $session->id;
954
        $sessionID = $session->id;
955
        C4::Context->_new_userenv($sessionID);
955
        C4::Context->new_userenv($sessionID);
956
        $cookie = $query->cookie(
956
        $cookie = $query->cookie(
957
            -name     => 'CGISESSID',
957
            -name     => 'CGISESSID',
958
            -value    => $sessionID,
958
            -value    => $sessionID,
Lines 1509-1515 sub check_api_auth { Link Here
1509
            return ( "failed", undef, undef ) unless $session;
1509
            return ( "failed", undef, undef ) unless $session;
1510
1510
1511
            my $sessionID = $session->id;
1511
            my $sessionID = $session->id;
1512
            C4::Context->_new_userenv($sessionID);
1512
            C4::Context->new_userenv($sessionID);
1513
            my $cookie = $query->cookie(
1513
            my $cookie = $query->cookie(
1514
                -name     => 'CGISESSID',
1514
                -name     => 'CGISESSID',
1515
                -value    => $sessionID,
1515
                -value    => $sessionID,
Lines 1695-1701 sub check_cookie_auth { Link Here
1695
            $session->param( 'lasttime', time() );
1695
            $session->param( 'lasttime', time() );
1696
            my $flags = defined($flagsrequired) ? haspermission( $userid, $flagsrequired ) : 1;
1696
            my $flags = defined($flagsrequired) ? haspermission( $userid, $flagsrequired ) : 1;
1697
            if ($flags) {
1697
            if ($flags) {
1698
                C4::Context->_new_userenv($sessionID);
1698
                C4::Context->new_userenv($sessionID);
1699
                C4::Context->interface($session->param('interface'));
1699
                C4::Context->interface($session->param('interface'));
1700
                C4::Context->set_userenv(
1700
                C4::Context->set_userenv(
1701
                    $session->param('number'),       $session->param('id') // '',
1701
                    $session->param('number'),       $session->param('id') // '',
Lines 1714-1720 sub check_cookie_auth { Link Here
1714
            }
1714
            }
1715
1715
1716
        } else {
1716
        } else {
1717
            C4::Context->_new_userenv($sessionID);
1717
            C4::Context->new_userenv($sessionID);
1718
            C4::Context->interface($session->param('interface'));
1718
            C4::Context->interface($session->param('interface'));
1719
            C4::Context->set_userenv( undef, q{} );
1719
            C4::Context->set_userenv( undef, q{} );
1720
            return ( "anon", $session );
1720
            return ( "anon", $session );
(-)a/C4/InstallAuth.pm (-3 / +3 lines)
Lines 240-246 sub checkauth { Link Here
240
    my ( $userid, $cookie, $sessionID, $flags, $envcookie );
240
    my ( $userid, $cookie, $sessionID, $flags, $envcookie );
241
    my $logout = $query->param('logout.x');
241
    my $logout = $query->param('logout.x');
242
    if ( $sessionID = $query->cookie("CGISESSID") ) {
242
    if ( $sessionID = $query->cookie("CGISESSID") ) {
243
        C4::Context->_new_userenv($sessionID);
243
        C4::Context->new_userenv($sessionID);
244
        my $session =
244
        my $session =
245
          CGI::Session->new( "driver:File", $sessionID,
245
          CGI::Session->new( "driver:File", $sessionID,
246
            { Directory => $sessdir } );
246
            { Directory => $sessdir } );
Lines 285-293 sub checkauth { Link Here
285
          CGI::Session->new( "driver:File", undef, { Directory => $sessdir } );
285
          CGI::Session->new( "driver:File", undef, { Directory => $sessdir } );
286
        $sessionID = $session->id;
286
        $sessionID = $session->id;
287
        $userid    = $query->param('userid');
287
        $userid    = $query->param('userid');
288
        C4::Context->_new_userenv($sessionID);
288
        C4::Context->new_userenv($sessionID);
289
        my $password = $query->param('password');
289
        my $password = $query->param('password');
290
        C4::Context->_new_userenv($sessionID);
290
        C4::Context->new_userenv($sessionID);
291
        my ( $return, $cardnumber ) = checkpw( $userid, $password );
291
        my ( $return, $cardnumber ) = checkpw( $userid, $password );
292
        if ($return) {
292
        if ($return) {
293
            $loggedin = 1;
293
            $loggedin = 1;
(-)a/Koha/REST/V1/Auth.pm (-1 / +1 lines)
Lines 518-524 sub _set_userenv { Link Here
518
        $THE_library = $patron->library;
518
        $THE_library = $patron->library;
519
    }
519
    }
520
520
521
    C4::Context->_new_userenv( $patron->borrowernumber );
521
    C4::Context->new_userenv( $patron->borrowernumber );
522
    C4::Context->set_userenv(
522
    C4::Context->set_userenv(
523
        $patron->borrowernumber,  # number,
523
        $patron->borrowernumber,  # number,
524
        $patron->userid,          # userid,
524
        $patron->userid,          # userid,
(-)a/Koha/Script.pm (-2 / +2 lines)
Lines 46-56 sub import { Link Here
46
    my $class = shift;
46
    my $class = shift;
47
    my @flags = @_;
47
    my @flags = @_;
48
48
49
    C4::Context->_new_userenv(1);
49
    C4::Context->new_userenv(1);
50
    if ( ( $flags[0] || '' ) eq '-cron' ) {
50
    if ( ( $flags[0] || '' ) eq '-cron' ) {
51
51
52
        # Set userenv
52
        # Set userenv
53
        C4::Context->_new_userenv(1);
53
        C4::Context->new_userenv(1);
54
        C4::Context->set_userenv(
54
        C4::Context->set_userenv(
55
            undef, undef, undef, 'CRON', 'CRON',
55
            undef, undef, undef, 'CRON', 'CRON',
56
            undef, undef, undef, undef,  undef
56
            undef, undef, undef, undef,  undef
(-)a/opac/ilsdi.pl (-1 / +1 lines)
Lines 128-134 unless ( $cgi->param('service') ) { Link Here
128
}
128
}
129
129
130
# Set the userenv
130
# Set the userenv
131
C4::Context->_new_userenv( 'ILSDI_'.time() );
131
C4::Context->new_userenv( 'ILSDI_'.time() );
132
C4::Context->set_userenv(
132
C4::Context->set_userenv(
133
    undef, undef, undef, 'ILSDI', 'ILSDI',
133
    undef, undef, undef, 'ILSDI', 'ILSDI',
134
    undef, undef, undef, undef, undef,
134
    undef, undef, undef, undef, undef,
(-)a/t/Token.t (-1 / +1 lines)
Lines 26-32 use Time::HiRes qw|usleep|; Link Here
26
use C4::Context;
26
use C4::Context;
27
use Koha::Token;
27
use Koha::Token;
28
28
29
C4::Context->_new_userenv('DUMMY SESSION');
29
C4::Context->new_userenv('DUMMY SESSION');
30
C4::Context->set_userenv(0,42,0,'firstname','surname', 'CPL', 'Library 1', 0, '');
30
C4::Context->set_userenv(0,42,0,'firstname','surname', 'CPL', 'Library 1', 0, '');
31
31
32
my $tokenizer = Koha::Token->new;
32
my $tokenizer = Koha::Token->new;
(-)a/t/db_dependent/Auth.t (-3 / +3 lines)
Lines 108-114 subtest 'checkauth() tests' => sub { Link Here
108
        is( $userid, undef, 'If librarian user is used and password with GET, they should not be logged in' );
108
        is( $userid, undef, 'If librarian user is used and password with GET, they should not be logged in' );
109
    };
109
    };
110
110
111
    C4::Context->_new_userenv; # For next tests
111
    C4::Context->new_userenv; # For next tests
112
112
113
};
113
};
114
114
Lines 167-173 subtest 'no_set_userenv parameter tests' => sub { Link Here
167
167
168
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
168
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
169
    is( C4::Context->userenv, undef, 'Userenv should be undef as required' );
169
    is( C4::Context->userenv, undef, 'Userenv should be undef as required' );
170
    C4::Context->_new_userenv('DUMMY SESSION');
170
    C4::Context->new_userenv('DUMMY SESSION');
171
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', '');
171
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', '');
172
    is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' );
172
    is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' );
173
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
173
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
Lines 641-647 subtest 'Userenv clearing in check_cookie_auth' => sub { Link Here
641
    is( C4::Context->userenv, undef, 'Environment should be cleared too' );
641
    is( C4::Context->userenv, undef, 'Environment should be cleared too' );
642
642
643
    # Show that we clear the userenv again: set up env and check deleted session
643
    # Show that we clear the userenv again: set up env and check deleted session
644
    C4::Context->_new_userenv( $sessionID );
644
    C4::Context->new_userenv( $sessionID );
645
    C4::Context->set_userenv; # empty
645
    C4::Context->set_userenv; # empty
646
    is( defined C4::Context->userenv, 1, 'There should be an empty userenv again' );
646
    is( defined C4::Context->userenv, 1, 'There should be an empty userenv again' );
647
    ( $auth_status, $session) = C4::Auth::check_cookie_auth( $sessionID );
647
    ( $auth_status, $session) = C4::Auth::check_cookie_auth( $sessionID );
(-)a/t/db_dependent/Koha/Items.t (-1 / +1 lines)
Lines 1288-1294 subtest 'store' => sub { Link Here
1288
            C4::Circulation::LostItem( $item->itemnumber, 1 );
1288
            C4::Circulation::LostItem( $item->itemnumber, 1 );
1289
1289
1290
            # Unset the userenv
1290
            # Unset the userenv
1291
            C4::Context->_new_userenv(undef);
1291
            C4::Context->new_userenv(undef);
1292
1292
1293
            # Simluate item marked as found
1293
            # Simluate item marked as found
1294
            $item->itemlost(0)->store;
1294
            $item->itemlost(0)->store;
(-)a/t/db_dependent/Koha/Reviews.t (-1 / +1 lines)
Lines 70-76 is( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id Link Here
70
70
71
subtest 'search_limited' => sub {
71
subtest 'search_limited' => sub {
72
    plan tests => 2;
72
    plan tests => 2;
73
    C4::Context->_new_userenv('xxx');
73
    C4::Context->new_userenv('xxx');
74
    my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1' } )->store;
74
    my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1' } )->store;
75
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
75
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
76
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron_1->branchcode })->store();
76
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron_1->branchcode })->store();
(-)a/t/db_dependent/Koha/Template/Plugin/Registers.t (-2 / +2 lines)
Lines 45-51 subtest 'session_register_id' => sub { Link Here
45
        '1', "Returns the register id when set in the userenv" );
45
        '1', "Returns the register id when set in the userenv" );
46
46
47
    # Unset the userenv
47
    # Unset the userenv
48
    C4::Context->_new_userenv(undef);
48
    C4::Context->new_userenv(undef);
49
};
49
};
50
50
51
subtest 'session_register_name' => sub {
51
subtest 'session_register_name' => sub {
Lines 61-67 subtest 'session_register_name' => sub { Link Here
61
        'Register One', "Returns the register name when set in the userenv" );
61
        'Register One', "Returns the register name when set in the userenv" );
62
62
63
    # Unset the userenv
63
    # Unset the userenv
64
    C4::Context->_new_userenv(undef);
64
    C4::Context->new_userenv(undef);
65
};
65
};
66
66
67
subtest 'all() tests' => sub {
67
subtest 'all() tests' => sub {
(-)a/t/db_dependent/Patron/Borrower_Discharge.t (-1 / +1 lines)
Lines 42-48 my $library = $builder->build({ source => 'Branch' }); Link Here
42
my $another_library = $builder->build({ source => 'Branch' });
42
my $another_library = $builder->build({ source => 'Branch' });
43
my $itemtype        = $builder->build({ source => 'Itemtype' })->{itemtype};
43
my $itemtype        = $builder->build({ source => 'Itemtype' })->{itemtype};
44
44
45
C4::Context->_new_userenv('xxx');
45
C4::Context->new_userenv('xxx');
46
my $patron = $builder->build({
46
my $patron = $builder->build({
47
    source => 'Borrower',
47
    source => 'Borrower',
48
    value => {
48
    value => {
(-)a/t/lib/Mocks.pm (-2 / +1 lines)
Lines 115-121 Also, some sane defaults are set if no parameters are passed. Link Here
115
sub mock_userenv {
115
sub mock_userenv {
116
    my ( $params ) = @_;
116
    my ( $params ) = @_;
117
117
118
    C4::Context->_new_userenv(42);
118
    C4::Context->new_userenv(42);
119
119
120
    my $userenv;
120
    my $userenv;
121
    if ( $params and my $patron = $params->{patron} ) {
121
    if ( $params and my $patron = $params->{patron} ) {
122
- 

Return to bug 29954