Koha-clms/t/db_dependent/Koha
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
..
Account Bug 40255: (QA follow-up) Adjust test count 2026-04-17 09:18:15 -06:00
Acquisition Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
Auth Bug 33782: (QA follow-up) Fix qa issues 2026-02-10 10:51:33 -07:00
BackgroundJob Bug 40846: Improve handling of ignored records 2026-01-21 07:44:20 -07:00
BackgroundJobs Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Biblio Bug 41031: Fix the subtest check_fixed_length in MARC21.t 2025-12-01 12:53:43 -07:00
Cash Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Charges Bug 36506: Adjust existing tests and test builder 2026-02-27 11:38:47 -07:00
Checkouts Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
CirculationRules Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Club Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Config Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Database Bug 42103: (follow-up) Fix failing test 2026-05-06 09:52:19 -06:00
ERM Bug 39438: (follow-up) Remove agreement_id from periods before comparing to result 2026-02-06 07:21:01 -07:00
Edifact Bug 42010: Escape EDIFACT special characters in BGM purchase order number 2026-03-24 15:35:34 +01:00
File Bug 40811: (follow-up) Fix list context bug and add comprehensive tests 2026-01-21 15:28:17 -07:00
Filter Bug 38136: Refactor database translations (alternative) 2026-04-15 11:37:14 -06:00
ILL Bug 40504: Add tests 2026-03-26 14:21:23 +01:00
Import Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Item Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Items Bug 41884: Adjust tests 2026-04-15 09:14:49 -06:00
Library Bug 28530: Fix tests 2026-02-10 10:51:38 -07:00
Middleware Bug 38365: Fix Koha/Middleware/ContentSecurityPolicy.t 2026-03-17 09:38:50 +01:00
Notice Bug 35267: (follow-up) More comprehensive and db agnostic tests 2026-04-17 09:18:09 -06:00
OAI/Server Bug 37713: (QA follow-up) Add unit tests 2026-04-17 09:18:04 -06:00
Object Bug 32370: (QA follow-up) Add https to license url, use Test::NoWarnings 2026-01-22 10:02:26 -07:00
Objects Bug 35451: Fix test data 2025-11-07 10:54:06 -07:00
Old Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Patron Bug 40136: (follow-up) Fix extended_attributes logaction to populate diff column 2026-03-23 10:42:26 +01:00
Patrons Bug 41145: Add unit test coverage for stopping duplicated borrowerslog logging due to extended patron attributes being deleted on import 2025-12-17 13:24:26 -07:00
Plugins Bug 42098: EDIFACT edi_cron.pl runs disabled plugins due to bug in Koha::Plugins::Handler::run 2026-03-19 10:20:35 +00:00
Policy Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Preservation Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
REST Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
SIP2 Bug 41311: (QA follow-up) Fix broken unit test 2026-04-24 11:43:25 -06:00
SMTP Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Schema/Util Bug 19871: (QA follow-up) Remove safe_do, use translate_exception directly 2026-04-23 16:04:19 -06:00
SearchEngine Bug 40658: Use local-number__sort and not local-number directly 2026-05-05 13:41:58 -06:00
Subscription Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Tags Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Template/Plugin Bug 38136: Refactor database translations (alternative) 2026-04-15 11:37:14 -06:00
Ticket Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
UI/Form/Builder Bug 38365: Require a non-empty nonce in FrameworkPlugin.t 2026-03-17 09:38:49 +01:00
XSLT Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Z3950Responder Bug 40680: Fix t tests 2025-12-01 08:34:01 -07:00
Account.t Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
ActionLogs.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
AdditionalContents.t Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
AdditionalField.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
ApiKey.t Bug 20638: Improve ApiKey logging to use structured data 2026-01-22 09:26:02 -07:00
ArticleRequest.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
ArticleRequests.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Authorities.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Authority.t Bug 41843: Gracefully handle XML errors during authority deletion 2026-04-10 09:48:12 -06:00
BackgroundJob.t Bug 40943: Fix Koha/BackgroundJob.t 2025-11-04 07:15:11 -07:00
BackgroundJobs.t Bug 42394: (QA follow-up) Clean up test 2026-04-17 09:17:59 -06:00
Biblio.t Bug 42188: (follow-up) Skip JSON payload in info column on ADD 2026-05-05 13:42:02 -06:00
BiblioFrameworks.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Biblios.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Booking.t Bug 41887: Skip clash detection on terminal status transition 2026-02-26 09:04:22 -07:00
Bookings.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Calendar.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Checkout.t Bug 35612: Add unit test for Koha::Checkout->branch_for_fee_context 2026-02-27 11:38:50 -07:00
Checkouts.t Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
CirculationRules.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Cities.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
ClassSortRules.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
ClassSources.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
ClassSplitRules.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Course.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Courses.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
CoverImages.t Bug 33857: Avoid increasing file size while uploading image 2026-03-24 09:55:52 +01:00
CsvProfiles.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
CurbsidePickups.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Database.t Bug 38384: Refactor plugin loading to use lightweight Koha::Plugins::Loader 2026-02-25 07:36:59 -07:00
Desks.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
EDI.t Bug 40391: Add unit tests for GIR:LSL support in EDI 2026-01-12 10:53:29 -07:00
Encryption.t Bug 40444: Add a test to ensure all Perl test files use Test::NoWarnings 2025-07-28 16:26:36 -06:00
Hold.t Bug 41954: Update existing tests 2026-04-16 15:54:11 -06:00
Holds.t Bug 23269: (RM follow-up): Tidy 2026-03-21 20:28:15 +00:00
ImportBatch.t Bug 41036: (QA follow-up) use nowarnings 2026-02-26 09:04:15 -07:00
Installer.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Item.t Bug 38136: Refactor database translations (alternative) 2026-04-15 11:37:14 -06:00
ItemTypes.t Bug 38136: Refactor database translations (alternative) 2026-04-15 11:37:14 -06:00
Items.t Bug 36506: Adjust existing tests and test builder 2026-02-27 11:38:47 -07:00
KeyboardShortcuts.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Libraries.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Library.t Bug 39482: (follow-up) Adjust tests 2025-12-29 09:56:17 -07:00
MarcOrder.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
MarcSubfieldStructures.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Notice_Util.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Notices.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
OAIHarvester.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
OAIServers.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
OAI_Sets.t Bug 41462: (QA follow-up) Add basic unit tests and koha_object_class methods 2026-03-26 14:21:26 +01:00
Object.t Bug 35380: Unit tests 2026-03-26 09:50:09 +01:00
Objects.t Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
Old.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Patron.t Bug 41956: Remove visual_hold_group_id 2026-05-06 15:21:00 -06:00
Patron_generate_userid.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Patrons.t Bug 39748: (follow-up) Update number of tests 2026-04-23 09:25:02 -06:00
Pseudonymization.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
PseudonymizedTransaction.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Quotes.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Ratings.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Recall.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Recalls.t Bug 39985: Set items.onloan when recall adjusts checkout due date 2025-12-01 08:34:05 -07:00
RecordSource.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Reports.t Bug 41919: Limit number of current reports a single user can run simultaneously 2026-05-07 07:56:21 -06:00
Reviews.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
SMS_Providers.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
SearchField.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
SearchFilters.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Session.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
SharedContent.t Bug 39745: Fix wrong system preference 'language' in test suite (mock_preference) 2026-01-26 14:36:44 -07:00
Statistic.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Statistics.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Subscription.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Suggestion.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Suggestions.t Bug 42030: Populate diff column for suggestion CREATE/MODIFY/DELETE logs 2026-05-01 11:04:22 -06:00
Tags.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Ticket.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Virtualshelf.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Virtualshelves.t Bug 39145: (follow-up) Tidy files 2025-09-29 14:02:26 -06:00
Z3950Servers.t Bug 40841: Add Z39.50 library limits 2026-03-26 14:21:27 +01:00