From 17796faffc8a9298bde713d5589456b2c2b2c90f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 25 Apr 2023 15:56:51 +0200 Subject: [PATCH] Bug 33606: Add a erm/config route to retrieve the ERM config needed for the Vue app This could be extended later in bug 32968 to pass the permission of the logged in user. Signed-off-by: Pedro Amorim Signed-off-by: Marcel de Rooy (cherry picked from commit cda3c377a20c401ef9a755f24eb839d515a8af72) Signed-off-by: Fridolin Somers (cherry picked from commit 5078f9f4dff2788318bee544e00724fa2fbf1dad) Signed-off-by: Matt Blenkinsop --- Koha/REST/V1/ERM.pm | 22 ++ api/v1/swagger/definitions/erm_config.yaml | 7 + api/v1/swagger/paths/erm_config.yaml | 38 ++++ api/v1/swagger/swagger.yaml | 4 + .../ERM/EHoldingsEBSCOPackagesList.vue | 6 +- .../ERM/EHoldingsEBSCOTitlesList.vue | 6 +- .../prog/js/vue/components/ERM/Main.vue | 28 +-- .../prog/js/vue/fetch/erm-api-client.js | 9 + t/cypress/integration/ERM/Agreements_spec.ts | 199 ++++++++++++------ t/cypress/integration/ERM/Dialog_spec.ts | 11 +- t/cypress/integration/ERM/Licenses_spec.ts | 67 +++--- t/cypress/integration/ERM/Packages_spec.ts | 30 ++- t/cypress/integration/ERM/Searchbar_spec.ts | 28 +-- t/cypress/integration/ERM/Titles_spec.ts | 9 +- 14 files changed, 310 insertions(+), 154 deletions(-) create mode 100644 api/v1/swagger/definitions/erm_config.yaml create mode 100644 api/v1/swagger/paths/erm_config.yaml diff --git a/Koha/REST/V1/ERM.pm b/Koha/REST/V1/ERM.pm index 3f98a8e12d..26bcc18607 100644 --- a/Koha/REST/V1/ERM.pm +++ b/Koha/REST/V1/ERM.pm @@ -31,6 +31,28 @@ Koha::REST::V1::Acquisitions::Funds =head2 Class methods +=head3 config + +Return the configuration options needed for the ERM Vue app + +=cut + +sub config { + my $c = shift->openapi->valid_input or return; + return $c->render( + status => 200, + openapi => { + settings => { + ERMModule => C4::Context->preference('ERMModule'), + ERMProviders => [split ',', C4::Context->preference('ERMProviders')] + }, + #permissions => { + # erm => + #} + }, + ) +} + =head3 list_users Return the list of possible ERM' users diff --git a/api/v1/swagger/definitions/erm_config.yaml b/api/v1/swagger/definitions/erm_config.yaml new file mode 100644 index 0000000000..2e98077571 --- /dev/null +++ b/api/v1/swagger/definitions/erm_config.yaml @@ -0,0 +1,7 @@ +--- +type: object +properties: + settings: + type: object + description: List of sysprefs used for the ERM module +additionalProperties: false diff --git a/api/v1/swagger/paths/erm_config.yaml b/api/v1/swagger/paths/erm_config.yaml new file mode 100644 index 0000000000..d5a7d3933c --- /dev/null +++ b/api/v1/swagger/paths/erm_config.yaml @@ -0,0 +1,38 @@ +--- +/erm/config: + get: + x-mojo-to: ERM#config + operationId: getERMconfig + description: This resource returns a list of options needed for the ERM Vue app + summary: get the ERM config + tags: + - ERM + produces: + - application/json + responses: + 200: + description: The ERM config + schema: + $ref: "../swagger.yaml#/definitions/erm_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: + erm: 1 diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index ee473162ad..38bfb5dfff 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -32,6 +32,8 @@ definitions: $ref: ./definitions/city.yaml erm_agreement: $ref: ./definitions/erm_agreement.yaml + erm_config: + $ref: ./definitions/erm_config.yaml erm_eholdings_title: $ref: ./definitions/erm_eholdings_title.yaml erm_eholdings_package: @@ -195,6 +197,8 @@ paths: $ref: ./paths/config_smtp_servers.yaml#/~1config~1smtp_servers "/config/smtp_servers/{smtp_server_id}": $ref: "./paths/config_smtp_servers.yaml#/~1config~1smtp_servers~1{smtp_server_id}" + /erm/config: + $ref: ./paths/erm_config.yaml#/~1erm~1config /erm/agreements: $ref: ./paths/erm_agreements.yaml#/~1erm~1agreements "/erm/agreements/{agreement_id}": diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue index a9a78235e5..f67efc6e05 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue @@ -82,7 +82,7 @@ export default { const { get_lib_from_av, map_av_dt_filter } = AVStore const ERMStore = inject("ERMStore") - const { sysprefs } = ERMStore + const { config } = ERMStore const table = ref() const filters = reactive({ @@ -98,7 +98,7 @@ export default { get_lib_from_av, escape_str, map_av_dt_filter, - sysprefs, + config, table, } }, @@ -168,7 +168,7 @@ export default { this.show_table = true this.local_count_packages = null - if (this.sysprefs.ERMProviders.includes("local")) { + if (this.config.ERMProviders.includes("local")) { const client = APIClient.erm const query = this.filters ? { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue index dc453b0777..3f0588e796 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue @@ -85,7 +85,7 @@ export default { const { get_lib_from_av } = AVStore const ERMStore = inject("ERMStore") - const { sysprefs } = ERMStore + const { config } = ERMStore const table = ref() const filters = reactive({ @@ -99,7 +99,7 @@ export default { av_title_publication_types, get_lib_from_av, escape_str, - sysprefs, + config, table, } }, @@ -179,7 +179,7 @@ export default { "/api/v1/erm/eholdings/ebsco/titles" ) } - if (this.sysprefs.ERMProviders.includes("local")) { + if (this.config.ERMProviders.includes("local")) { const client = APIClient.erm const q = this.filters diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue index 1bc99a3570..58c45d7216 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue @@ -1,5 +1,5 @@