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
Use only httx in nextcloud related requests.
Pavel Balashou89e4d06f8b00
diff --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 f4ea5b8916f..bbf24cc8f80 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@@ -79,9 +79,6 @@ module Storages::Peripherals::StorageInteraction::Nextclouddef validate_destination->(urls) do- request = Net::HTTP::Head.new(urls[:destination_url])- request.initialize_http_header Util.basic_auth_header(@username, @password)-response = Util.httpx.basic_auth(@username, @password)@@ -100,7 +97,6 @@ module Storages::Peripherals::StorageInteraction::Nextcloudendend- # rubocop:disable Metrics/AbcSizedef copy_folder->(urls) doresponse = Util@@ -110,7 +106,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloudurls[:source_url],headers: {'Destination' => urls[:destination_url],- 'Depth' => 'infinity',+ 'Depth' => 'infinity'})case response.status@@ -127,7 +123,5 @@ module Storages::Peripherals::StorageInteraction::Nextcloudendendend-- # rubocop:enable Metrics/AbcSizeendenddiff --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 3038fde0a9b..96dad117732 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@@ -60,15 +60,14 @@ module Storages::Peripherals::StorageInteraction::Nextcloudprivatedef files_info(file_ids, token)- httpx = HTTPX.with(headers:- {- 'Authorization' => "Bearer #{token.access_token}",- 'Accept' => 'application/json',- 'Content-Type' => 'application/json',- 'OCS-APIRequest' => 'true'- }- )- response = httpx.post(Util.join_uri_path(@uri.to_s, FILES_INFO_PATH), json: { fileIds: file_ids })+ response = Util+ .httpx+ .with(headers: { 'Authorization' => "Bearer #{token.access_token}",+ 'Accept' => 'application/json',+ 'Content-Type' => 'application/json',+ 'OCS-APIRequest' => 'true' })+ .post(Util.join_uri_path(@uri.to_s, FILES_INFO_PATH),+ json: { fileIds: file_ids })case response.statuswhen 200diff --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 0c0bbcac81a..bdd0455219a 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@@ -105,14 +105,10 @@ module Storages::Peripherals::StorageInteraction::Nextclouddef storage_files(response)response.map do |xml|- a = Nokogiri::XML(xml)- .xpath('//d:response')- .to_a-- parent, *files =- a.map do |file_element|- storage_file(file_element)- end+ parent, *files = Nokogiri::XML(xml)+ .xpath('//d:response')+ .to_a+ .map { |file_element| storage_file(file_element) }::Storages::StorageFiles.new(files, parent, ancestors(parent.location))enddiff --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 c2be065d34a..2472fbcd575 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@@ -44,7 +44,8 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Internalresponse = UTIL.httpx.basic_auth(@username, @password)- .delete(UTIL.join_uri_path(@uri, "remote.php/dav/files",+ .delete(UTIL.join_uri_path(@uri,+ "remote.php/dav/files",CGI.escapeURIComponent(@username),UTIL.escape_path(location)))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 18f90cde322..2e767d916eb 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@@ -81,7 +81,6 @@ module Storages::Peripherals::StorageInteraction::Nextcloudresponse = Util.httpx- .with(debug_level: 1, debug: $stdout).basic_auth(@username, @password).request("PROPPATCH",diff --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 cbe90cf9d2d..0b41fc73def 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@@ -66,28 +66,28 @@ module Storages::Peripherals::StorageInteraction::Nextcloudprivatedef outbound_response(method:, relative_path:, payload:, token:)- response = Util.http(@uri).post(- Util.join_uri_path(@uri.path, relative_path),- payload.to_json,- {- 'Authorization' => "Bearer #{token.access_token}",- 'Accept' => 'application/json',- 'Content-Type' => 'application/json'- }- )- case response- when Net::HTTPSuccess+ response = Util+ .httpx+ .with(headers: { 'Authorization' => "Bearer #{token.access_token}",+ 'Accept' => 'application/json',+ 'Content-Type' => 'application/json' })+ .post(+ Util.join_uri_path(@uri, relative_path),+ json: payload+ )+ case response.status+ when 200# The nextcloud API returns a successful response with empty body if the authorization is missing or expiredif response.body.present?ServiceResult.success(- result: JSON.parse(response.body, object_class: OpenStruct) # rubocop:disable Style/OpenStructUse+ result: JSON.parse(response.body.to_s, object_class: OpenStruct) # rubocop:disable Style/OpenStructUse)elseUtil.error(:unauthorized, 'Outbound request not authorized!')end- when Net::HTTPNotFound+ when 404Util.error(:not_found, 'Outbound request destination not found!', response)- when Net::HTTPUnauthorized+ when 401Util.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/util.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rbindex 19acdbcb7a7..63c3868bfcb 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb@@ -73,12 +73,6 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Util)end- def http(uri)- http = Net::HTTP.new(uri.host, uri.port)- http.use_ssl = uri.scheme == 'https'- http- end-def httpxHTTPX.plugin(:basic_auth).plugin(:webdav)enddiff --git a/modules/storages/app/validator/nextcloud_application_credentials_validator.rb b/modules/storages/app/validator/nextcloud_application_credentials_validator.rbindex 8b029fd4872..70e544db5f8 100644--- a/modules/storages/app/validator/nextcloud_application_credentials_validator.rb+++ b/modules/storages/app/validator/nextcloud_application_credentials_validator.rb@@ -26,6 +26,8 @@# See COPYRIGHT and LICENSE files for more details.#++class NextcloudApplicationCredentialsValidator+ UTIL = Storages::Peripherals::StorageInteraction::Nextcloud::Util+attr_reader :contract, :uridef initialize(contract)@@ -36,29 +38,17 @@ class NextcloudApplicationCredentialsValidatordef callreturn unless contract.model.password_changed?- case make_http_head_request_from(build_http_head_request)- when Net::HTTPSuccess+ response = UTIL+ .httpx+ .basic_auth(contract.username, contract.password)+ .head(UTIL.join_uri_path(uri, "remote.php/dav"))+ case response.status+ when 200true- when Net::HTTPUnauthorized+ when 401contract.errors.add(:password, :invalid_password)elsecontract.errors.add(:password, :unknown_error)endend-- private-- def build_http_head_request- request = Net::HTTP::Head.new Storages::Peripherals::StorageInteraction::Nextcloud::Util- .join_uri_path(uri.path, "remote.php/dav")- request.initialize_http_header Storages::Peripherals::StorageInteraction::Nextcloud::Util- .basic_auth_header(contract.username, contract.password)- request- end-- def make_http_head_request_from(request)- Storages::Peripherals::StorageInteraction::Nextcloud::Util- .http(uri)- .request(request)- endend