Koha-clms/Koha/Exceptions
Martin Renvoize 6f62a8fe30
Bug 41919: Limit number of current reports a single user can run simultaneously
Building on bug 41918, it would be good to limit the number of reports
a given user can run at a time. This control is config-file based as
it is tied to the server resources provided by the administrator.

Adds a new koha-conf.xml option total_running_reports_per_user_limit
(0 = disabled). When the configured limit is reached, the user is told
"You have too many reports running at the moment. Please wait for some
of them to finish before running this report again."

Note on implementation: the original patch on bz (attachment 198034)
performed a second pre-flight Koha::Reports->running call in
reports/guided_reports.pl. The bug 41918 QA follow-ups already pushed
the duplicate-running guard into Koha::Report::prep_report so it would
fire across the staff UI, svc/report and opac/svc/report. This patch
extends that same model-layer architecture rather than reintroducing
controller-layer enforcement:

- New Koha::Exceptions::Report::TotalRunning subclass of
  Koha::Exceptions::Report.
- prep_report now performs a second check after the duplicate one and
  throws TotalRunning when the user has total_running_reports_per_user_limit
  reports of any kind already in flight.
- All three callers (guided_reports.pl, svc/report, opac/svc/report)
  catch the new exception alongside DuplicateRunning, mapping it to a
  new template error key total_running_reports_limit_exceeded for the
  staff UI and a JSON {error: total_running_reports_limit_exceeded}
  with HTTP 429 for the JSON endpoints.

Test Plan:
1) Set total_running_reports_per_user_limit to 3 in your koha-conf.xml.
2) Create 3 long-running reports like:
   SELECT COUNT(*) FROM items i1 JOIN items i2 JOIN items i3 JOIN items i4 JOIN items i5 JOIN items i6
3) Run each report in turn by opening a new tab, browsing to the
   reports module, and choosing to run that report.
4) Note the first three continue to run, but a fourth attempt gives
   the new "too many reports running" alert in the staff UI.
5) Repeat against /cgi-bin/koha/svc/report?id=N and confirm an HTTP
   429 response with JSON {error: total_running_reports_limit_exceeded}.
6) Set total_running_reports_per_user_limit back to 0 and confirm
   normal behaviour resumes.
7) prove t/db_dependent/Koha/Reports.t -> 13 tests pass, including a
   new subtest for TotalRunning.

Signed-off-by: Alex Carver [Acerock7] <alex@rcls.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-05-07 07:56:21 -06:00
..
Acquisition Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Checkouts Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
ERM/EUsage Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Item Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Patron Bug 39014: (follow-up) Refactoring and renaming to can_be_guaranteed_by 2025-12-30 07:49:05 -07:00
Account.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
ApiKey.pm Bug 20638: Add revoke() and activate() methods to Koha::ApiKey 2026-01-22 09:26:00 -07:00
ArticleRequest.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Auth.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Authentication.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
Authorization.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
BackgroundJob.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Booking.pm Bug 29002: Add bookings objects and API classes 2023-11-03 12:04:07 -03:00
Calendar.pm Bug 27249: Add missing POD for Koha::Exceptions::Calendar 2023-10-17 14:45:33 -03:00
Checkin.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Checkout.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
CirculationRule.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
ClubHold.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
Config.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
CurbsidePickup.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Elasticsearch.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Hold.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
HoldGroup.pm Bug 40517: (follow-up) Fix GNU license links 2025-10-29 11:50:12 -06:00
Ill.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Library.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
MarcOverlayRule.pm Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Metadata.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Object.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Password.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Patron.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
Plugin.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Preservation.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
REST.pm Bug 28907: Add REST exceptions for public routes auth 2025-03-06 13:54:29 +01:00
Report.pm Bug 41919: Limit number of current reports a single user can run simultaneously 2026-05-07 07:56:21 -06:00
Suggestion.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
SysPref.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Token.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
TransferLimit.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Virtualshelf.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
XSLT.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00