Lines 29-51
my $input = CGI->new;
Link Here
|
29 |
my $op = $input->param('op') || 'list'; |
29 |
my $op = $input->param('op') || 'list'; |
30 |
my @messages; |
30 |
my @messages; |
31 |
|
31 |
|
32 |
# The "view" view should be accessible for the user who create this job. |
|
|
33 |
my $flags_required = $op ne 'view' ? { parameters => 'manage_background_jobs' } : undef; |
34 |
|
35 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
32 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
36 |
{ |
33 |
{ |
37 |
template_name => "admin/background_jobs.tt", |
34 |
template_name => "admin/background_jobs.tt", |
38 |
query => $input, |
35 |
query => $input, |
39 |
type => "intranet", |
36 |
type => "intranet", |
40 |
flagsrequired => $flags_required, |
37 |
flagsrequired => { catalogue => 1 }, |
41 |
} |
38 |
} |
42 |
); |
39 |
); |
43 |
|
40 |
|
|
|
41 |
my $logged_in_user = Koha::Patrons->find($loggedinuser); |
42 |
my $can_manage_background_jobs = |
43 |
$logged_in_user->has_permission( { parameters => 'manage_background_jobs' } ); |
44 |
|
44 |
if ( $op eq 'view' ) { |
45 |
if ( $op eq 'view' ) { |
45 |
my $id = $input->param('id'); |
46 |
my $id = $input->param('id'); |
46 |
if ( my $job = Koha::BackgroundJobs->find($id) ) { |
47 |
if ( my $job = Koha::BackgroundJobs->find($id) ) { |
47 |
if ( $job->borrowernumber ne $loggedinuser |
48 |
if ( $job->borrowernumber ne $loggedinuser |
48 |
&& !Koha::Patrons->find($loggedinuser)->has_permission( { parameters => 'manage_background_jobs' } ) ) |
49 |
&& !$can_manage_background_jobs ) |
49 |
{ |
50 |
{ |
50 |
push @messages, { code => 'cannot_view_job' }; |
51 |
push @messages, { code => 'cannot_view_job' }; |
51 |
} |
52 |
} |
Lines 61-75
if ( $op eq 'view' ) {
Link Here
|
61 |
|
62 |
|
62 |
if ( $op eq 'cancel' ) { |
63 |
if ( $op eq 'cancel' ) { |
63 |
my $id = $input->param('id'); |
64 |
my $id = $input->param('id'); |
64 |
if ( my $job = Koha::BackgroundJobs->find($id) ) { # FIXME Make sure logged in user can cancel this job |
65 |
my $job = Koha::BackgroundJobs->find($id); |
|
|
66 |
if ( $can_manage_background_jobs |
67 |
|| $job->borrowernumber eq $logged_in_user->borrowernumber ) |
68 |
{ |
65 |
$job->cancel; |
69 |
$job->cancel; |
66 |
} |
70 |
} |
|
|
71 |
else { |
72 |
push @messages, { code => 'cannot_cancel_job' }; |
73 |
} |
67 |
$op = 'list'; |
74 |
$op = 'list'; |
68 |
} |
75 |
} |
69 |
|
76 |
|
70 |
|
77 |
|
71 |
if ( $op eq 'list' ) { |
78 |
if ( $op eq 'list' ) { |
72 |
my $jobs = Koha::BackgroundJobs->search({}, { order_by => { -desc => 'enqueued_on' }}); |
79 |
my $jobs = |
|
|
80 |
$can_manage_background_jobs |
81 |
? Koha::BackgroundJobs->search( {}, |
82 |
{ order_by => { -desc => 'enqueued_on' } } ) |
83 |
: Koha::BackgroundJobs->search( |
84 |
{ borrowernumber => $logged_in_user->borrowernumber }, |
85 |
{ order_by => { -desc => 'enqueued_on' } } |
86 |
); |
73 |
$template->param( jobs => $jobs ); |
87 |
$template->param( jobs => $jobs ); |
74 |
} |
88 |
} |
75 |
|
89 |
|