From 286a00caaa8e6c3528d73488a9732473b7fb01c1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 8 Oct 2021 15:53:02 +0200 Subject: [PATCH] Bug 29020: Add link on the mainpage for users without admin access --- admin/background_jobs.pl | 28 ++++++++++++++----- .../prog/en/modules/intranet-main.tt | 8 +++++- mainpage.pl | 9 ++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/admin/background_jobs.pl b/admin/background_jobs.pl index 4dadcc1784..8a27c00a27 100755 --- a/admin/background_jobs.pl +++ b/admin/background_jobs.pl @@ -29,23 +29,24 @@ my $input = CGI->new; my $op = $input->param('op') || 'list'; my @messages; -# The "view" view should be accessible for the user who create this job. -my $flags_required = $op ne 'view' ? { parameters => 'manage_background_jobs' } : undef; - my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "admin/background_jobs.tt", query => $input, type => "intranet", - flagsrequired => $flags_required, + flagsrequired => { catalogue => 1 }, } ); +my $logged_in_user = Koha::Patrons->find($loggedinuser); +my $can_manage_background_jobs = + $logged_in_user->has_permission( { parameters => 'manage_background_jobs' } ); + if ( $op eq 'view' ) { my $id = $input->param('id'); if ( my $job = Koha::BackgroundJobs->find($id) ) { if ( $job->borrowernumber ne $loggedinuser - && !Koha::Patrons->find($loggedinuser)->has_permission( { parameters => 'manage_background_jobs' } ) ) + && !$can_manage_background_jobs ) { push @messages, { code => 'cannot_view_job' }; } @@ -61,15 +62,28 @@ if ( $op eq 'view' ) { if ( $op eq 'cancel' ) { my $id = $input->param('id'); - if ( my $job = Koha::BackgroundJobs->find($id) ) { # FIXME Make sure logged in user can cancel this job + my $job = Koha::BackgroundJobs->find($id); + if ( $can_manage_background_jobs + || $job->borrowernumber eq $logged_in_user->borrowernumber ) + { $job->cancel; } + else { + push @messages, { code => 'cannot_cancel_job' }; + } $op = 'list'; } if ( $op eq 'list' ) { - my $jobs = Koha::BackgroundJobs->search({}, { order_by => { -desc => 'enqueued_on' }}); + my $jobs = + $can_manage_background_jobs + ? Koha::BackgroundJobs->search( {}, + { order_by => { -desc => 'enqueued_on' } } ) + : Koha::BackgroundJobs->search( + { borrowernumber => $logged_in_user->borrowernumber }, + { order_by => { -desc => 'enqueued_on' } } + ); $template->param( jobs => $jobs ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt index b97e4d4801..cf7f0300e3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt @@ -165,7 +165,7 @@
[%# Following statement must be in one line for translatability %] - [% 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 ) %] + [% 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 %]
[% IF pending_article_requests %]
@@ -234,6 +234,12 @@
[% END %] + [% IF already_ran_jobs %] + + [% END %] +
[% END %] diff --git a/mainpage.pl b/mainpage.pl index ab7089c8f3..6972d39871 100755 --- a/mainpage.pl +++ b/mainpage.pl @@ -33,6 +33,7 @@ use Koha::ArticleRequests; use Koha::ProblemReports; use Koha::Quotes; use Koha::Suggestions; +use Koha::BackgroundJobs; my $query = CGI->new; @@ -45,6 +46,8 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( } ); +my $logged_in_user = Koha::Patrons->find($loggedinuser); + my $homebranch; if (C4::Context->userenv) { $homebranch = C4::Context->userenv->{'branch'}; @@ -99,6 +102,12 @@ my $pending_article_requests = Koha::ArticleRequests->search_limited( )->count; my $pending_problem_reports = Koha::ProblemReports->search({ status => 'New' }); +unless ( $logged_in_user->has_permission( { parameters => 'manage_background_jobs' } ) ) { + my $already_ran_jobs = Koha::BackgroundJobs->search( + { borrowernumber => $logged_in_user->borrowernumber } )->count ? 1 : 0; + $template->param( already_ran_jobs => $already_ran_jobs ); +} + $template->param( pendingcomments => $pendingcomments, pendingtags => $pendingtags, -- 2.17.1