From c1455422e4c13317166339699fe8b7d3a259e77d Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Tue, 30 May 2023 14:44:48 +0000 Subject: [PATCH] Bug 34587: Add test connection button Signed-off-by: Jessica Zairo Signed-off-by: Michaela Sieber Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/ERM/UsageDataProviders.pm | 28 ++++++++++++ .../paths/erm_usage_data_providers.yaml | 38 ++++++++++++++++ api/v1/swagger/swagger.yaml | 2 + .../ERM/UsageStatisticsDataProvidersList.vue | 45 ++++++++++++++++++- .../prog/js/vue/fetch/erm-api-client.js | 4 ++ 5 files changed, 116 insertions(+), 1 deletion(-) diff --git a/Koha/REST/V1/ERM/UsageDataProviders.pm b/Koha/REST/V1/ERM/UsageDataProviders.pm index 7d4293a28d..8aa9e71542 100644 --- a/Koha/REST/V1/ERM/UsageDataProviders.pm +++ b/Koha/REST/V1/ERM/UsageDataProviders.pm @@ -331,4 +331,32 @@ sub run { $c->unhandled_exception($_); }; } + +=head3 test_connection + +=cut + +sub test_connection { + my $c = shift->openapi->valid_input or return; + + my $udprovider = Koha::ERM::UsageDataProviders->find( $c->validation->param('erm_usage_data_provider_id') ); + + unless ($udprovider) { + return $c->render( + status => 404, + openapi => { error => "Usage data provider not found" } + ); + } + try { + my $service_active = $udprovider->test_connection; + return $c->render( + status => 200, + openapi => $service_active + ); + } + catch { + $c->unhandled_exception($_); + }; +} + 1; diff --git a/api/v1/swagger/paths/erm_usage_data_providers.yaml b/api/v1/swagger/paths/erm_usage_data_providers.yaml index 2ad45858ab..6ad30e320f 100644 --- a/api/v1/swagger/paths/erm_usage_data_providers.yaml +++ b/api/v1/swagger/paths/erm_usage_data_providers.yaml @@ -407,6 +407,44 @@ description: Under maintenance schema: $ref: "../swagger.yaml#/definitions/error" + x-koha-authorization: + permissions: + erm: 1 +"/erm/usage_data_providers/{erm_usage_data_provider_id}/test_connection": + get: + x-mojo-to: ERM::UsageDataProviders#test_connection + operationId: testUsageDataProviderHarvester + tags: + - usage data provider harvester + summary: Run this data provider's harvester + produces: + - application/json + parameters: + - $ref: "../swagger.yaml#/parameters/erm_usage_data_provider_id_pp" + responses: + 200: + description: Successful connection test + schema: + items: + $ref: "../swagger.yaml#/definitions/erm_usage_data_provider" + 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 \ No newline at end of file diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 387f795e3a..7b88e50f8b 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -293,6 +293,8 @@ paths: $ref: "./paths/erm_usage_data_providers.yaml#/~1erm~1usage_data_providers~1{erm_usage_data_provider_id}" "/erm/usage_data_providers/{erm_usage_data_provider_id}/run": $ref: "./paths/erm_usage_data_providers.yaml#/~1erm~1usage_data_providers~1{erm_usage_data_provider_id}~1run" + "/erm/usage_data_providers/{erm_usage_data_provider_id}/test_connection": + $ref: "./paths/erm_usage_data_providers.yaml#/~1erm~1usage_data_providers~1{erm_usage_data_provider_id}~1test_connection" /erm/usage_titles: $ref: ./paths/erm_usage_titles.yaml#/~1erm~1usage_titles /erm/users: diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersList.vue index acced92ce0..86b23ac247 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersList.vue @@ -25,6 +25,7 @@ @edit="edit_usage_data_provider" @delete="delete_usage_data_provider" @run_now="run_harvester_now" + @test_connection="test_harvester_connection" >
@@ -44,7 +45,8 @@ export default { const AVStore = inject("AVStore") // Left in for future permissions fixes const { get_lib_from_av, map_av_dt_filter } = AVStore - const { setConfirmationDialog, setMessage } = inject("mainStore") + const { setConfirmationDialog, setMessage, setWarning } = + inject("mainStore") const table = ref() @@ -53,6 +55,7 @@ export default { map_av_dt_filter, setConfirmationDialog, setMessage, + setWarning, table, } }, @@ -76,6 +79,12 @@ export default { icon: "fa fa-play", }, }, + { + test_connection: { + text: this.$__("Test"), + icon: "fa fa-check", + }, + }, "edit", "delete", ], @@ -216,6 +225,40 @@ export default { ) } }, + test_harvester_connection(usage_data_provider, dt, event) { + const { erm_usage_data_provider_id: id, name } = usage_data_provider + + if (usage_data_provider.active) { + const client = APIClient.erm + client.usage_data_providers.test(id).then( + success => { + if (success) { + this.setMessage( + this.$__( + "Harvester connection was successful for usage data provider %s" + ).format(name), + true + ) + } else { + this.setMessage( + this.$__( + "No connection for usage data provider %s, please check your credentials and try again." + ).format(name), + true + ) + } + }, + error => {} + ) + } else { + this.setWarning( + this.$__( + "This data provider is inactive - connection testing is not possible" + ), + true + ) + } + }, getTableColumns() { return [ { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js index e2c233fa83..dab77486c8 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js @@ -280,6 +280,10 @@ export class ERMAPIClient extends HttpClient { this.get({ endpoint: "usage_data_providers/" + id + "/run?begin_date="+ begin_date + "&end_date=" + end_date, }), + test: (id) => + this.get({ + endpoint: "usage_data_providers/" + id + "/test_connection", + }), //count: () => this.count("usage_data_providers"), //TODO: Implement count method }; } -- 2.39.5