From a23c01d26a66572de460d148ef63eba9e55c34a2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 31 Jul 2023 17:51:28 +0200 Subject: [PATCH] Bug 30708: Rebase - Use a dedicated 'config' endpoint To retrieve the sysprefs, instead of using the svc script. See bug 33606. Signed-off-by: Laurence Rault --- Koha/REST/V1/Preservation.pm | 54 +++++++++++++++++++ .../definitions/preservation_config.yaml | 7 +++ api/v1/swagger/paths/preservation_config.yaml | 38 +++++++++++++ api/v1/swagger/swagger.yaml | 4 ++ .../js/vue/components/Preservation/Main.vue | 52 +++++++----------- .../vue/components/Preservation/Settings.vue | 20 ++++--- .../components/Preservation/TrainsFormAdd.vue | 7 +-- .../components/Preservation/WaitingList.vue | 9 ++-- .../js/vue/fetch/preservation-api-client.js | 9 ++++ .../prog/js/vue/modules/preservation.ts | 6 ++- .../prog/js/vue/stores/preservation.js | 9 ++-- 11 files changed, 163 insertions(+), 52 deletions(-) create mode 100644 Koha/REST/V1/Preservation.pm create mode 100644 api/v1/swagger/definitions/preservation_config.yaml create mode 100644 api/v1/swagger/paths/preservation_config.yaml diff --git a/Koha/REST/V1/Preservation.pm b/Koha/REST/V1/Preservation.pm new file mode 100644 index 00000000000..994f9eb583b --- /dev/null +++ b/Koha/REST/V1/Preservation.pm @@ -0,0 +1,54 @@ +package Koha::REST::V1::Preservation; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Mojo::Base 'Mojolicious::Controller'; + +use Koha::Patrons; + +use Try::Tiny qw( catch try ); + +=head1 NAME + +Koha::REST::V1::Preservation + +=head1 API + +=head2 Class methods + +=head3 config + +Return the configuration options needed for the Preservation Vue app + +=cut + +sub config { + my $c = shift->openapi->valid_input or return; + return $c->render( + status => 200, + openapi => { + settings => { + enabled => C4::Context->preference('PreservationModule'), + not_for_loan_waiting_list_in => C4::Context->preference('PreservationNotForLoanWaitingListIn'), + not_for_loan_default_train_in => C4::Context->preference('PreservationNotForLoanDefaultTrainIn'), + }, + }, + ); +} + +1; diff --git a/api/v1/swagger/definitions/preservation_config.yaml b/api/v1/swagger/definitions/preservation_config.yaml new file mode 100644 index 00000000000..c88e1bd0bdf --- /dev/null +++ b/api/v1/swagger/definitions/preservation_config.yaml @@ -0,0 +1,7 @@ +--- +type: object +properties: + settings: + type: object + description: List of sysprefs used for the Preservation module +additionalProperties: false diff --git a/api/v1/swagger/paths/preservation_config.yaml b/api/v1/swagger/paths/preservation_config.yaml new file mode 100644 index 00000000000..59cd7d4a4d3 --- /dev/null +++ b/api/v1/swagger/paths/preservation_config.yaml @@ -0,0 +1,38 @@ +--- +/preservation/config: + get: + x-mojo-to: Preservation#config + operationId: getPreservationconfig + description: This resource returns a list of options needed for the Preservation Vue app. EXPERIMENTAL - DO NOT RELY on this, it is subject to change! + summary: get the Preservation config + tags: + - Preservation + produces: + - application/json + responses: + 200: + description: The Preservation module config + schema: + $ref: "../swagger.yaml#/definitions/preservation_config" + 400: + description: Bad request + schema: + $ref: "../swagger.yaml#/definitions/error" + 403: + description: Access forbidden + 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: + preservation: 1 diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index cc18bdf095b..acd886815f3 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -90,6 +90,8 @@ definitions: $ref: ./definitions/patron_balance.yaml patron_extended_attribute: $ref: ./definitions/patron_extended_attribute.yaml + preservation_config: + $ref: ./definitions/preservation_config.yaml preservation_train: $ref: ./definitions/preservation_train.yaml preservation_processing: @@ -321,6 +323,8 @@ paths: $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password" "/patrons/{patron_id}/password/expiration_date": $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date" + /preservation/config: + $ref: ./paths/preservation_config.yaml#/~1preservation~1config /preservation/trains: $ref: ./paths/preservation_trains.yaml#/~1preservation~1trains "/preservation/trains/{train_id}": diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/Main.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/Main.vue index b5bcc9a7e8b..217bc513936 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/Main.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/Main.vue @@ -1,5 +1,5 @@