From c8b56a7dc30c9fbde604be64d8799c6f3356108e Mon Sep 17 00:00:00 2001 From: Frank Bergmann Date: Thu, 30 Jun 2022 14:57:53 +0200 Subject: [PATCH] WIP - error_file_link also working --- .../lib/api/v3/file_links/work_packages_file_links_api.rb | 7 ++++++- .../file_links/mixed_case_file_links_integration_spec.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb b/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb index efb7e55493..ffce201f7c 100644 --- a/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb +++ b/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb @@ -50,6 +50,7 @@ module API get do # API supports query filters on storages: # storage: { operator: '=', values: [storage_id] + # ToDo: Check if ParamsToQueryService raises condition? query = ParamsToQueryService .new(::Storages::Storage, current_user, @@ -57,9 +58,10 @@ module API .call(params) unless query.valid? - message = I18n.t('api_v3.errors.missing_or_malformed_parameter', parameter: 'filters') + message = I18n.t('api_v3.errors.missing_or_malformed_parameter') raise ::API::Errors::InvalidQuery.new(message) end + # ToDo: Double-check that I've got this tested # Get the list of all FileLinks for the work package. # This could be a huge array in some cases... @@ -71,6 +73,7 @@ module API begin # Synchronize with Nextcloud. StorageAPI handles OAuth2 for us. + # We ignore the result, because partial errors (storage network issues) are written to each FileLink service_result = ::Storages::FileLinkSyncService .new(user: current_user) .call(file_links) @@ -81,6 +84,8 @@ module API current_user: ) rescue StandardError => e + # ToDo: Check if API response handles exceptions like the one below (API.root) + # There was an error during the SyncService, which should normally not occur. message = "#{I18n.t('api_v3.errors.code_500')}: #{e.message}" raise ::API::Errors::InternalError.new(message) diff --git a/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb b/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb index f2cfa59758..07202f9488 100644 --- a/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb +++ b/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb @@ -211,7 +211,7 @@ describe 'API v3 file links resource', with_flag: { storages_module_active: true # The FileLink from a Nextcloud with timeout should have origin_permission=:error error_file_link = elements.detect { |e| e["originData"]["id"] == "29" } - expect(other_user_file_link["_links"]["permission"]["href"]).to eql API::V3::FileLinks::URN_PERMISSION_ERROR + expect(error_file_link["_links"]["permission"]["href"]).to eql API::V3::FileLinks::URN_PERMISSION_ERROR # ToDo: Search in elements for file_link with origin_id = '25' and check origin_permission = :not_authenticated # ToDo: Search for '24' and check for perms = :view