OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#52181] bad error message on request timeout to remote storage
Eric Schubert2a098dcfdcd6
diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rbindex 3ec80707cb4..8100224d5ba 100644--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb@@ -42,9 +42,9 @@ module Storagesdef authorization_check_wrappercase yield- when 200..299+ in { status: 200..299 }:success- when 401, 403+ in { status: 401 | 403 }:refresh_neededelse:errordiff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rbindex 7b54125acb7..0e835ae098c 100644--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb@@ -51,7 +51,7 @@ module Storages'OCS-APIRequest' => 'true','Accept' => 'application/json'}- ).status+ )endenddiff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rbindex d22346c04af..e19a892ea64 100644--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb@@ -51,7 +51,7 @@ module StoragesHTTPX.get(util.join_uri_path(@uri, '/v1.0/me'),headers: { 'Authorization' => "Bearer #{access_token}", 'Accept' => 'application/json' }- ).status+ )endenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rbindex 47bac702ae2..7719f89e0a2 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb@@ -54,13 +54,13 @@ module Storages::Peripherals::StorageInteraction::NextcloudCGI.escapeURIComponent(user),'groups'),- form: { "groupid" => CGI.escapeURIComponent(group) },+ form: { "groupid" => CGI.escapeURIComponent(group) })error_data = Storages::StorageErrorData.new(source: self.class, payload: response)- case response.status- when 200..299+ case response+ in { status: 200..299 }statuscode = Nokogiri::XML(response.body.to_s).xpath('/ocs/meta/statuscode').textcase statuscode@@ -77,18 +77,19 @@ module Storages::Peripherals::StorageInteraction::Nextcloudwhen "105"Util.error(:error, "Failed to add user to group", error_data)end- when 405+ in { status: 405 }Util.error(:not_allowed, 'Outbound request method not allowed', error_data)- when 401+ in { status: 401 }Util.error(:not_found, 'Outbound request destination not found', error_data)- when 404+ in { status: 404 }Util.error(:unauthorized, 'Outbound request not authorized', error_data)- when 409+ in { status: 409 }Util.error(:conflict, Util.error_text_from_response(response), error_data)elseUtil.error(:error, 'Outbound request failed', error_data)endend+# rubocop:enable Metrics/AbcSizeendenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rbindex 4fa9b23b21f..f0df5699b74 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb@@ -84,12 +84,12 @@ module Storages::Peripherals::StorageInteraction::Nextcloud.basic_auth(@username, @password).head(urls[:destination_url])- case response.status- when 200..299+ case response+ in { status: 200..299 }Util.error(:conflict, 'Destination folder already exists.')- when 401+ in { status: 401 }Util.error(:unauthorized, "unauthorized (validate_destination)")- when 404+ in { status: 404 }ServiceResult.success(result: urls)elseUtil.error(:unknown, "Unexpected response (validate_destination): #{response.code}", response)@@ -109,14 +109,14 @@ module Storages::Peripherals::StorageInteraction::Nextcloud'Depth' => 'infinity'})- case response.status- when 200..299+ case response+ in { status: 200..299 }ServiceResult.success(message: 'Folder was successfully copied')- when 401+ in { status: 401 }Util.error(:unauthorized, "Unauthorized (copy_folder)")- when 404+ in { status: 404 }Util.error(:not_found, "Project folder not found (copy_folder)")- when 409+ in { status: 409 }Util.error(:conflict, Util.error_text_from_response(response))elseUtil.error(:unknown, "Unexpected response (copy_folder): #{response.status}", response)diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rbindex 1724f7697e1..f7264b7f7cb 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb@@ -58,20 +58,20 @@ module Storages::Peripherals::StorageInteraction::Nextclouderror_data = Storages::StorageErrorData.new(source: self.class, payload: response)- case response.status- when 200..299+ case response+ in { status: 200..299 }ServiceResult.success(message: 'Folder was successfully created.')- when 405+ in { status: 405 }if Util.error_text_from_response(response) == 'The resource you tried to create already exists'ServiceResult.success(message: 'Folder already exists.')elseUtil.error(:not_allowed, 'Outbound request method not allowed', error_data)end- when 401+ in { status: 401 }Util.error(:unauthorized, 'Outbound request not authorized', error_data)- when 404+ in { status: 404 }Util.error(:not_found, 'Outbound request destination not found', error_data)- when 409+ in { status: 409 }Util.error(:conflict, Util.error_text_from_response(response), error_data)elseUtil.error(:error, 'Outbound request failed', error_data)diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rbindex 0184867923a..b87c9510a39 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb@@ -41,35 +41,9 @@ module Storages::Peripherals::StorageInteraction::Nextcloudnew(storage).call(user:, file_link:)end- # rubocop:disable Metrics/AbcSizedef call(user:, file_link:)result = Util.token(user:, configuration: @configuration) do |token|- service_result = begin- response = Util- .httpx- .post(- Util.join_uri_path(@uri, '/ocs/v2.php/apps/dav/api/v1/direct'),- json: { fileId: file_link.origin_id },- headers: {- 'Authorization' => "Bearer #{token.access_token}",- 'OCS-APIRequest' => 'true',- 'Accept' => 'application/json',- 'Content-Type' => 'application/json'- }- )- case response.status- when 200..299- ServiceResult.success(result: response)- when 404- Util.error(:not_found, 'Outbound request destination not found!', response)- when 401- Util.error(:unauthorized, 'Outbound request not authorized!', response)- else- Util.error(:error, 'Outbound request failed!')- end- end-- service_result.bind do |resp|+ direct_download_request(token, file_link).bind do |resp|# The nextcloud API returns a successful response with empty body if the authorization is missing or expiredif resp.body.blank?Util.error(:unauthorized, 'Outbound request not authorized!')@@ -84,10 +58,33 @@ module Storages::Peripherals::StorageInteraction::Nextcloud.map { |download_token| download_link(download_token, file_link.origin_name) }end- # rubocop:enable Metrics/AbcSize-private+ def direct_download_request(token, file_link)+ response = Util+ .httpx+ .post(+ Util.join_uri_path(@uri, '/ocs/v2.php/apps/dav/api/v1/direct'),+ json: { fileId: file_link.origin_id },+ headers: {+ 'Authorization' => "Bearer #{token.access_token}",+ 'OCS-APIRequest' => 'true',+ 'Accept' => 'application/json',+ 'Content-Type' => 'application/json'+ }+ )+ case response+ in { status: 200..299 }+ ServiceResult.success(result: response)+ in { status: 404 }+ Util.error(:not_found, 'Outbound request destination not found!', response)+ in { status: 401 }+ Util.error(:unauthorized, 'Outbound request not authorized!', response)+ else+ Util.error(:error, 'Outbound request failed!')+ end+ end+def download_link(token, origin_name)Util.join_uri_path(@uri, 'index.php/apps/integration_openproject/direct', token, CGI.escape(origin_name))enddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rbindex 77df6fb0705..0987f16df54 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb@@ -59,12 +59,12 @@ module Storages::Peripherals::StorageInteraction::Nextcloud'OCS-APIRequest' => 'true' }).get(Util.join_uri_path(@uri, FILE_INFO_PATH, file_id))- case response.status- when 200..299+ case response+ in { status: 200..299 }ServiceResult.success(result: response.body)- when 404+ in { status: 404 }Util.error(:not_found, 'Outbound request destination not found!', response)- when 401+ in { status: 401 }Util.error(:unauthorized, 'Outbound request not authorized!', response)elseUtil.error(:error, 'Outbound request failed!')diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rbindex 8d9017a4998..55f15a7a9e5 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb@@ -69,12 +69,12 @@ module Storages::Peripherals::StorageInteraction::Nextcloud.post(Util.join_uri_path(@uri.to_s, FILES_INFO_PATH),json: { fileIds: file_ids })- case response.status- when 200..299+ case response+ in { status: 200..299 }ServiceResult.success(result: response.body.to_s)- when 404+ in { status: 404 }Util.error(:not_found, 'Outbound request destination not found!', response)- when 401+ in { status: 401 }Util.error(:unauthorized, 'Outbound request not authorized!', response)elseUtil.error(:error, 'Outbound request failed!', response)diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rbindex 4e96c42d7e0..abd24e8bff5 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb@@ -45,7 +45,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud.httpx.request("PROPFIND",- Util.join_uri_path(@uri, "remote.php/dav/files", CGI.escapeURIComponent(token.origin_user_id), requested_folder(folder)),+ Util.join_uri_path(@uri,+ "remote.php/dav/files",+ CGI.escapeURIComponent(token.origin_user_id),+ requested_folder(folder)),xml: requested_properties,headers: {'Depth' => '1',@@ -64,12 +67,12 @@ module Storages::Peripherals::StorageInteraction::Nextclouddef handle_response(response)error_data = Storages::StorageErrorData.new(source: self, payload: response)- case response.status- when 200..299+ case response+ in { status: 200..299 }ServiceResult.success(result: response.body)- when 404+ in { status: 404 }Util.error(:not_found, 'Outbound request destination not found', error_data)- when 401+ in { status: 401 }Util.error(:unauthorized, 'Outbound request not authorized', error_data)elseUtil.error(:error, 'Outbound request failed', error_data)diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rbindex 1450e2e4153..622f07217db 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb@@ -47,29 +47,30 @@ module Storages::Peripherals::StorageInteraction::Nextcloudresponse = Util.httpx.basic_auth(@username, @password)- .with(headers: {'OCS-APIRequest' => 'true'})+ .with(headers: { 'OCS-APIRequest' => 'true' }).get(Util.join_uri_path(@uri, "ocs/v1.php/cloud/groups", CGI.escapeURIComponent(group)))error_data = Storages::StorageErrorData.new(source: self.class, payload: response)- case response.status- when 200..299+ case response+ in { status: 200..299 }group_users = Nokogiri::XML(response.body.to_s).xpath('/ocs/data/users/element').map(&:text)ServiceResult.success(result: group_users)- when 405+ in { status: 405 }Util.error(:not_allowed, 'Outbound request method not allowed', error_data)- when 401+ in { status: 401 }Util.error(:unauthorized, 'Outbound request not authorized', error_data)- when 404+ in { status: 404 }Util.error(:not_found, 'Outbound request destination not found', error_data)- when 409+ in { status: 409 }Util.error(:conflict, error_text_from_response(response), error_data)elseUtil.error(:error, 'Outbound request failed', error_data)endend+# rubocop:enable Metrics/AbcSizeendenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rbindex 2c848aeb040..c8821319bd2 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb@@ -49,12 +49,12 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::InternalCGI.escapeURIComponent(@username),UTIL.escape_path(location)))- case response.status- when 200..299+ case response+ in { status: 200..299 }ServiceResult.success- when 404+ in { status: 404 }UTIL.error(:not_found)- when 401+ in { status: 401 }UTIL.error(:unauthorized)elseUTIL.error(:error)diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rbindex cd37e9eea16..bf5199761a9 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb@@ -93,7 +93,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Internalresponse = UTIL.httpx.basic_auth(@username, @password)- .with(headers: { "Depth" => depth})+ .with(headers: { "Depth" => depth }).request("PROPFIND",UTIL.join_uri_path(@@ -102,13 +102,13 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::InternalCGI.escapeURIComponent(@username),UTIL.escape_path(path)),- xml: body,+ xml: body)error_data = Storages::StorageErrorData.new(source: self.class, payload: response)- case response.status- when 200..299+ case response+ in { status: 200..299 }doc = Nokogiri::XML(response.body.to_s)result = {}doc.xpath('/d:multistatus/d:response').each do |resource_section|@@ -125,11 +125,11 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::InternalendServiceResult.success(result:)- when 405+ in { status: 405 }UTIL.error(:not_allowed, 'Outbound request method not allowed', error_data)- when 401+ in { status: 401 }UTIL.error(:unauthorized, 'Outbound request not authorized', error_data)- when 404+ in { status: 404 }UTIL.error(:not_found, 'Outbound request destination not found', error_data)elseUTIL.error(:error, 'Outbound request failed', error_data)diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rbindex 1fc5f256b62..70ac648824c 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb@@ -56,8 +56,8 @@ module Storages::Peripherals::StorageInteraction::Nextclouderror_data = Storages::StorageErrorData.new(source: self.class, payload: response)- case response.status- when 200..299+ case response+ in { status: 200..299 }statuscode = Nokogiri::XML(response.body.to_s).xpath('/ocs/meta/statuscode').textcase statuscodewhen "100"@@ -74,18 +74,19 @@ module Storages::Peripherals::StorageInteraction::Nextcloudmessage = Nokogiri::XML(response.body).xpath('/ocs/meta/message').textUtil.error(:error, "Failed to remove user #{user} from group #{group}: #{message}", error_data)end- when 405+ in { status: 405 }Util.error(:not_allowed, 'Outbound request method not allowed', error_data)- when 401+ in { status: 401 }Util.error(:unauthorized, 'Outbound request not authorized', error_data)- when 404+ in { status: 404 }Util.error(:not_found, 'Outbound request destination not found', error_data)- when 409+ in { status: 409 }Util.error(:conflict, Util.error_text_from_response(response), error_data)elseUtil.error(:error, 'Outbound request failed', error_data)endend+# rubocop:enable Metrics/AbcSizeendenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rbindex 3a84be73ae7..41e31c16d2f 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb@@ -51,18 +51,21 @@ module Storages::Peripherals::StorageInteraction::Nextcloud"MOVE",Util.join_uri_path(@base_path, Util.escape_path(source)),headers: {- 'Destination' => Util.join_uri_path(@uri.path, "remote.php/dav/files", CGI.escapeURIComponent(@username), Util.escape_path(target))+ 'Destination' => Util.join_uri_path(@uri.path,+ "remote.php/dav/files",+ CGI.escapeURIComponent(@username),+ Util.escape_path(target))})error_data = Storages::StorageErrorData.new(source: self.class, payload: response)- case response.status- when 200..299+ case response+ in { status: 200..299 }ServiceResult.success- when 404+ in { status: 404 }Util.error(:not_found, 'Outbound request destination not found', error_data)- when 401+ in { status: 401 }Util.error(:unauthorized, 'Outbound request not authorized', error_data)elseUtil.error(:error, 'Outbound request failed', error_data)diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rbindex e856b0b965f..404767b4a7c 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb@@ -43,6 +43,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloudend# rubocop:disable Metrics/AbcSize+ # rubocop:disable Metrics/PerceivedComplexitydef call(path:, permissions:)raise ArgumentError if path.blank?@@ -93,22 +94,24 @@ module Storages::Peripherals::StorageInteraction::Nextclouderror_data = Storages::StorageErrorData.new(source: self.class, payload: response)- case response.status- when 200..299+ case response+ in { status: 200..299 }doc = Nokogiri::XML(response.body.to_s)if doc.xpath("/d:multistatus/d:response/d:propstat[d:status[text() = 'HTTP/1.1 200 OK']]/d:prop/nc:acl-list").present?ServiceResult.success(result: :success)elseUtil.error(:error, "nc:acl properly has not been set for #{path}", error_data)end- when 404+ in { status: 404 }Util.error(:not_found, 'Outbound request destination not found', error_data)- when 401+ in { status: 401 }Util.error(:unauthorized, 'Outbound request not authorized', error_data)elseUtil.error(:error, 'Outbound request failed', error_data)endend+# rubocop:enable Metrics/AbcSize+ # rubocop:enable Metrics/PerceivedComplexityendenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rbindex 71f7c258ba0..3d789cac958 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb@@ -50,7 +50,6 @@ module Storages::Peripherals::StorageInteraction::NextcloudUtil.error(:error, 'Data is invalid', data)elseoutbound_response(- method: :post,relative_path: URI_TOKEN_REQUEST,payload: { folder_id: data['parent'] },token:@@ -65,7 +64,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloudprivate- def outbound_response(method:, relative_path:, payload:, token:)+ def outbound_response(relative_path:, payload:, token:)response = Util.httpx.with(headers: { 'Authorization' => "Bearer #{token.access_token}",@@ -75,8 +74,8 @@ module Storages::Peripherals::StorageInteraction::NextcloudUtil.join_uri_path(@uri, relative_path),json: payload)- case response.status- when 200..299+ case response+ in { status: 200..299 }# The nextcloud API returns a successful response with empty body if the authorization is missing or expiredif response.body.present?ServiceResult.success(@@ -85,9 +84,9 @@ module Storages::Peripherals::StorageInteraction::NextcloudelseUtil.error(:unauthorized, 'Outbound request not authorized!')end- when 404+ in { status: 404 }Util.error(:not_found, 'Outbound request destination not found!', response)- when 401+ in { status: 401 }Util.error(:unauthorized, 'Outbound request not authorized!', response)elseUtil.error(:error, 'Outbound request failed!')diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rbindex ea1ec7ac2e5..6e3e21fc76b 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb@@ -52,11 +52,7 @@ module Storagesheaders: { 'Authorization' => "Bearer #{token.access_token}" })- if (300..399).include?(response.status)- ServiceResult.success(result: response.headers['Location'])- else- handle_errors(response)- end+ handle_errors(response)endend@@ -64,18 +60,20 @@ module Storagesdef handle_errors(response)case response- when 404+ in { status: 300..399 }+ ServiceResult.success(result: response.headers['Location'])+ in { status: 404 }ServiceResult.failure(result: :not_found,- errors: ::Storages::StorageError.new(code: :not_found, data: response.body))- when 403+ errors: ::Storages::StorageError.new(code: :not_found, data: response))+ in { status: 403 }ServiceResult.failure(result: :forbidden,- errors: ::Storages::StorageError.new(code: :forbidden, data: response.body))- when 401+ errors: ::Storages::StorageError.new(code: :forbidden, data: response))+ in { status: 401 }ServiceResult.failure(result: :unauthorized,- errors: ::Storages::StorageError.new(code: :unauthorized, data: response.body))+ errors: ::Storages::StorageError.new(code: :unauthorized, data: response))elseServiceResult.failure(result: :error,- errors: ::Storages::StorageError.new(code: :error, data: response.body))+ errors: ::Storages::StorageError.new(code: :error, data: response))endenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rbindex bba2e7ebb2d..59f2dccebdd 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb@@ -72,10 +72,16 @@ module Storagesif query_result.success?query_result.resultelse+ status = if query_result.error_payload.instance_of?(HTTPX::ErrorResponse)+ query_result.error_payload.error+ else+ query_result.error_payload.dig(:error, :code)+ end+StorageFileInfo.new(id: file_id,- status: query_result.error_payload.dig(:error, :code),- status_code: Rack::Utils::SYMBOL_TO_STATUS_CODE[query_result.errors.code]+ status:,+ status_code: Rack::Utils::SYMBOL_TO_STATUS_CODE[query_result.errors.code] || 500)endenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rbindex 972db4b0024..b315f83039c 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb@@ -66,21 +66,18 @@ module Storagesprivatedef handle_response(response, map_value)- json = MultiJson.load(response.body.to_s, symbolize_keys: true)- error_data = ::Storages::StorageErrorData.new(source: self, payload: json)-- case response.status- when 200..299- ServiceResult.success(result: json.fetch(map_value))- when 404+ case response+ in { status: 200..299 }+ ServiceResult.success(result: response.json(symbolize_keys: true).fetch(map_value))+ in { status: 404 }ServiceResult.failure(result: :not_found,- errors: ::Storages::StorageError.new(code: :not_found, data: error_data))- when 401+ errors: Util.storage_error(response:, code: :not_found, source: self))+ in { status: 401 }ServiceResult.failure(result: :unauthorized,- errors: ::Storages::StorageError.new(code: :unauthorized, data: error_data))+ errors: Util.storage_error(response:, code: :unauthorized, source: self))else- ServiceResult.failure(result: :error,- errors: ::Storages::StorageError.new(code: :error, data: error_data))+ data = ::Storages::StorageErrorData.new(source: self, payload: response)+ ServiceResult.failure(result: :error, errors: ::Storages::StorageError.new(code: :error, data:))endenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/internal/drive_item_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/internal/drive_item_query.rbindex 150af97837d..dfeb779d26f 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/internal/drive_item_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/internal/drive_item_query.rb@@ -43,24 +43,21 @@ module Storagesenddef handle_responses(response)- json = MultiJson.load(response.body.to_s, symbolize_keys: true)- error_data = ::Storages::StorageErrorData.new(source: self, payload: json)-- case response.status- when 200..299- ServiceResult.success(result: json)- when 404+ case response+ in { status: 200..299 }+ ServiceResult.success(result: response.json(symbolize_keys: true))+ in { status: 404 }ServiceResult.failure(result: :not_found,- errors: ::Storages::StorageError.new(code: :not_found, data: error_data))- when 403+ errors: UTIL.storage_error(response:, code: :not_found, source: self))+ in { status: 403 }ServiceResult.failure(result: :forbidden,- errors: ::Storages::StorageError.new(code: :forbidden, data: error_data))- when 401+ errors: UTIL.storage_error(response:, code: :forbidden, source: self))+ in { status: 401 }ServiceResult.failure(result: :unauthorized,- errors: ::Storages::StorageError.new(code: :unauthorized, data: error_data))+ errors: UTIL.storage_error(response:, code: :unauthorized, source: self))else- ServiceResult.failure(result: :error,- errors: ::Storages::StorageError.new(code: :error, data: error_data))+ data = ::Storages::StorageErrorData.new(source: self, payload: response)+ ServiceResult.failure(result: :error, errors: ::Storages::StorageError.new(code: :error, data:))endenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rbindex 6d60844943c..bb5d19d0f95 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb@@ -59,24 +59,21 @@ module Storagesenddef handle_responses(response)- json = MultiJson.load(response.body.to_s, symbolize_keys: true)- error_data = ::Storages::StorageErrorData.new(source: self, payload: json)-- case response.status- when 200..299- ServiceResult.success(result: json)- when 404+ case response+ in { status: 200..299 }+ ServiceResult.success(result: response.json(symbolize_keys: true))+ in { status: 404 }ServiceResult.failure(result: :not_found,- errors: ::Storages::StorageError.new(code: :not_found, data: error_data))- when 403+ errors: Util.storage_error(response:, code: :not_found, source: self))+ in { status: 403 }ServiceResult.failure(result: :forbidden,- errors: ::Storages::StorageError.new(code: :forbidden, data: error_data))- when 401+ errors: Util.storage_error(response:, code: :forbidden, source: self))+ in { status: 401 }ServiceResult.failure(result: :unauthorized,- errors: ::Storages::StorageError.new(code: :unauthorized, data: error_data))+ errors: Util.storage_error(response:, code: :unauthorized, source: self))else- ServiceResult.failure(result: :error,- errors: ::Storages::StorageError.new(code: :error, data: error_data))+ data = ::Storages::StorageErrorData.new(source: self, payload: response)+ ServiceResult.failure(result: :error, errors: ::Storages::StorageError.new(code: :error, data:))endenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rbindex 6093cb9f888..44225327b60 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb@@ -65,13 +65,13 @@ module Storagesenddef handle_response(response)- case response.status- when 200..299+ case response+ in { status: 200..299 }upload_url = MultiJson.load(response.body, symbolize_keys: true)[:uploadUrl]ServiceResult.success(result: ::Storages::UploadLink.new(URI(upload_url), :put))- when 404+ in { status: 404 }ServiceResult.failure(result: :not_found, errors: ::Storages::StorageError.new(code: :not_found))- when 401+ in { status: 401 }ServiceResult.failure(result: :unauthorized, errors: ::Storages::StorageError.new(code: :unauthorized))elseServiceResult.failure(result: :error, errors: ::Storages::StorageError.new(code: :error))diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rbindex dfb8a78e479..9a3ef5f0fdb 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb@@ -59,6 +59,12 @@ module Storages::Peripherals::StorageInteraction::OneDrive::Util)end+ def storage_error(response:, code:, source:)+ data = ::Storages::StorageErrorData.new(source:, payload: response.json(symbolize_keys: true))++ ::Storages::StorageError.new(code:, data:)+ end+def join_uri_path(uri, *)# We use `File.join` to ensure single `/` in between every part. This API will break if executed on a# Windows context, as it used `\` as file separators. But we anticipate that OpenProjectdiff --git a/modules/storages/app/validator/nextcloud_application_credentials_validator.rb b/modules/storages/app/validator/nextcloud_application_credentials_validator.rbindex cfff7a3a5fc..59d4a9c5944 100644--- a/modules/storages/app/validator/nextcloud_application_credentials_validator.rb+++ b/modules/storages/app/validator/nextcloud_application_credentials_validator.rb@@ -35,6 +35,7 @@ class NextcloudApplicationCredentialsValidator@uri = URI(contract.host).normalizeend+ # rubocop:disable Metrics/AbcSizedef callreturn unless contract.model.password_changed?@@ -42,13 +43,15 @@ class NextcloudApplicationCredentialsValidator.httpx.basic_auth(contract.username, contract.password).head(UTIL.join_uri_path(uri, "remote.php/dav"))- case response.status- when 200..299+ case response+ in { status: 200..299 }true- when 401+ in { status: 401 }contract.errors.add(:password, :invalid_password)elsecontract.errors.add(:password, :unknown_error)endend++ # rubocop:enable Metrics/AbcSizeenddiff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/file_info_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/file_info_query_spec.rbindex 770017d79be..ae782aef455 100644--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/file_info_query_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/file_info_query_spec.rb@@ -186,4 +186,20 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FileInfoQuer)endend++ context 'with network errors' do+ let(:file_id) { '01AZJL5PNCQCEBFI3N7JGZSX5AOX32Z3LA' }++ before do+ request = HTTPX::Request.new(:get, 'https://my.timeout.org/')+ allow(HTTPX).to receive(:get).and_return(HTTPX::ErrorResponse.new(request, 'Timeout happens', {}))+ end++ it 'must return an error with wrapped network error response' do+ error = subject.call(user:, file_id:)+ expect(error).to be_failure+ expect(error.result).to eq(:error)+ expect(error.error_payload).to be_a(HTTPX::ErrorResponse)+ end+ endenddiff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_info_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_info_query_spec.rbindex 1d1bdf841ba..5ef8633bd27 100644--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_info_query_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_info_query_spec.rb@@ -214,5 +214,30 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesInfoQue)endend++ context 'with network errors' do+ let(:file_ids) { %w[01AZJL5PKU2WV3U3RKKFF2A7ZCWVBXRTEU] }++ before do+ request = HTTPX::Request.new(:get, 'https://my.timeout.org/')+ allow(HTTPX).to receive(:get).and_return(HTTPX::ErrorResponse.new(request, 'Timeout happens', {}))+ end++ it 'must return an array of file information when called' do+ result = subject.call(user:, file_ids:)+ expect(result).to be_success++ result.match(+ on_success: ->(file_infos) do+ expect(file_infos.size).to eq(1)+ expect(file_infos).to all(be_a(Storages::StorageFileInfo))+ expect(file_infos[0].id).to eq('01AZJL5PKU2WV3U3RKKFF2A7ZCWVBXRTEU')+ expect(file_infos[0].status).to eq('Timeout happens')+ expect(file_infos[0].status_code).to eq(500)+ end,+ on_failure: ->(error) { fail "Expected success, got #{error}" }+ )+ end+ endendenddiff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rbindex a309a40f1ce..5f83796ee8e 100644--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rb@@ -238,5 +238,19 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesQuery,)endend++ context 'with network errors' do+ before do+ request = HTTPX::Request.new(:get, 'https://my.timeout.org/')+ allow(HTTPX).to receive(:get).and_return(HTTPX::ErrorResponse.new(request, 'Timeout happens', {}))+ end++ it 'must return an error with wrapped network error response' do+ error = described_class.call(storage:, user:, folder:)+ expect(error).to be_failure+ expect(error.result).to eq(:error)+ expect(error.error_payload).to be_a(HTTPX::ErrorResponse)+ end+ endendenddiff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rbindex aa786682f54..44e54762780 100644--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rb@@ -89,5 +89,19 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::OpenStorageQ)endend++ context 'with network errors' do+ before do+ request = HTTPX::Request.new(:get, 'https://my.timeout.org/')+ allow(HTTPX).to receive(:get).and_return(HTTPX::ErrorResponse.new(request, 'Timeout happens', {}))+ end++ it 'must return an error with wrapped network error response' do+ error = subject.call(user:)+ expect(error).to be_failure+ expect(error.result).to eq(:error)+ expect(error.error_payload).to be_a(HTTPX::ErrorResponse)+ end+ endendenddiff --git a/spec/services/oauth_clients/one_drive_connection_manager_spec.rb b/spec/services/oauth_clients/one_drive_connection_manager_spec.rbindex 679dab96e2c..3b04b0aa902 100644--- a/spec/services/oauth_clients/one_drive_connection_manager_spec.rb+++ b/spec/services/oauth_clients/one_drive_connection_manager_spec.rb@@ -129,12 +129,19 @@ RSpec.describe OAuthClients::ConnectionManager, :webmock, type: :model doendend- context 'when Unathorized is returned' do+ context 'when Unauthorized is returned' dobefore dostub_request(:get, 'https://graph.microsoft.com/v1.0/me').to_return(status: 401)endcontext 'with valid refresh token' do+ before do+ stub_request(:post, 'https://login.microsoftonline.com/consumers/oauth2/v2.0/token')+ .to_return(status: 200,+ body: { access_token: 'ThereIsNoPeaceOnlyPassion' }.to_json,+ headers: { 'Content-Type' => 'application/json' })+ end+it 'refreshes the access token and returns :connected' doexpect(authorization_state).to eq :connectedend