From feeb288e300934c29fdc02cdc480e4300ead197a 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 Signed-off-by: Tomas Cohen Arazi --- 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 | 9 +---- t/cypress/integration/ERM/Dialog_spec.ts | 9 +---- t/cypress/integration/ERM/Licenses_spec.ts | 9 +---- t/cypress/integration/ERM/Packages_spec.ts | 9 +---- t/cypress/integration/ERM/Searchbar_spec.ts | 9 +---- t/cypress/integration/ERM/Titles_spec.ts | 9 +---- 14 files changed, 108 insertions(+), 66 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 3e248299ea..4eebfdf23d 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -36,6 +36,8 @@ definitions: $ref: ./definitions/credit.yaml debit: $ref: ./definitions/debit.yaml + erm_config: + $ref: ./definitions/erm_config.yaml erm_agreement: $ref: ./definitions/erm_agreement.yaml erm_eholdings_title: @@ -213,6 +215,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 551b19325c..2a5822371d 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 dc5cf89c7f..a3405d50fe 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 d395c26b44..12e569e28d 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 @@