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

(-)a/Koha/BackgroundJobs.pm (-7 / +4 lines)
Lines 40-48 Returns all background jobs the logged in user should be allowed to see Link Here
40
sub search_limited {
40
sub search_limited {
41
    my ( $self, $params, $attributes ) = @_;
41
    my ( $self, $params, $attributes ) = @_;
42
42
43
    # Assume permission if context has no user
43
    my $can_manage_background_jobs;
44
    my $can_manage_background_jobs = 1;
45
46
    my $logged_in_user;
44
    my $logged_in_user;
47
    my $userenv = C4::Context->userenv;
45
    my $userenv = C4::Context->userenv;
48
    if ( $userenv and $userenv->{number} ) {
46
    if ( $userenv and $userenv->{number} ) {
Lines 51-60 sub search_limited { Link Here
51
            { parameters => 'manage_background_jobs' } );
49
            { parameters => 'manage_background_jobs' } );
52
    }
50
    }
53
51
54
    return $can_manage_background_jobs
52
    return $self->search( $params, $attributes ) if $can_manage_background_jobs;
55
      ? $self->search( $params, $attributes )
53
    my $id = $logged_in_user ? $logged_in_user->borrowernumber : undef;
56
      : $self->search( { borrowernumber => $logged_in_user->borrowernumber } )
54
    return $self->search({ borrowernumber => $id  })->search( $params, $attributes );
57
      ->search( $params, $attributes );
58
}
55
}
59
56
60
=head3 filter_by_current
57
=head3 filter_by_current
(-)a/t/db_dependent/Koha/BackgroundJobs.t (-2 / +19 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 13;
22
use Test::More tests => 14;
23
use Test::MockModule;
23
use Test::MockModule;
24
24
25
use List::MoreUtils qw(any);
25
use List::MoreUtils qw(any);
Lines 122-124 subtest 'filter_by_current() tests' => sub { Link Here
122
122
123
    $schema->storage->txn_rollback;
123
    $schema->storage->txn_rollback;
124
};
124
};
125
- 
125
126
subtest 'search_limited' => sub {
127
    plan tests => 3;
128
129
    $schema->storage->txn_begin;
130
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } );
131
    my $patron2 = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } );
132
    my $job1 = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { borrowernumber => $patron1->id } } );
133
134
    C4::Context->set_userenv( undef, q{} );
135
    is( Koha::BackgroundJobs->search_limited->count, 0, 'No jobs found without userenv' );
136
    C4::Context->set_userenv( $patron1->id, $patron1->userid );
137
    is( Koha::BackgroundJobs->search_limited->count, 1, 'My job found' );
138
    C4::Context->set_userenv( $patron2->id, $patron2->userid );
139
    is( Koha::BackgroundJobs->search_limited->count, 0, 'No jobs for me' );
140
141
    $schema->storage->txn_rollback;
142
};

Return to bug 30982