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

(-)a/admin/background_jobs.pl (-7 / +21 lines)
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
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt (-1 / +7 lines)
Lines 165-171 Link Here
165
                <div class="row">
165
                <div class="row">
166
                    <div class="col-sm-12">
166
                    <div class="col-sm-12">
167
                        [%# Following statement must be in one line for translatability %]
167
                        [%# Following statement must be in one line for translatability %]
168
                        [% IF ( CAN_user_tools_moderate_comments  && pendingcomments ) || ( CAN_user_tools_moderate_tags && pendingtags ) || ( CAN_user_borrowers_edit_borrowers && pending_borrower_modifications ) || ( CAN_user_suggestions_suggestions_manage && pendingsuggestions ) || ( CAN_user_borrowers_edit_borrowers && pending_discharge_requests ) || pending_article_requests || ( Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes && pending_checkout_notes.count ) || ( Koha.Preference('OPACReportProblem') && CAN_user_problem_reports && pending_problem_reports.count ) %]
168
                        [% IF ( CAN_user_tools_moderate_comments  && pendingcomments ) || ( CAN_user_tools_moderate_tags && pendingtags ) || ( CAN_user_borrowers_edit_borrowers && pending_borrower_modifications ) || ( CAN_user_suggestions_suggestions_manage && pendingsuggestions ) || ( CAN_user_borrowers_edit_borrowers && pending_discharge_requests ) || pending_article_requests || ( Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes && pending_checkout_notes.count ) || ( Koha.Preference('OPACReportProblem') && CAN_user_problem_reports && pending_problem_reports.count ) || already_ran_jobs %]
169
                            <div id="area-pending">
169
                            <div id="area-pending">
170
                                [% IF pending_article_requests %]
170
                                [% IF pending_article_requests %]
171
                                <div class="pending-info" id="article_requests_pending">
171
                                <div class="pending-info" id="article_requests_pending">
Lines 234-239 Link Here
234
                                    </div>
234
                                    </div>
235
                                [% END %]
235
                                [% END %]
236
236
237
                                [% IF already_ran_jobs %]
238
                                    <div class="pending-info" id="background_jobs">
239
                                        <a href="/cgi-bin/koha/admin/background_jobs.pl">Access your background jobs</a>
240
                                    </div>
241
                                [% END %]
242
237
                            </div>
243
                            </div>
238
244
239
                        [% END %]
245
                        [% END %]
(-)a/mainpage.pl (-1 / +9 lines)
Lines 33-38 use Koha::ArticleRequests; Link Here
33
use Koha::ProblemReports;
33
use Koha::ProblemReports;
34
use Koha::Quotes;
34
use Koha::Quotes;
35
use Koha::Suggestions;
35
use Koha::Suggestions;
36
use Koha::BackgroundJobs;
36
37
37
my $query = CGI->new;
38
my $query = CGI->new;
38
39
Lines 45-50 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( Link Here
45
    }
46
    }
46
);
47
);
47
48
49
my $logged_in_user = Koha::Patrons->find($loggedinuser);
50
48
my $homebranch;
51
my $homebranch;
49
if (C4::Context->userenv) {
52
if (C4::Context->userenv) {
50
    $homebranch = C4::Context->userenv->{'branch'};
53
    $homebranch = C4::Context->userenv->{'branch'};
Lines 99-104 my $pending_article_requests = Koha::ArticleRequests->search_limited( Link Here
99
)->count;
102
)->count;
100
my $pending_problem_reports = Koha::ProblemReports->search({ status => 'New' });
103
my $pending_problem_reports = Koha::ProblemReports->search({ status => 'New' });
101
104
105
unless ( $logged_in_user->has_permission( { parameters => 'manage_background_jobs' } ) ) {
106
    my $already_ran_jobs = Koha::BackgroundJobs->search(
107
        { borrowernumber => $logged_in_user->borrowernumber } )->count ? 1 : 0;
108
    $template->param( already_ran_jobs => $already_ran_jobs );
109
}
110
102
$template->param(
111
$template->param(
103
    pendingcomments                => $pendingcomments,
112
    pendingcomments                => $pendingcomments,
104
    pendingtags                    => $pendingtags,
113
    pendingtags                    => $pendingtags,
105
- 

Return to bug 29020