From 60544bcdc95f4b673b790a5b9369f296e7b29db8 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 Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart (cherry picked from commit fde5d5f7019728f56a8e16433e52c17dd021dffa) Signed-off-by: Andrew Fuerste-Henry --- 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 1835e831e4..6c39ae0bf9 100755 --- a/admin/background_jobs.pl +++ b/admin/background_jobs.pl @@ -31,24 +31,25 @@ 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 }, debug => 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' }; } @@ -70,15 +71,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 dc1ba8a534..5deb64c9b9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt @@ -149,7 +149,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 || all_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 ( 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 %]
@@ -218,6 +218,12 @@
[% END %] + [% IF already_ran_jobs %] + + [% END %] +
[% END %] diff --git a/mainpage.pl b/mainpage.pl index 183b5e0fcd..5ed35a1e7e 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'}; @@ -94,6 +97,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.39.5