Bug 41918: (QA follow-up) Catch DuplicateRunning in op=export path
The CSV/tab export branch (op=export) of reports/guided_reports.pl calls Koha::Report::prep_report just like the op=run branch and the two svc/report endpoints, but unlike the others it had no eval/catch around the call. The QA follow-ups that pushed enforcement into the model layer therefore left this one path emitting a 500 (uncaught Koha::Exceptions::Report::DuplicateRunning) when the configured duplicate-running limit is exceeded. Wrap the call in the same pattern as svc/report: on DuplicateRunning return HTTP 429 Too Many Requests with a plain-text body explaining the situation. Plain text rather than the staff template because op=export sets file-download headers and the user is expecting either the file or an error - we don't have a sensible way to fall back into the report-run template from this branch. The CLI runners (misc/cronjobs/runreport.pl, misc/export_records.pl) still bypass prep_report and therefore the limit, which is intended: scheduled / batch jobs should not be subject to user-quota enforcement. Test plan: 1) Set duplicate_running_reports_per_user_limit=1 in koha-conf.xml, restart_all. 2) Start a long-running report from the staff UI. 3) While it is running, navigate to op=export with the same report id (eg. via the "Export" button). 4) Before the patch: 500 with a stack trace in the logs. After the patch: 429 with body "This report is already running. Please wait for it to finish before running it again." 5) Set the limit back to 0 and confirm exports work normally again. Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
63af0dd4fd
commit
4227119b63
|
|
@ -667,7 +667,18 @@ if ( !$op ) {
|
|||
$reportname ? "$report_id-$reportname-reportresults.$format" : "$report_id-reportresults.$format";
|
||||
my $scrubber = C4::Scrubber->new();
|
||||
|
||||
( $sql, undef ) = $report->prep_report( \@param_names, \@sql_params, { export => 1 } );
|
||||
eval { ( $sql, undef ) = $report->prep_report( \@param_names, \@sql_params, { export => 1 } ); };
|
||||
if ( my $e = $@ ) {
|
||||
if ( ref($e) eq 'Koha::Exceptions::Report::DuplicateRunning' ) {
|
||||
print $input->header(
|
||||
-status => '429 Too Many Requests',
|
||||
-type => 'text/plain; charset=UTF-8',
|
||||
);
|
||||
print "This report is already running. Please wait for it to finish before running it again.\n";
|
||||
exit;
|
||||
}
|
||||
die $e;
|
||||
}
|
||||
my ( $sth, $q_errors ) = execute_query( { sql => $sql, report_id => $report_id } );
|
||||
unless ( $q_errors and @$q_errors ) {
|
||||
my ( $type, $content );
|
||||
|
|
|
|||
Loading…
Reference in New Issue