From 288e6c874cb026cd29207b052c064003d4d69e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20=E2=80=9Etadzik=E2=80=9D=20So=C5=9Bnierz?= Date: Thu, 6 Mar 2025 16:18:44 +0100 Subject: [PATCH] Bug 39600: Switch OPAC ILL request listing to server-side rendering This brings it technologically closer to intranet's ILL table and also enables pagination. Test plan: 1. In KTD, go to http://localhost:8081/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=master+switch and enable the ILL module 2. Run the following in koha-shell to populate the request list for user `koha`: perl -Mt::lib::TestBuilder -e ' my $builder = t::lib::TestBuilder->new; do { $builder->build_sample_ill_request({borrowernumber => 51}); } for (1..50); ' 3. Navigate to http://localhost:8080/cgi-bin/koha/opac-illrequests.pl, log in as `koha` as needed 4. Observe the new request list being paginated and server-side-sortable Sponsored-by: Wiko (https://www.wiko-berlin.de/) --- Koha/REST/V1/ILL/Requests.pm | 25 +++ api/v1/swagger/paths/patrons.yaml | 66 ++++++++ api/v1/swagger/swagger.yaml | 2 + .../bootstrap/en/includes/doc-head-close.inc | 1 + .../bootstrap/en/modules/opac-illrequests.tt | 146 +++++++++++++++--- opac/opac-illrequests.pl | 10 +- 6 files changed, 220 insertions(+), 30 deletions(-) diff --git a/Koha/REST/V1/ILL/Requests.pm b/Koha/REST/V1/ILL/Requests.pm index d024913c21..6291f7a358 100644 --- a/Koha/REST/V1/ILL/Requests.pm +++ b/Koha/REST/V1/ILL/Requests.pm @@ -58,6 +58,31 @@ sub list { }; } +sub patron_list { + my $c = shift->openapi->valid_input or return; + my $user = $c->stash('koha.user'); + + if ($user->borrowernumber != $c->param('patron_id') and !$user->is_superlibrarian) { + return $c->render( + status => 403, + openapi => { error => "Cannot lookup ILL requests for other users" } + ); + } + + return try { + my $reqs = $c->objects->search(Koha::ILL::Requests->search( + { borrowernumber => $c->param('patron_id') } + )); + + return $c->render( + status => 200, + openapi => $reqs, + ); + } catch { + $c->unhandled_exception($_); + }; +} + =head3 add Adds a new ILL request diff --git a/api/v1/swagger/paths/patrons.yaml b/api/v1/swagger/paths/patrons.yaml index 3cdc322445..dca5ce64be 100644 --- a/api/v1/swagger/paths/patrons.yaml +++ b/api/v1/swagger/paths/patrons.yaml @@ -662,3 +662,69 @@ x-koha-authorization: permissions: borrowers: delete_borrowers +"/patrons/{patron_id}/ill/requests": + get: + x-mojo-to: ILL::Requests#patron_list + operationId: getPatronIllRequests + tags: + - patrons + - ill_requests + summary: Get patron's ILL requests + parameters: + - $ref: "../swagger.yaml#/parameters/patron_id_pp" + - $ref: "../swagger.yaml#/parameters/page" + - $ref: "../swagger.yaml#/parameters/per_page" + - $ref: "../swagger.yaml#/parameters/match" + - $ref: "../swagger.yaml#/parameters/order_by" + - $ref: "../swagger.yaml#/parameters/q_param" + - $ref: "../swagger.yaml#/parameters/q_body" + - $ref: "../swagger.yaml#/parameters/request_id_header" + - name: x-koha-embed + in: header + required: false + description: Embed list sent as a request header + type: array + items: + type: string + enum: + - +strings + - extended_attributes + collectionFormat: csv + produces: + - application/json + responses: + "200": + description: A list of parton's ILL requests + schema: + type: array + items: + $ref: "../swagger.yaml#/definitions/ill_request" + "400": + description: Bad request + schema: + $ref: "../swagger.yaml#/definitions/error" + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + "404": + description: Patron not found + schema: + $ref: "../swagger.yaml#/definitions/error" + "500": + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: "../swagger.yaml#/definitions/error" + "503": + description: Under maintenance + schema: + $ref: "../swagger.yaml#/definitions/error" + x-koha-authorization: + permissions: {} diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 45a062c9bf..18e275965d 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -477,6 +477,8 @@ paths: $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date" "/patrons/{patron_id}/recalls": $ref: "./paths/patrons_recalls.yaml#/~1patrons~1{patron_id}~1recalls" + "/patrons/{patron_id}/ill/requests": + $ref: "./paths/patrons.yaml#/~1patrons~1{patron_id}~1ill~1requests" /patron_categories: $ref: ./paths/patron_categories.yaml#/~1patron_categories /preservation/config: diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc index f63e4f08d7..7c85b21f5f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc @@ -87,5 +87,6 @@ [% Asset.css("lib/fontawesome/css/fontawesome.min.css") | $raw %] [% Asset.css("lib/fontawesome/css/brands.min.css") | $raw %] [% Asset.css("lib/fontawesome/css/solid.min.css") | $raw %] +[% Asset.css("lib/datatables/datatables.min.css") | $raw %] [% PROCESS 'html_helpers.inc' %] [% KohaPlugins.get_plugins_opac_head | $raw %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt index b3a5bfad6c..60e58b10d0 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt @@ -146,23 +146,6 @@ - [% FOREACH request IN requests %] - [% status = request.status | html %] - [% type = request.get_type %] - - [% request.id | html %] - [% IF request.metadata.Author %][% request.metadata.Author | html %][% ELSE %]N/A[% END %] - [% IF request.metadata.Title %][% request.metadata.Title | html %][% ELSE %]N/A[% END %] - [% request.backend | html %] - [% IF type %][% type | html %][% ELSE %]N/A[% END %] - [% request.status_alias ? request.statusalias.lib_opac : request.capabilities.$status.name | html %] - [% request.placed | $KohaDates %] - [% request.updated | $KohaDates %] - - View - - - [% END %] [% ELSIF op == 'view' %] @@ -334,10 +317,131 @@ [% BLOCK jsinclude %] [% INCLUDE 'datatables.inc' %]