Browse Source

Bug 29020: Add link on the mainpage for users without admin access

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.11.x
Jonathan Druart 2 months ago
parent
commit
fde5d5f701
  1. 28
      admin/background_jobs.pl
  2. 8
      koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt
  3. 9
      mainpage.pl

28
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 );
}

8
koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt

@ -165,7 +165,7 @@
<div class="row">
<div class="col-sm-12">
[%# 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 %]
<div id="area-pending">
[% IF pending_article_requests %]
<div class="pending-info" id="article_requests_pending">
@ -234,6 +234,12 @@
</div>
[% END %]
[% IF already_ran_jobs %]
<div class="pending-info" id="background_jobs">
<a href="/cgi-bin/koha/admin/background_jobs.pl">Access your background jobs</a>
</div>
[% END %]
</div>
[% END %]

9
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,

Loading…
Cancel
Save