[Bug 42720] New: Add REST API equivalents for svc/report and opac/svc/report
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42720 Bug ID: 42720 Summary: Add REST API equivalents for svc/report and opac/svc/report Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: kyle@bywatersolutions.com QA Contact: testopia@bugs.koha-community.org CC: tomascohen@gmail.com We should have equivalent functionality as svc/report in the REST API. Perhaps some time in the future we could deprecate the old version. Having a REST equivalent would come with better better authentication, documentation, http responses ( somewhat fixed by bug 42596 ) and other things. It could have pagination for example. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42720 Kyle M Hall (khall) <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |42596 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42596 [Bug 42596] Add ability for reports APIs ( svc/report, opac/svc/report ) to run reports as background jobs -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42720 Kyle M Hall (khall) <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |kyle@bywatersolutions.com |ity.org | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42720 Kyle M Hall (khall) <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42720 --- Comment #1 from Kyle M Hall (khall) <kyle@bywatersolutions.com> --- Created attachment 202840 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202840&action=edit Bug 42720: Add REST API endpoints to run a saved report and fetch its results We should have equivalent functionality to svc/report in the REST API. This patch adds the staff endpoints. POST /reports/{report_id}/run runs a saved SQL report. A foreground run returns the rows synchronously, capped by SvcMaxReportRows, in the same shape as svc/report ( positional arrays, or column-keyed objects when annotated is set ). A background run enqueues a Koha::BackgroundJob::RunReport and returns 202 Accepted with a results URL to poll. GET /reports/job/{job_id}/results is the deferred twin of a foreground run: it returns the rows once the job has finished, 202 while the job is still queued or running, and the same 400 a foreground run gives if the job failed. There is deliberately no separate status endpoint, the generic GET /jobs/{job_id} already provides job status, so adding one under /reports would just duplicate it. Running in the foreground needs execute_reports_foreground, and in the background execute_reports_background. The logic is shared so the public endpoints added next can reuse it via the is_public stash flag. Test Plan: 1) Apply this patch 2) Restart all the things! 3) Enable the RESTBasicAuth system preference 4) Create a SQL report, e.g. SELECT 1 AS one, 2 AS two 5) curl -X POST http://localhost:8081/api/v1/reports/<id>/run \ -u koha:koha -H 'Content-Type: application/json' \ -d '{"run_type":"foreground"}' 6) Note the rows are returned as [[1,2]]! 7) Repeat with {"run_type":"foreground","annotated":true} 8) Note the rows are now keyed by column name! 9) Repeat with {"run_type":"background"} 10) Note you get a 202 with a job_id and a results_url! 11) curl the results_url 12) Note you get the rows once the job finishes! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42720 --- Comment #2 from Kyle M Hall (khall) <kyle@bywatersolutions.com> --- Created attachment 202841 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202841&action=edit Bug 42720: Add public REST API endpoints for running and fetching public reports This patch adds the OPAC equivalents of the staff reports endpoints, under /public, matching what opac/svc/report does today. They reuse the same controller as the staff endpoints, keying off the is_public stash flag the API authentication guard sets for /public routes, so the two sides expose an identical interface and differ only in the path. POST /public/reports/{report_id}/run runs a report that is flagged public. GET /public/reports/job/{job_id}/results fetches a background run's results, but only for jobs whose report is public. A single endpoint can't serve both the staff and public cases because the guard decides public vs staff from the /public path prefix before the controller knows which report was requested, so a sibling /public route is the right shape. Test Plan: 1) Apply this patch 2) Restart all the things! 3) Enable the RESTPublicAPI and RESTPublicAnonymousRequests system preferences 4) Create a SQL report and mark it public, e.g. SELECT 1 AS one, 2 AS two 5) curl -X POST http://localhost:8080/api/v1/public/reports/<id>/run \ -H 'Content-Type: application/json' -d '{"run_type":"foreground"}' 6) Note the rows are returned without any authentication! 7) Mark the report as not public 8) Repeat step 5 9) Note you now get a 404! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42720 --- Comment #3 from Kyle M Hall (khall) <kyle@bywatersolutions.com> --- Created attachment 202842 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202842&action=edit Bug 42720: Add unit tests Patch from commit 84ae8d3 -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org