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
[#56334] moved url builder to higher context
Eric Schubertccebe4e63c08
diff --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 764c4b4b0e3..aa8a038b827 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@@ -52,13 +52,10 @@ module Storagesenddef to_httpx_oauth_config- issuer = URI(StorageInteraction::RequestUrlBuilder.build(@storage,- "/index.php/apps/oauth2/api/v1")).normalize-StorageInteraction::AuthenticationStrategies::OAuthConfiguration.new(client_id: @oauth_client.client_id,client_secret: @oauth_client.client_secret,- issuer:,+ issuer: URI(UrlBuilder.url(@storage.uri, "/index.php/apps/oauth2/api/v1")).normalize,scope: [])end@@ -77,8 +74,8 @@ module Storagesscheme: uri.scheme,host: uri.host,port: uri.port,- authorization_endpoint: StorageInteraction::RequestUrlBuilder.path(uri.path, "/index.php/apps/oauth2/authorize"),- token_endpoint: StorageInteraction::RequestUrlBuilder.path(uri.path, "/index.php/apps/oauth2/api/v1/token")+ authorization_endpoint: UrlBuilder.path(uri.path, "/index.php/apps/oauth2/authorize"),+ token_endpoint: UrlBuilder.path(uri.path, "/index.php/apps/oauth2/api/v1/token"))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 5ea1cc9bccc..276a0b6f8d3 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@@ -51,10 +51,7 @@ module Storages.basic_auth(@username, @password).with(headers: { "OCS-APIRequest" => "true" }).post(- RequestUrlBuilder.build(@storage,- "ocs/v1.php/cloud/users",- user,- "groups"),+ UrlBuilder.url(@storage.uri, "ocs/v1.php/cloud/users", user, "groups"),form: { "groupid" => CGI.escapeURIComponent(group) })diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/auth_check_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/auth_check_query.rbindex 2ff3d4358db..69330d91b27 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/auth_check_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/auth_check_query.rb@@ -45,7 +45,7 @@ module Storagesdef call(auth_strategy:)Authentication[auth_strategy].call(storage: @storage, http_options: Util.ocs_api_request) do |http|- handle_response http.get(RequestUrlBuilder.build(@storage, "/ocs/v1.php/cloud/user"))+ handle_response http.get(UrlBuilder.url(@storage.uri, "/ocs/v1.php/cloud/user"))endenddiff --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 d8e0e50a791..f16d41e5997 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@@ -67,15 +67,8 @@ module Storagesenddef build_origin_urls(source_path:, destination_path:)- source_url = RequestUrlBuilder.build(@storage,- "remote.php/dav/files",- @storage.username,- source_path)-- destination_url = RequestUrlBuilder.build(@storage,- "remote.php/dav/files",- @storage.username,- destination_path)+ source_url = UrlBuilder.url(@storage.uri, "remote.php/dav/files", @storage.username, source_path)+ destination_url = UrlBuilder.url(@storage.uri, "remote.php/dav/files", @storage.username, destination_path){ source_url:, destination_url: }enddiff --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 6cd8cd90fcf..772bee9f1b5 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@@ -48,14 +48,12 @@ module Storages.on_failure { |error| return error }.result- path_prefix = RequestUrlBuilder.path(@storage.uri.path,- "remote.php/dav/files",- origin_user_id)- request_url = RequestUrlBuilder.build(@storage,- "remote.php/dav/files",- origin_user_id,- parent_location.path,- folder_name)+ path_prefix = UrlBuilder.path(@storage.uri.path, "remote.php/dav/files", origin_user_id)+ request_url = UrlBuilder.url(@storage.uri,+ "remote.php/dav/files",+ origin_user_id,+ parent_location.path,+ folder_name)create_folder_request(auth_strategy, request_url, path_prefix)enddiff --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 ab0490f32d3..f74c78fccf4 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@@ -61,8 +61,7 @@ module Storagesdef direct_download_request(auth_strategy:, file_link:)Authentication[auth_strategy].call(storage: @storage, http_options:) do |http|- result = handle_response http.post(RequestUrlBuilder.build(@storage,- "/ocs/v2.php/apps/dav/api/v1/direct"),+ result = handle_response http.post(UrlBuilder.url(@storage.uri, "/ocs/v2.php/apps/dav/api/v1/direct"),json: { fileId: file_link.origin_id })result.bind do |resp|@@ -96,7 +95,7 @@ module Storagesenddef download_link(token, origin_name)- RequestUrlBuilder.build(@storage, "index.php/apps/integration_openproject/direct", token, origin_name)+ UrlBuilder.url(@storage.uri, "index.php/apps/integration_openproject/direct", token, origin_name)enddef direct_download_token(body:)diff --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 83279f0f208..7671b70ac87 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@@ -71,7 +71,7 @@ module Storagesenddef file_info(http, file_id)- response = http.get(RequestUrlBuilder.build(@storage, FILE_INFO_PATH, file_id))+ response = http.get(UrlBuilder.url(@storage.uri, FILE_INFO_PATH, file_id))error_data = StorageErrorData.new(source: self.class, payload: response)case response@@ -140,7 +140,7 @@ module Storagesidx += prefix.length - 1- RequestUrlBuilder.path(file_path[idx..])+ UrlBuilder.path(file_path[idx..])endendenddiff --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 43e081719df..779c3d8e4c6 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@@ -63,7 +63,7 @@ module Storagesprivatedef files_info(http, file_ids)- response = http.post(RequestUrlBuilder.build(@storage, FILES_INFO_PATH), json: { fileIds: file_ids })+ response = http.post(UrlBuilder.url(@storage.uri, FILES_INFO_PATH), json: { fileIds: file_ids })error_data = StorageErrorData.new(source: self.class, payload: response)case response@@ -143,7 +143,7 @@ module Storages# in all supported versions of OpenProjectIntegation Nextcloud App.file_path << "/" if mimetype == "application/x-op-directory" && file_path[-1] != "/"- RequestUrlBuilder.path(file_path[idx..])+ UrlBuilder.path(file_path[idx..])endendenddiff --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 8a47b60059f..1b9ba3e9f2f 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@@ -46,9 +46,7 @@ module Storagesendorigin_user = origin_user_id(auth_strategy.user)- @location_prefix = RequestUrlBuilder.path(@storage.uri.path,- "remote.php/dav/files",- origin_user)+ @location_prefix = UrlBuilder.path(@storage.uri.path, "remote.php/dav/files", origin_user)result = make_request(auth_strategy:, folder:, user: auth_strategy.user)storage_files(result)@@ -62,10 +60,10 @@ module StoragesAuthentication[auth_strategy].call(storage: @storage,http_options: Util.webdav_request_with_depth(1)) do |http|response = http.request("PROPFIND",- RequestUrlBuilder.build(@storage,- "remote.php/dav/files",- origin_user,- folder.path),+ UrlBuilder.url(@storage.uri,+ "remote.php/dav/files",+ origin_user,+ folder.path),xml: requested_properties)handle_response(response)enddiff --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 55c319bb6cb..4249b21f643 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@@ -49,8 +49,8 @@ module Storages::Peripherals::StorageInteraction::Nextcloud.basic_auth(@username, @password).with(headers: { "OCS-APIRequest" => "true" }).get(- Storages::Peripherals::StorageInteraction::RequestUrlBuilder.build(- @storage,+ Storages::UrlBuilder.url(+ @storage.uri,"ocs/v1.php/cloud/groups",CGI.escapeURIComponent(group))diff --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 f09231b839e..c6021441f8f 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@@ -47,7 +47,7 @@ module StoragesAuthentication[auth_strategy].call(storage: @storage) do |http|handle_response http.delete(- RequestUrlBuilder.build(@storage, "remote.php/dav/files", origin_user_id, location)+ UrlBuilder.url(@storage.uri, "remote.php/dav/files", origin_user_id, location))endenddiff --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 311d2d29564..ad5a22c36db 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@@ -73,10 +73,7 @@ module Storagesenddef call(http:, username:, path:, props:)- request_uri = RequestUrlBuilder.build(@storage,- "remote.php/dav/files",- username,- path)+ request_uri = UrlBuilder.url(@storage.uri, "remote.php/dav/files", username, path)response = http.request(:propfind, request_uri, xml: request_body(props))handle_response(response, username)@@ -130,7 +127,7 @@ module Storagesdef resource_path(section, username)path = CGI.unescape(section.xpath("d:href").text.strip)- .gsub!(RequestUrlBuilder.path(@storage.uri.path, "remote.php/dav/files", username), "")+ .gsub!(UrlBuilder.path(@storage.uri.path, "remote.php/dav/files", username), "")path.end_with?("/") && path.length > 1 ? path.chop : pathenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query_legacy.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query_legacy.rbindex 014e6cf16f6..a080512170f 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query_legacy.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query_legacy.rb@@ -98,10 +98,7 @@ module Storages.with(headers: { "Depth" => depth }).request("PROPFIND",- RequestUrlBuilder.build(@storage,- "remote.php/dav/files",- @username,- path),+ UrlBuilder.url(@storage.uri, "remote.php/dav/files", @username, path),xml: body)@@ -112,7 +109,7 @@ module Storagesdoc = Nokogiri::XML(response.body.to_s)result = {}doc.xpath("/d:multistatus/d:response").each do |resource_section|- source_path = RequestUrlBuilder.path(@storage.uri.path, "/remote.php/dav/files", @username)+ source_path = UrlBuilder.path(@storage.uri.path, "/remote.php/dav/files", @username)resource = CGI.unescape(resource_section.xpath("d:href").text.strip).gsub!(source_path, "")result[resource] = {}diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rbindex 5ad857f0a8c..1f9bfe317b9 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rb@@ -44,7 +44,7 @@ module Storages# rubocop:disable Lint/UnusedMethodArgumentdef call(auth_strategy:, file_id:, open_location: false)location_flag = open_location ? 0 : 1- url = RequestUrlBuilder.build(@storage, "index.php/f/#{file_id}") + "?openfile=#{location_flag}"+ url = UrlBuilder.url(@storage.uri, "index.php/f/#{file_id}") + "?openfile=#{location_flag}"ServiceResult.success(result: url)enddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_storage_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_storage_query.rbindex 79c97bcd059..5e63aac427a 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_storage_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_storage_query.rb@@ -43,7 +43,7 @@ module Storages# rubocop:disable Lint/UnusedMethodArgumentdef call(auth_strategy:)- ServiceResult.success(result: RequestUrlBuilder.build(@storage, "index.php/apps/files"))+ ServiceResult.success(result: UrlBuilder.url(@storage.uri, "index.php/apps/files"))end# rubocop:enable Lint/UnusedMethodArgumentdiff --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 ad865088ba8..f2799d62428 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@@ -48,8 +48,8 @@ module Storages::Peripherals::StorageInteraction::Nextcloud.basic_auth(@username, @password).with(headers: { "OCS-APIRequest" => "true" }).delete(- Storages::Peripherals::StorageInteraction::RequestUrlBuilder.build(- @storage,+ Storages::UrlBuilder.url(+ @storage.uri,"ocs/v1.php/cloud/users",user,"groups"diff --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 2b025793110..865c0ad18ed 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@@ -61,14 +61,15 @@ module Storagesprivatedef make_request(auth_strategy, user, file_info, name)- source_path = RequestUrlBuilder.build(@storage,- "remote.php/dav/files",- user,- CGI.unescape(file_info.location))- destination = RequestUrlBuilder.path(@storage.uri.path,- "remote.php/dav/files",- user,- CGI.unescape(target_path(file_info, name)))+ source_path = UrlBuilder.url(@storage.uri,+ "remote.php/dav/files",+ user,+ CGI.unescape(file_info.location))++ destination = UrlBuilder.path(@storage.uri.path,+ "remote.php/dav/files",+ user,+ CGI.unescape(target_path(file_info, name)))Authentication[auth_strategy].call(storage: @storage) do |http|handle_response http.request("MOVE", source_path, headers: { "Destination" => destination })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 6f09f7ed991..eed0d4b2855 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@@ -85,8 +85,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud.basic_auth(@username, @password).request("PROPPATCH",- Storages::Peripherals::StorageInteraction::RequestUrlBuilder- .build(@storage, "remote.php/dav/files", @username, path),+ Storages::UrlBuilder.url(@storage.uri, "remote.php/dav/files", @username, path),xml: body)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 bf66441be32..2a8fd6f3fcc 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@@ -58,11 +58,11 @@ module Storagesprivatedef base_uri- RequestUrlBuilder.build(@storage, "index.php/apps/integration_openproject/direct-upload-token")+ UrlBuilder.url(@storage.uri, "index.php/apps/integration_openproject/direct-upload-token")enddef upload_base_uri- RequestUrlBuilder.build(@storage, "index.php/apps/integration_openproject/direct-upload")+ UrlBuilder.url(@storage.uri, "index.php/apps/integration_openproject/direct-upload")enddef upload_data_failurediff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/request_url_builder.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/request_url_builder.rbdeleted file mode 100644index e13c98f33ff..00000000000--- a/modules/storages/app/common/storages/peripherals/storage_interaction/request_url_builder.rb+++ /dev/null@@ -1,77 +0,0 @@-# frozen_string_literal:true--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2024 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See COPYRIGHT and LICENSE files for more details.-#++--module Storages- module Peripherals- module StorageInteraction- class RequestUrlBuilder- class << self- def build(storage, *path_fragments)- host_uri = storage.uri-- URI.join(host_uri.origin,- ensure_sub_path(host_uri.path),- *split_and_escape(path_fragments))- .to_s- end-- def path(*path_fragments)- URI.join(URI("https://drop.me"), *split_and_escape(path_fragments)).path- end-- private-- def ensure_sub_path(fragment)- fragment.ends_with?("/") ? fragment : "#{fragment}/"- end-- def split_and_escape(fragments)- return fragments if fragments.empty?-- single_fragments = fragments- .map { |f| f.split("/") }- .flatten- .reject(&:empty?)- .each { |f| ensure_unescaped_fragments(f) }- .map { |f| CGI.escapeURIComponent(f) }-- single_fragments[..-2]- .map { |f| "#{f}/" }- .push(single_fragments.last)- end-- def ensure_unescaped_fragments(fragment)- raise ArgumentError, "URL-escaped character found: #{fragment}" if CGI.unescape(fragment) != fragment- end- end- end- end- end-enddiff --git a/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.rb b/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.rbindex ce7b1fee7b1..cd1eda0c8e2 100644--- a/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.rb+++ b/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.rb@@ -86,19 +86,5 @@ module Storages::Admin::Formsdef default_form_urladmin_settings_storage_automatically_managed_project_folders_path(storage)end-- def storage_provider_credentials_copy_instructions- "#{I18n.t('storages.instructions.copy_from')}: #{provider_credentials_instructions_link}".html_safe- end-- def provider_credentials_instructions_link- render(- Primer::Beta::Link.new(- href: Storages::Peripherals::StorageInteraction::RequestUrlBuilder.build(storage,- "settings/admin/openproject"),- target: "_blank"- )- ) { I18n.t("storages.instructions.#{storage.short_provider_type}.integration") }- endendenddiff --git a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rbindex 57be26c54ef..e7ee84b98c4 100644--- a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb+++ b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb@@ -64,8 +64,7 @@ module Storages::Admin::Formsenddef nextcloud_integration_link(target: "_blank")- href = Storages::Peripherals::StorageInteraction::RequestUrlBuilder- .build(storage, "settings/admin/openproject")+ href = Storages::UrlBuilder.url(storage.uri, "settings/admin/openproject")render(Primer::Beta::Link.new(href:, target:)) { I18n.t("storages.instructions.nextcloud.integration") }enddiff --git a/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rb b/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rbindex 5b37b6e92a4..d5be8c22042 100644--- a/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rb+++ b/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rb@@ -46,10 +46,7 @@ module Storages::Admindef oauth_application_details_linkrender(Primer::Beta::Link.new(- href: ::Storages::Peripherals::StorageInteraction::RequestUrlBuilder.build(- storage,- "settings/admin/openproject"- ),+ href: ::Storages::UrlBuilder.url(storage.uri, "settings/admin/openproject"),target: "_blank")) { I18n.t("storages.instructions.oauth_application_details_link_text") }diff --git a/modules/storages/app/forms/storages/admin/managed_project_folders/application_password_input.rb b/modules/storages/app/forms/storages/admin/managed_project_folders/application_password_input.rbindex 78b72512b35..fecc2dc137b 100644--- a/modules/storages/app/forms/storages/admin/managed_project_folders/application_password_input.rb+++ b/modules/storages/app/forms/storages/admin/managed_project_folders/application_password_input.rb@@ -55,8 +55,7 @@ module Storages::Admin::ManagedProjectFoldersdef provider_type_linkrender(Primer::Beta::Link.new(- href: Storages::Peripherals::StorageInteraction::RequestUrlBuilder.build(@storage,- "settings/admin/openproject"),+ href: Storages::UrlBuilder.url(@storage.uri, "settings/admin/openproject"),target: "_blank")) { I18n.t("storages.instructions.#{@storage.short_provider_type}.integration") }diff --git a/modules/storages/app/helpers/storages/url_builder.rb b/modules/storages/app/helpers/storages/url_builder.rbnew file mode 100644index 00000000000..41e1d861558--- /dev/null+++ b/modules/storages/app/helpers/storages/url_builder.rb@@ -0,0 +1,71 @@+# frozen_string_literal:true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module Storages+ class UrlBuilder+ class << self+ def url(uri, *path_fragments)+ URI.join(uri.origin,+ ensure_sub_path(uri.path),+ *split_and_escape(path_fragments))+ .to_s+ end++ def path(*path_fragments)+ URI.join(URI("https://drop.me"), *split_and_escape(path_fragments)).path+ end++ private++ def ensure_sub_path(fragment)+ fragment.ends_with?("/") ? fragment : "#{fragment}/"+ end++ def split_and_escape(fragments)+ return fragments if fragments.empty?++ single_fragments = fragments+ .map { |f| f.split("/") }+ .flatten+ .reject(&:empty?)+ .each { |f| ensure_unescaped_fragments(f) }+ .map { |f| CGI.escapeURIComponent(f) }++ single_fragments[..-2]+ .map { |f| "#{f}/" }+ .push(single_fragments.last)+ end++ def ensure_unescaped_fragments(fragment)+ raise ArgumentError, "URL-escaped character found: #{fragment}" if CGI.unescape(fragment) != fragment+ end+ end+ end+enddiff --git a/modules/storages/app/models/storages/project_storage.rb b/modules/storages/app/models/storages/project_storage.rbindex aa1420da726..3575337a0d3 100644--- a/modules/storages/app/models/storages/project_storage.rb+++ b/modules/storages/app/models/storages/project_storage.rb@@ -70,7 +70,7 @@ module Storagesenddef project_folder_path_escaped- escape_path(managed_project_folder_path)+ UrlBuilder.path(managed_project_folder_path)enddef file_inside_project_folder?(escaped_file_path)@@ -122,9 +122,5 @@ module Storages(project_folder_automatic? && !user.allowed_in_project?(:read_files, project)) ||project_folder_id.blank?end-- def escape_path(path)- Peripherals::StorageInteraction::RequestUrlBuilder.path(path)- endendenddiff --git a/modules/storages/app/validator/nextcloud_application_credentials_validator.rb b/modules/storages/app/validator/nextcloud_application_credentials_validator.rbindex 7deae539322..74cf924e09c 100644--- a/modules/storages/app/validator/nextcloud_application_credentials_validator.rb+++ b/modules/storages/app/validator/nextcloud_application_credentials_validator.rb@@ -26,8 +26,6 @@# See COPYRIGHT and LICENSE files for more details.#++class NextcloudApplicationCredentialsValidator- BUILDER = Storages::Peripherals::StorageInteraction::RequestUrlBuilder-attr_reader :contract, :uridef initialize(contract)@@ -41,7 +39,7 @@ class NextcloudApplicationCredentialsValidatorresponse = OpenProject.httpx.basic_auth(contract.username, contract.password)- .head(BUILDER.build(contract.model, "remote.php/dav"))+ .head(Storages::UrlBuilder.url(contract.model.uri, "remote.php/dav"))case responsein { status: 200..299 }truediff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/request_url_builder_spec.rb b/modules/storages/spec/common/storages/url_builder_spec.rbsimilarity index 65%rename from modules/storages/spec/common/storages/peripherals/storage_interaction/request_url_builder_spec.rbrename to modules/storages/spec/common/storages/url_builder_spec.rbindex 657213f6c27..4a4291194ce 100644--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/request_url_builder_spec.rb+++ b/modules/storages/spec/common/storages/url_builder_spec.rb@@ -30,31 +30,31 @@require "spec_helper"-RSpec.describe Storages::Peripherals::StorageInteraction::RequestUrlBuilder do- describe "build" do+RSpec.describe Storages::UrlBuilder do+ describe "url" docontext "if storage is of Nextcloud provider type" docontext "with a standard host url" dolet(:storage) { create(:nextcloud_storage, host: "https://example.com/") }it "returns the correct request URL" do- expect(described_class.build(storage, "/path/")).to eq("https://example.com/path")- expect(described_class.build(storage, "/path")).to eq("https://example.com/path")- expect(described_class.build(storage, "path/")).to eq("https://example.com/path")- expect(described_class.build(storage, "path")).to eq("https://example.com/path")+ expect(described_class.url(storage.uri, "/path/")).to eq("https://example.com/path")+ expect(described_class.url(storage.uri, "/path")).to eq("https://example.com/path")+ expect(described_class.url(storage.uri, "path/")).to eq("https://example.com/path")+ expect(described_class.url(storage.uri, "path")).to eq("https://example.com/path")- expect(described_class.build(storage, "path", "/another/fragment/"))+ expect(described_class.url(storage.uri, "path", "/another/fragment/")).to eq("https://example.com/path/another/fragment")- expect(described_class.build(storage, "/path/", "/another/fragment/"))+ expect(described_class.url(storage.uri, "/path/", "/another/fragment/")).to eq("https://example.com/path/another/fragment")- expect(described_class.build(storage, "/path/", "another/fragment"))+ expect(described_class.url(storage.uri, "/path/", "another/fragment")).to eq("https://example.com/path/another/fragment")- expect(described_class.build(storage, "/path/", "/another/", "/fragment/"))+ expect(described_class.url(storage.uri, "/path/", "/another/", "/fragment/")).to eq("https://example.com/path/another/fragment")- expect(described_class.build(storage, "path", "//with-double-slash/"))+ expect(described_class.url(storage.uri, "path", "//with-double-slash/")).to eq("https://example.com/path/with-double-slash")- expect(described_class.build(storage, "path", "new folder/stærforge"))+ expect(described_class.url(storage.uri, "path", "new folder/stærforge")).to eq("https://example.com/path/new%20folder/st%C3%A6rforge")endend@@ -63,8 +63,8 @@ RSpec.describe Storages::Peripherals::StorageInteraction::RequestUrlBuilder dolet(:storage) { create(:nextcloud_storage, host: "https://example.com") }it "returns the correct request URL" do- expect(described_class.build(storage, "/path/")).to eq("https://example.com/path")- expect(described_class.build(storage, "path")).to eq("https://example.com/path")+ expect(described_class.url(storage.uri, "/path/")).to eq("https://example.com/path")+ expect(described_class.url(storage.uri, "path")).to eq("https://example.com/path")endend@@ -72,8 +72,8 @@ RSpec.describe Storages::Peripherals::StorageInteraction::RequestUrlBuilder dolet(:storage) { create(:nextcloud_storage, host: "https://example.com/html/") }it "returns the correct request URL" do- expect(described_class.build(storage, "/path/")).to eq("https://example.com/html/path")- expect(described_class.build(storage, "path")).to eq("https://example.com/html/path")+ expect(described_class.url(storage.uri, "/path/")).to eq("https://example.com/html/path")+ expect(described_class.url(storage.uri, "path")).to eq("https://example.com/html/path")endend@@ -81,8 +81,8 @@ RSpec.describe Storages::Peripherals::StorageInteraction::RequestUrlBuilder dolet(:storage) { create(:nextcloud_storage, host: "https://example.com/html") }it "returns the correct request URL" do- expect(described_class.build(storage, "/path/")).to eq("https://example.com/html/path")- expect(described_class.build(storage, "path")).to eq("https://example.com/html/path")+ expect(described_class.url(storage.uri, "/path/")).to eq("https://example.com/html/path")+ expect(described_class.url(storage.uri, "path")).to eq("https://example.com/html/path")endendend@@ -91,12 +91,12 @@ RSpec.describe Storages::Peripherals::StorageInteraction::RequestUrlBuilder dolet(:storage) { create(:one_drive_storage) }it "returns the correct request URL" do- expect(described_class.build(storage, "/path/")).to eq("https://graph.microsoft.com/path")- expect(described_class.build(storage, "/path")).to eq("https://graph.microsoft.com/path")- expect(described_class.build(storage, "path/")).to eq("https://graph.microsoft.com/path")- expect(described_class.build(storage, "path")).to eq("https://graph.microsoft.com/path")+ expect(described_class.url(storage.uri, "/path/")).to eq("https://graph.microsoft.com/path")+ expect(described_class.url(storage.uri, "/path")).to eq("https://graph.microsoft.com/path")+ expect(described_class.url(storage.uri, "path/")).to eq("https://graph.microsoft.com/path")+ expect(described_class.url(storage.uri, "path")).to eq("https://graph.microsoft.com/path")- expect(described_class.build(storage, "path", "/to/", "/request"))+ expect(described_class.url(storage.uri, "path", "/to/", "/request")).to eq("https://graph.microsoft.com/path/to/request")endend@@ -105,7 +105,7 @@ RSpec.describe Storages::Peripherals::StorageInteraction::RequestUrlBuilder dolet(:storage) { create(:nextcloud_storage) }it "raises an exception" do- expect { described_class.build(storage, "/path/", "/i%20am%20escaped/") }.to raise_error(ArgumentError)+ expect { described_class.url(storage.uri, "/path/", "/i%20am%20escaped/") }.to raise_error(ArgumentError)endend@@ -113,7 +113,7 @@ RSpec.describe Storages::Peripherals::StorageInteraction::RequestUrlBuilder dolet(:storage) { create(:nextcloud_storage, host: "https://example.com/html/") }it "returns only the storage uri" do- expect(described_class.build(storage)).to eq("https://example.com/html/")+ expect(described_class.url(storage.uri)).to eq("https://example.com/html/")endendend@@ -132,5 +132,11 @@ RSpec.describe Storages::Peripherals::StorageInteraction::RequestUrlBuilder doexpect(described_class.path("/path/", "/new folder/stærforge/")).to eq("/path/new%20folder/st%C3%A6rforge")end++ context "if a fragment with an url escaped character is given" do+ it "raises an error" do+ expect { described_class.path("/path/", "/i%20am%20escaped/") }.to raise_error(ArgumentError)+ end+ endendend