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

(-)a/Koha/BackgroundJobs.pm (+28 lines)
Lines 29-34 Koha::BackgroundJobs - Koha BackgroundJob Object set class Link Here
29
29
30
=cut
30
=cut
31
31
32
=head2 search_limited
33
34
  my $background_jobs = Koha::BackgroundJobs->search_limited( $params, $attributes );
35
36
Returns all background jobs the logged in user should be allowed to see
37
38
=cut
39
40
sub search_limited {
41
    my ( $self, $params, $attributes ) = @_;
42
43
    # Assume permission if context has no user
44
    my $can_manage_background_jobs = 1;
45
46
    my $logged_in_user;
47
    my $userenv = C4::Context->userenv;
48
    if ( $userenv and $userenv->{number} ) {
49
        $logged_in_user = Koha::Patrons->find( $userenv->{number} );
50
        $can_manage_background_jobs = $logged_in_user->has_permission(
51
            { parameters => 'manage_background_jobs' } );
52
    }
53
54
    return $can_manage_background_jobs
55
      ? $self->search( $params, $attributes )
56
      : $self->search( { borrowernumber => $logged_in_user->borrowernumber } )
57
      ->search( $params, $attributes );
58
}
59
32
=head3 _type
60
=head3 _type
33
61
34
=cut
62
=cut
(-)a/Koha/REST/V1/BackgroundJobs.pm (-15 / +2 lines)
Lines 35-58 sub list { Link Here
35
    my $c = shift->openapi->valid_input or return;
35
    my $c = shift->openapi->valid_input or return;
36
36
37
    return try {
37
    return try {
38
        my $patron = $c->stash('koha.user');
38
        my $background_jobs_set = Koha::BackgroundJobs->new;
39
39
        my $background_jobs     = $c->objects->search($background_jobs_set);
40
        my $can_manage_background_jobs =
41
          $patron->has_permission( { parameters => 'manage_background_jobs' } );
42
43
        my $background_jobs_set =
44
          $can_manage_background_jobs
45
          ? Koha::BackgroundJobs->new
46
          : Koha::BackgroundJobs->search(
47
            { borrowernumber => $patron->borrowernumber } );
48
49
        my $background_jobs = $c->objects->search( $background_jobs_set );
50
        return $c->render( status => 200, openapi => $background_jobs );
40
        return $c->render( status => 200, openapi => $background_jobs );
51
    }
41
    }
52
    catch {
42
    catch {
53
        $c->unhandled_exception($_);
43
        $c->unhandled_exception($_);
54
    };
44
    };
55
56
}
45
}
57
46
58
sub get {
47
sub get {
Lines 90-94 sub get { Link Here
90
    };
79
    };
91
}
80
}
92
81
93
94
1;
82
1;
95
- 

Return to bug 30982