Jonathan Druart
eb2dfad0d1
Bug 30982: REST API specs Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: (QA follow-up) Double quoting and console.log This patch fixes the issues highlighted by the QA script; We use double quotes for translatable strings in JS and remove an errant console.log call. Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: Add tests and implement GET /background_jobs/$id Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: Make code more re-usable Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: Add 'context' to the REST API specs context has been added by bug 30889 Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: Add Koha::BackgroundJobs->filter_by_current Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: API tweaks This patch makes the following changes to the 'background_jobs' API: * We now call them 'jobs' * Removed deprecated query parameter definitions * Added only_current query parameter * Controller gets adapted to use $rs->filter_by_current when only_current is passed Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: Adapt table to new API spec Disclaimer: this patch is highly opinionated :-D When I started looking at this patch I felt like the two tables (current/past jobs) implemented on bug 30462 was the way to go. In order to make this patches apply after it I had to redo all the things. Or most of them. But I decided to keep the idea of filtering out completed tasks, not just having the option to display 'the last hour' tasks. For the task I added some required helper methods and the relevant tests as well. So a behavior change. Hope you all agree with it. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: Rename 'Background Jobs' => 'Jobs' Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: (QA follow-up) Resolve pod warning Empty section in previous paragraph at line 32 in file Koha/BackgroundJobs.pm Test plan: Run podchecker again on this module. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: (QA follow-up) Spelling [1] Correct: BackgrounJob [2] If should filter out not current jobs => Had a hard time reading that one until I replaced if by it. => Decided to rephrase it in a more positive way. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: (QA follow-up) Remove redundancy from template The template now contains two lists for both status and type: a TT list and a JS list. The type list already proves that redundancy leads to bugs. We miss three types at one side: Unknown job type 'stage_marc_for_import' Unknown job type 'marc_import_commit_batch' Unknown job type 'marc_import_revert_batch' This patch removes the TT list. And gets the status and type via an additional js call. For that reason I hide the fieldset until document ready. This can be improved later when needed. Test plan: Look at status and type on both job list and detail view. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 30982: (QA follow-up) No userenv, no jobs + # Assume permission if context has no user + my $can_manage_background_jobs = 1; => This felt a bit unsafe. Test plan: Try interface for jobs. Call API with cookie. Call API with OAuth. Run t/db_dependent/Koha/BackgroundJobs.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
85 lines
2.4 KiB
Perl
Executable file
85 lines
2.4 KiB
Perl
Executable file
#! /usr/bin/perl
|
|
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
use Modern::Perl;
|
|
use CGI qw ( -utf8 );
|
|
|
|
use C4::Context;
|
|
use Koha::DateUtils qw( dt_from_string );
|
|
use C4::Auth qw( get_template_and_user );
|
|
use C4::Output qw( output_html_with_http_headers );
|
|
|
|
use Koha::BackgroundJobs;
|
|
use Koha::Virtualshelves;
|
|
|
|
my $input = CGI->new;
|
|
my $op = $input->param('op') || 'list';
|
|
my @messages;
|
|
|
|
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
|
|
{
|
|
template_name => "admin/background_jobs.tt",
|
|
query => $input,
|
|
type => "intranet",
|
|
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
|
|
&& !$can_manage_background_jobs )
|
|
{
|
|
push @messages, { code => 'cannot_view_job' };
|
|
}
|
|
else {
|
|
$template->param( job => $job, );
|
|
if ( $job->status ne 'new' ) {
|
|
my $report = $job->additional_report() || {};
|
|
$template->param( %$report );
|
|
}
|
|
}
|
|
} else {
|
|
$op = 'list';
|
|
}
|
|
}
|
|
|
|
if ( $op eq 'cancel' ) {
|
|
my $id = $input->param('id');
|
|
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';
|
|
}
|
|
|
|
$template->param(
|
|
messages => \@messages,
|
|
op => $op,
|
|
);
|
|
|
|
output_html_with_http_headers $input, $cookie, $template->output;
|