Skip to content

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

[#56334] replace nextcloud path and url building

Eric Schubert6a1db4eb60fb
diff --git a/modules/storages/app/common/storages/peripherals/managed_folder_identifier/nextcloud.rb b/modules/storages/app/common/storages/peripherals/managed_folder_identifier/nextcloud.rb
index 54aa02541a3..7e6be978d68 100644
--- a/modules/storages/app/common/storages/peripherals/managed_folder_identifier/nextcloud.rb
+++ b/modules/storages/app/common/storages/peripherals/managed_folder_identifier/nextcloud.rb
@@ -11,7 +11,7 @@ module Storages
end
def path
- "#{@storage.group_folder}/#{@project.name.tr('/', '|')} (#{@project.id})/"
+ "/#{@storage.group_folder}/#{@project.name.tr('/', '|')} (#{@project.id})/"
end
def location
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.rb
index 191f49cdd47..764c4b4b0e3 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
@@ -38,7 +38,7 @@ module Storages
# rubocop:disable Lint/MissingSuper
def initialize(storage)
- @uri = storage.uri
+ @storage = storage
raise(ArgumentError, "Storage must have configured OAuth client credentials") if storage.oauth_client.blank?
@@ -52,10 +52,13 @@ module Storages
end
def 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: URI(Util.join_uri_path(@uri, "/index.php/apps/oauth2/api/v1")).normalize,
+ issuer:,
scope: []
)
end
@@ -65,15 +68,17 @@ module Storages
end
def basic_rack_oauth_client
+ uri = @storage.uri
+
Rack::OAuth2::Client.new(
identifier: @oauth_client.client_id,
secret: @oauth_client.client_secret,
redirect_uri: @oauth_client.redirect_uri,
- scheme: @uri.scheme,
- host: @uri.host,
- port: @uri.port,
- authorization_endpoint: Util.join_uri_path(@uri.path, "/index.php/apps/oauth2/authorize"),
- token_endpoint: Util.join_uri_path(@uri.path, "/index.php/apps/oauth2/api/v1/token")
+ scheme: 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")
)
end
end
diff --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.rb
index 6de0ec796fe..5ea1cc9bccc 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
@@ -28,68 +28,72 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Storages::Peripherals::StorageInteraction::Nextcloud
- class AddUserToGroupCommand
- def initialize(storage)
- @uri = storage.uri
- @username = storage.username
- @password = storage.password
- @group = storage.group
- end
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module Nextcloud
+ class AddUserToGroupCommand
+ def initialize(storage)
+ @storage = storage
+ @username = storage.username
+ @password = storage.password
+ @group = storage.group
+ end
- # rubocop:disable Metrics/AbcSize
- def self.call(storage:, user:, group: storage.group)
- new(storage).call(user:, group:)
- end
+ # rubocop:disable Metrics/AbcSize
+ def self.call(storage:, user:, group: storage.group)
+ new(storage).call(user:, group:)
+ end
- def call(user:, group: @group)
- response = OpenProject
- .httpx
- .basic_auth(@username, @password)
- .with(headers: { "OCS-APIRequest" => "true" })
- .post(
- Util.join_uri_path(
- @uri,
- "ocs/v1.php/cloud/users",
- CGI.escapeURIComponent(user),
- "groups"
- ),
- form: { "groupid" => CGI.escapeURIComponent(group) }
- )
+ def call(user:, group: @group)
+ response = OpenProject
+ .httpx
+ .basic_auth(@username, @password)
+ .with(headers: { "OCS-APIRequest" => "true" })
+ .post(
+ RequestUrlBuilder.build(@storage,
+ "ocs/v1.php/cloud/users",
+ user,
+ "groups"),
+ form: { "groupid" => CGI.escapeURIComponent(group) }
+ )
- error_data = Storages::StorageErrorData.new(source: self.class, payload: response)
+ error_data = StorageErrorData.new(source: self.class, payload: response)
- case response
- in { status: 200..299 }
- statuscode = Nokogiri::XML(response.body.to_s).xpath("/ocs/meta/statuscode").text
+ case response
+ in { status: 200..299 }
+ statuscode = Nokogiri::XML(response.body.to_s).xpath("/ocs/meta/statuscode").text
- case statuscode
- when "100"
- ServiceResult.success(message: "User has been added successfully")
- when "101"
- Util.error(:error, "No group specified", error_data)
- when "102"
- Util.error(:error, "Group does not exist", error_data)
- when "103"
- Util.error(:error, "User does not exist", error_data)
- when "104"
- Util.error(:error, "Insufficient privileges", error_data)
- when "105"
- Util.error(:error, "Failed to add user to group", error_data)
+ case statuscode
+ when "100"
+ ServiceResult.success(message: "User has been added successfully")
+ when "101"
+ Util.error(:error, "No group specified", error_data)
+ when "102"
+ Util.error(:error, "Group does not exist", error_data)
+ when "103"
+ Util.error(:error, "User does not exist", error_data)
+ when "104"
+ Util.error(:error, "Insufficient privileges", error_data)
+ when "105"
+ Util.error(:error, "Failed to add user to group", error_data)
+ end
+ in { status: 405 }
+ Util.error(:not_allowed, "Outbound request method not allowed", error_data)
+ in { status: 401 }
+ Util.error(:not_found, "Outbound request destination not found", error_data)
+ in { status: 404 }
+ Util.error(:unauthorized, "Outbound request not authorized", error_data)
+ in { status: 409 }
+ Util.error(:conflict, Util.error_text_from_response(response), error_data)
+ else
+ Util.error(:error, "Outbound request failed", error_data)
+ end
+ end
+
+ # rubocop:enable Metrics/AbcSize
end
- in { status: 405 }
- Util.error(:not_allowed, "Outbound request method not allowed", error_data)
- in { status: 401 }
- Util.error(:not_found, "Outbound request destination not found", error_data)
- in { status: 404 }
- Util.error(:unauthorized, "Outbound request not authorized", error_data)
- in { status: 409 }
- Util.error(:conflict, Util.error_text_from_response(response), error_data)
- else
- Util.error(:error, "Outbound request failed", error_data)
end
end
-
- # rubocop:enable Metrics/AbcSize
end
end
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.rb
index a2d33060540..2ff3d4358db 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
@@ -33,8 +33,6 @@ module Storages
module StorageInteraction
module Nextcloud
class AuthCheckQuery
- Auth = ::Storages::Peripherals::StorageInteraction::Authentication
-
using ServiceResultRefinements
def self.call(storage:, auth_strategy:)
@@ -46,8 +44,8 @@ module Storages
end
def call(auth_strategy:)
- Auth[auth_strategy].call(storage: @storage, http_options: Util.ocs_api_request) do |http|
- handle_response http.get(Util.join_uri_path(@storage.uri, "/ocs/v1.php/cloud/user"))
+ 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"))
end
end
@@ -58,10 +56,10 @@ module Storages
in { status: 200..299 }
ServiceResult.success
in { status: 401 }
- ServiceResult.failure(result: :unauthorized, errors: ::Storages::StorageError.new(code: :unauthorized))
+ ServiceResult.failure(result: :unauthorized, errors: StorageError.new(code: :unauthorized))
else
- data = ::Storages::StorageErrorData.new(source: self.class, payload: response)
- ServiceResult.failure(result: :error, errors: ::Storages::StorageError.new(code: :error, data:))
+ data = StorageErrorData.new(source: self.class, payload: response)
+ ServiceResult.failure(result: :error, errors: StorageError.new(code: :error, data:))
end
end
end
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.rb
index 6caf5d2cf20..d8e0e50a791 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,21 +67,15 @@ module Storages
end
def build_origin_urls(source_path:, destination_path:)
- escaped_username = CGI.escapeURIComponent(@storage.username)
-
- source_url = Util.join_uri_path(
- @storage.uri,
- "remote.php/dav/files",
- escaped_username,
- Util.escape_path(source_path)
- )
-
- destination_url = Util.join_uri_path(
- @storage.uri,
- "remote.php/dav/files",
- escaped_username,
- Util.escape_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:, destination_url: }
end
@@ -144,9 +138,11 @@ module Storages
end
def get_folder_id(destination_path)
- Registry
- .resolve("#{@storage.short_provider_type}.queries.file_ids")
- .call(storage: @storage, path: destination_path).map { |result| @data.with(id: result[destination_path]["fileid"]) }
+ call = Registry
+ .resolve("#{@storage.short_provider_type}.queries.file_ids")
+ .call(storage: @storage, path: destination_path)
+
+ call.map { |result| @data.with(id: result[destination_path]["fileid"]) }
end
end
end
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.rb
index 340b7e1008e..6cd8cd90fcf 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
@@ -45,15 +45,17 @@ module Storages
def call(auth_strategy:, folder_name:, parent_location:)
origin_user_id = Util.origin_user_id(caller: self.class, storage: @storage, auth_strategy:)
- if origin_user_id.failure?
- return origin_user_id
- end
-
- folder_path = Util.join_uri_path(parent_location, folder_name)
- path_prefix = URI.parse(Util.join_uri_path(base_uri, CGI.escapeURIComponent(origin_user_id.result))).path
- request_url = Util.join_uri_path(base_uri,
- CGI.escapeURIComponent(origin_user_id.result),
- Util.escape_path(folder_path))
+ .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)
create_folder_request(auth_strategy, request_url, path_prefix)
end
@@ -132,8 +134,6 @@ module Storages
end
# rubocop:enable Metrics/AbcSize
-
- def base_uri = Util.join_uri_path(@storage.uri, "remote.php", "dav", "files")
end
end
end
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.rb
index b578af94fbd..ab0490f32d3 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
@@ -28,107 +28,112 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Storages::Peripherals::StorageInteraction::Nextcloud
- class DownloadLinkQuery
- using Storages::Peripherals::ServiceResultRefinements
-
- Auth = ::Storages::Peripherals::StorageInteraction::Authentication
-
- def self.call(storage:, auth_strategy:, file_link:)
- new(storage).call(auth_strategy:, file_link:)
- end
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module Nextcloud
+ class DownloadLinkQuery
+ using ServiceResultRefinements
+
+ def self.call(storage:, auth_strategy:, file_link:)
+ new(storage).call(auth_strategy:, file_link:)
+ end
- def initialize(storage)
- @storage = storage
- end
+ def initialize(storage)
+ @storage = storage
+ end
- def call(auth_strategy:, file_link:)
- if file_link.nil?
- return failure(code: :error, payload: nil, log_message: "File link can not be nil.")
- end
+ def call(auth_strategy:, file_link:)
+ if file_link.nil?
+ return failure(code: :error, payload: nil, log_message: "File link can not be nil.")
+ end
- direct_download_request(auth_strategy:, file_link:)
- .bind { |response_body| direct_download_token(body: response_body) }
- .map { |download_token| download_link(download_token, file_link.origin_name) }
- end
+ direct_download_request(auth_strategy:, file_link:)
+ .bind { |response_body| direct_download_token(body: response_body) }
+ .map { |download_token| download_link(download_token, file_link.origin_name) }
+ end
- private
+ private
- def http_options
- Util.ocs_api_request.deep_merge(Util.accept_json)
- end
+ def http_options
+ Util.ocs_api_request.deep_merge(Util.accept_json)
+ end
- def direct_download_request(auth_strategy:, file_link:)
- Auth[auth_strategy].call(storage: @storage, http_options:) do |http|
- result = handle_response http.post(Util.join_uri_path(@storage.uri, "/ocs/v2.php/apps/dav/api/v1/direct"),
- json: { fileId: file_link.origin_id })
-
- result.bind do |resp|
- # The nextcloud API returns a successful response with empty body if the authorization is missing or expired
- if resp.body.blank?
- Util.error(:unauthorized, "Outbound request not authorized!")
- else
- ServiceResult.success(result: resp.body.to_s)
+ def 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"),
+ json: { fileId: file_link.origin_id })
+
+ result.bind do |resp|
+ # The nextcloud API returns a successful response with empty body if the authorization is missing or expired
+ if resp.body.blank?
+ Util.error(:unauthorized, "Outbound request not authorized!")
+ else
+ ServiceResult.success(result: resp.body.to_s)
+ end
+ end
+ end
end
- end
- end
- end
- def handle_response(response)
- case response
- in { status: 200..299 }
- ServiceResult.success(result: response)
- in { status: 404 }
- failure(code: :not_found,
- payload: response.json(symbolize_keys: true),
- log_message: "Outbound request destination not found!")
- in { status: 401 }
- failure(code: :unauthorized,
- payload: response.json(symbolize_keys: true),
- log_message: "Outbound request not authorized!")
- else
- failure(code: :error,
- payload: response.json(symbolize_keys: true),
- log_message: "Outbound request failed with unknown error!")
- end
- end
+ def handle_response(response)
+ case response
+ in { status: 200..299 }
+ ServiceResult.success(result: response)
+ in { status: 404 }
+ failure(code: :not_found,
+ payload: response.json(symbolize_keys: true),
+ log_message: "Outbound request destination not found!")
+ in { status: 401 }
+ failure(code: :unauthorized,
+ payload: response.json(symbolize_keys: true),
+ log_message: "Outbound request not authorized!")
+ else
+ failure(code: :error,
+ payload: response.json(symbolize_keys: true),
+ log_message: "Outbound request failed with unknown error!")
+ end
+ end
- def download_link(token, origin_name)
- Util.join_uri_path(@storage.uri, "index.php/apps/integration_openproject/direct", token, CGI.escape(origin_name))
- end
+ def download_link(token, origin_name)
+ RequestUrlBuilder.build(@storage, "index.php/apps/integration_openproject/direct", token, origin_name)
+ end
- def direct_download_token(body:)
- token = parse_direct_download_token(body:)
- if token.blank?
- return Util.error(:error, "Received unexpected json response", body)
- end
+ def direct_download_token(body:)
+ token = parse_direct_download_token(body:)
+ if token.blank?
+ return Util.error(:error, "Received unexpected json response", body)
+ end
- ServiceResult.success(result: token)
- end
+ ServiceResult.success(result: token)
+ end
- def parse_direct_download_token(body:)
- begin
- json = JSON.parse(body)
- rescue JSON::ParserError
- return nil
- end
+ def parse_direct_download_token(body:)
+ begin
+ json = JSON.parse(body)
+ rescue JSON::ParserError
+ return nil
+ end
- direct_download_url = json.dig("ocs", "data", "url")
- return nil if direct_download_url.blank?
+ direct_download_url = json.dig("ocs", "data", "url")
+ return nil if direct_download_url.blank?
- path = URI.parse(direct_download_url).path
- return nil if path.blank?
+ path = URI.parse(direct_download_url).path
+ return nil if path.blank?
- path.split("/").last
- end
+ path.split("/").last
+ end
- def failure(code:, payload:, log_message:)
- ServiceResult.failure(
- result: code,
- errors: ::Storages::StorageError.new(code:,
- data: ::Storages::StorageErrorData.new(source: self.class, payload:),
- log_message:)
- )
+ def failure(code:, payload:, log_message:)
+ ServiceResult.failure(
+ result: code,
+ errors: StorageError.new(code:,
+ data: StorageErrorData.new(source: self.class, payload:),
+ log_message:)
+ )
+ end
+ end
+ end
end
end
end
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.rb
index ec7c8824d4d..83279f0f208 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 Storages
end
def file_info(http, file_id)
- response = http.get(Util.join_uri_path(@storage.uri, FILE_INFO_PATH, file_id))
+ response = http.get(RequestUrlBuilder.build(@storage, FILE_INFO_PATH, file_id))
error_data = StorageErrorData.new(source: self.class, payload: response)
case response
@@ -140,7 +140,7 @@ module Storages
idx += prefix.length - 1
- Util.escape_path(file_path[idx..]).chomp("/")
+ RequestUrlBuilder.path(file_path[idx..])
end
end
end
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.rb
index afbd8acb933..43e081719df 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
@@ -28,119 +28,125 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Storages::Peripherals::StorageInteraction::Nextcloud
- class FilesInfoQuery
- using Storages::Peripherals::ServiceResultRefinements
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module Nextcloud
+ class FilesInfoQuery
+ using ServiceResultRefinements
- FILES_INFO_PATH = "ocs/v1.php/apps/integration_openproject/filesinfo"
- Auth = ::Storages::Peripherals::StorageInteraction::Authentication
+ FILES_INFO_PATH = "ocs/v1.php/apps/integration_openproject/filesinfo"
- def self.call(storage:, auth_strategy:, file_ids:)
- new(storage).call(auth_strategy:, file_ids:)
- end
-
- def initialize(storage)
- @storage = storage
- end
+ def self.call(storage:, auth_strategy:, file_ids:)
+ new(storage).call(auth_strategy:, file_ids:)
+ end
- def call(auth_strategy:, file_ids:)
- if file_ids.nil?
- return Util.error(:error, "File IDs can not be nil", file_ids)
- end
+ def initialize(storage)
+ @storage = storage
+ end
- if file_ids.empty?
- return ServiceResult.success(result: [])
- end
+ def call(auth_strategy:, file_ids:)
+ if file_ids.nil?
+ return Util.error(:error, "File IDs can not be nil", file_ids)
+ end
- http_options = Util.ocs_api_request.deep_merge(Util.accept_json)
- Auth[auth_strategy].call(storage: @storage, http_options:) do |http|
- files_info(http, file_ids).map(&parse_json) >> handle_failure >> create_storage_file_infos
- end
- end
+ if file_ids.empty?
+ return ServiceResult.success(result: [])
+ end
- private
-
- def files_info(http, file_ids)
- response = http.post(Util.join_uri_path(@storage.uri, FILES_INFO_PATH), json: { fileIds: file_ids })
- error_data = Storages::StorageErrorData.new(source: self.class, payload: response)
-
- case response
- in { status: 200..299 }
- ServiceResult.success(result: response.body)
- in { status: 404 }
- Util.error(:not_found, "Outbound request destination not found!", error_data)
- in { status: 401 }
- Util.error(:unauthorized, "Outbound request not authorized!", error_data)
- else
- Util.error(:error, "Outbound request failed!", error_data)
- end
- end
+ http_options = Util.ocs_api_request.deep_merge(Util.accept_json)
+ Authentication[auth_strategy].call(storage: @storage, http_options:) do |http|
+ files_info(http, file_ids).map(&parse_json) >> handle_failure >> create_storage_file_infos
+ end
+ end
- def parse_json
- ->(response_body) do
- # rubocop:disable Style/OpenStructUse
- JSON.parse(response_body, object_class: OpenStruct)
- # rubocop:enable Style/OpenStructUse
- end
- end
+ private
- def handle_failure
- ->(response_object) do
- if response_object.ocs.meta.status == "ok"
- ServiceResult.success(result: response_object)
- else
- error_data = Storages::StorageErrorData.new(source: self.class, payload: response_object)
- Util.error(:error, "Outbound request failed!", error_data)
- end
- end
- end
+ def files_info(http, file_ids)
+ response = http.post(RequestUrlBuilder.build(@storage, FILES_INFO_PATH), json: { fileIds: file_ids })
+ error_data = StorageErrorData.new(source: self.class, payload: response)
- # rubocop:disable Metrics/AbcSize
- def create_storage_file_infos
- ->(response_object) do
- ServiceResult.success(
- result: response_object.ocs.data.each_pair.map do |key, value|
- if value.statuscode == 200
- ::Storages::StorageFileInfo.new(
- status: value.status,
- status_code: value.statuscode,
- id: value.id,
- name: value.name,
- last_modified_at: Time.zone.at(value.mtime),
- created_at: Time.zone.at(value.ctime),
- mime_type: value.mimetype,
- size: value.size,
- owner_name: value.owner_name,
- owner_id: value.owner_id,
- last_modified_by_name: value.modifier_name,
- last_modified_by_id: value.modifier_id,
- permissions: value.dav_permissions,
- location: location(value.path, value.mimetype)
- )
+ case response
+ in { status: 200..299 }
+ ServiceResult.success(result: response.body)
+ in { status: 404 }
+ Util.error(:not_found, "Outbound request destination not found!", error_data)
+ in { status: 401 }
+ Util.error(:unauthorized, "Outbound request not authorized!", error_data)
else
- ::Storages::StorageFileInfo.new(
- status: value.status,
- status_code: value.statuscode,
- id: key.to_s.to_i
+ Util.error(:error, "Outbound request failed!", error_data)
+ end
+ end
+
+ def parse_json
+ ->(response_body) do
+ # rubocop:disable Style/OpenStructUse
+ JSON.parse(response_body, object_class: OpenStruct)
+ # rubocop:enable Style/OpenStructUse
+ end
+ end
+
+ def handle_failure
+ ->(response_object) do
+ if response_object.ocs.meta.status == "ok"
+ ServiceResult.success(result: response_object)
+ else
+ error_data = StorageErrorData.new(source: self.class, payload: response_object)
+ Util.error(:error, "Outbound request failed!", error_data)
+ end
+ end
+ end
+
+ # rubocop:disable Metrics/AbcSize
+ def create_storage_file_infos
+ ->(response_object) do
+ ServiceResult.success(
+ result: response_object.ocs.data.each_pair.map do |key, value|
+ if value.statuscode == 200
+ StorageFileInfo.new(
+ status: value.status,
+ status_code: value.statuscode,
+ id: value.id,
+ name: value.name,
+ last_modified_at: Time.zone.at(value.mtime),
+ created_at: Time.zone.at(value.ctime),
+ mime_type: value.mimetype,
+ size: value.size,
+ owner_name: value.owner_name,
+ owner_id: value.owner_id,
+ last_modified_by_name: value.modifier_name,
+ last_modified_by_id: value.modifier_id,
+ permissions: value.dav_permissions,
+ location: location(value.path, value.mimetype)
+ )
+ else
+ StorageFileInfo.new(
+ status: value.status,
+ status_code: value.statuscode,
+ id: key.to_s.to_i
+ )
+ end
+ end
)
end
end
- )
- end
- end
- # rubocop:enable Metrics/AbcSize
+ # rubocop:enable Metrics/AbcSize
- def location(file_path, mimetype)
- prefix = "files/"
- idx = file_path.rindex(prefix)
- return "/" if idx == nil
+ def location(file_path, mimetype)
+ prefix = "files/"
+ idx = file_path.rindex(prefix)
+ return "/" if idx == nil
- idx += prefix.length - 1
- # Remove the following when /filesinfo starts responding with a trailing slash for directory paths
- # in all supported versions of OpenProjectIntegation Nextcloud App.
- file_path << "/" if mimetype == "application/x-op-directory" && file_path[-1] != "/"
- Util.escape_path(file_path[idx..])
+ idx += prefix.length - 1
+ # Remove the following when /filesinfo starts responding with a trailing slash for directory paths
+ # in all supported versions of OpenProjectIntegation Nextcloud App.
+ file_path << "/" if mimetype == "application/x-op-directory" && file_path[-1] != "/"
+
+ RequestUrlBuilder.path(file_path[idx..])
+ end
+ end
+ end
end
end
end
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.rb
index d7a9eb0b0ea..8a47b60059f 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
@@ -26,211 +26,209 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Storages::Peripherals::StorageInteraction::Nextcloud
- class FilesQuery
- Auth = ::Storages::Peripherals::StorageInteraction::Authentication
-
- def self.call(storage:, auth_strategy:, folder:)
- new(storage).call(auth_strategy:, folder:)
- end
-
- def initialize(storage)
- @storage = storage
- end
-
- def call(auth_strategy:, folder:)
- if auth_strategy.user.nil?
- error_data = Storages::StorageErrorData.new(source: self)
- return Util.error(:error, "Cannot execute query without user context.", error_data)
- end
-
- origin_user = origin_user_id(auth_strategy.user)
- @location_prefix = Util.join_uri_path(@storage.uri.path,
- "remote.php/dav/files",
- origin_user.gsub(" ", "%20"))
-
- result = make_request(auth_strategy:, folder:, user: auth_strategy.user)
- storage_files(result)
- end
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module Nextcloud
+ class FilesQuery
+ def self.call(storage:, auth_strategy:, folder:)
+ new(storage).call(auth_strategy:, folder:)
+ end
- private
+ def initialize(storage)
+ @storage = storage
+ end
- def make_request(auth_strategy:, folder:, user:)
- origin_user = origin_user_id(user)
+ def call(auth_strategy:, folder:)
+ if auth_strategy.user.nil?
+ error_data = StorageErrorData.new(source: self)
+ return Util.error(:error, "Cannot execute query without user context.", error_data)
+ end
- Auth[auth_strategy].call(storage: @storage,
- http_options: Util.webdav_request_with_depth(1)) do |http|
- response = http.request("PROPFIND",
- Util.join_uri_path(@storage.uri,
- "remote.php/dav/files",
- CGI.escapeURIComponent(origin_user),
- requested_folder(folder)),
- xml: requested_properties)
- handle_response(response)
- end
- end
+ origin_user = origin_user_id(auth_strategy.user)
+ @location_prefix = RequestUrlBuilder.path(@storage.uri.path,
+ "remote.php/dav/files",
+ origin_user)
- def handle_response(response)
- error_data = Storages::StorageErrorData.new(source: self.class, payload: response)
-
- case response
- in { status: 200..299 }
- ServiceResult.success(result: response.body)
- in { status: 404 }
- Util.error(:not_found, "Outbound request destination not found", error_data)
- in { status: 401 }
- Util.error(:unauthorized, "Outbound request not authorized", error_data)
- else
- Util.error(:error, "Outbound request failed", error_data)
- end
- end
+ result = make_request(auth_strategy:, folder:, user: auth_strategy.user)
+ storage_files(result)
+ end
- def origin_user_id(user)
- OAuthClientToken.find_by(user_id: user, oauth_client_id: @storage.oauth_client.id)&.origin_user_id || ""
- end
+ private
+
+ def make_request(auth_strategy:, folder:, user:)
+ origin_user = origin_user_id(user)
+
+ Authentication[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),
+ xml: requested_properties)
+ handle_response(response)
+ end
+ end
- def requested_folder(folder)
- return "" if folder.root?
+ def handle_response(response)
+ error_data = StorageErrorData.new(source: self.class, payload: response)
+
+ case response
+ in { status: 200..299 }
+ ServiceResult.success(result: response.body)
+ in { status: 404 }
+ Util.error(:not_found, "Outbound request destination not found", error_data)
+ in { status: 401 }
+ Util.error(:unauthorized, "Outbound request not authorized", error_data)
+ else
+ Util.error(:error, "Outbound request failed", error_data)
+ end
+ end
- Util.escape_path(folder.path)
- end
+ def origin_user_id(user)
+ OAuthClientToken.find_by(user_id: user, oauth_client_id: @storage.oauth_client.id)&.origin_user_id || ""
+ end
- # rubocop:disable Metrics/AbcSize
- def requested_properties
- Nokogiri::XML::Builder.new do |xml|
- xml["d"].propfind(
- "xmlns:d" => "DAV:",
- "xmlns:oc" => "http://owncloud.org/ns"
- ) do
- xml["d"].prop do
- xml["oc"].fileid
- xml["oc"].size
- xml["d"].getcontenttype
- xml["d"].getlastmodified
- xml["oc"].permissions
- xml["oc"].send(:"owner-display-name")
+ # rubocop:disable Metrics/AbcSize
+ def requested_properties
+ Nokogiri::XML::Builder.new do |xml|
+ xml["d"].propfind(
+ "xmlns:d" => "DAV:",
+ "xmlns:oc" => "http://owncloud.org/ns"
+ ) do
+ xml["d"].prop do
+ xml["oc"].fileid
+ xml["oc"].size
+ xml["d"].getcontenttype
+ xml["d"].getlastmodified
+ xml["oc"].permissions
+ xml["oc"].send(:"owner-display-name")
+ end
+ end
+ end.to_xml
end
- end
- end.to_xml
- end
- # rubocop:enable Metrics/AbcSize
+ # rubocop:enable Metrics/AbcSize
- def storage_files(response)
- response.map do |xml|
- parent, *files = Nokogiri::XML(xml)
- .xpath("//d:response")
- .to_a
- .map { |file_element| storage_file(file_element) }
+ def storage_files(response)
+ response.map do |xml|
+ 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))
- end
- end
+ StorageFiles.new(files, parent, ancestors(parent.location))
+ end
+ end
- def ancestors(parent_location)
- path = parent_location.split("/")
- return [] if path.count == 0
+ def ancestors(parent_location)
+ path = parent_location.split("/")
+ return [] if path.count == 0
- path.take(path.count - 1).reduce([]) do |list, item|
- last = list.last
- prefix = last.nil? || last.location[-1] != "/" ? "/" : ""
- location = "#{last&.location}#{prefix}#{item}"
- list.append(forge_ancestor(location))
- end
- end
+ path.take(path.count - 1).reduce([]) do |list, item|
+ last = list.last
+ prefix = last.nil? || last.location[-1] != "/" ? "/" : ""
+ location = "#{last&.location}#{prefix}#{item}"
+ list.append(forge_ancestor(location))
+ end
+ end
- # The ancestors are simply derived objects from the parents location string. Until we have real information
- # from the nextcloud API about the path to the parent, we need to derive name, location and forge an ID.
- def forge_ancestor(location)
- ::Storages::StorageFile.new(id: Digest::SHA256.hexdigest(location), name: name(location), location:)
- end
+ # The ancestors are simply derived objects from the parents location string. Until we have real information
+ # from the nextcloud API about the path to the parent, we need to derive name, location and forge an ID.
+ def forge_ancestor(location)
+ StorageFile.new(id: Digest::SHA256.hexdigest(location), name: name(location), location:)
+ end
- def name(location)
- location == "/" ? "Root" : CGI.unescape(location.split("/").last)
- end
+ def name(location)
+ location == "/" ? "Root" : CGI.unescape(location.split("/").last)
+ end
- def storage_file(file_element)
- location = location(file_element)
-
- ::Storages::StorageFile.new(
- id: id(file_element),
- name: name(location),
- size: size(file_element),
- mime_type: mime_type(file_element),
- last_modified_at: last_modified_at(file_element),
- created_by_name: created_by(file_element),
- location:,
- permissions: permissions(file_element)
- )
- end
+ def storage_file(file_element)
+ location = location(file_element)
+
+ StorageFile.new(
+ id: id(file_element),
+ name: name(location),
+ size: size(file_element),
+ mime_type: mime_type(file_element),
+ last_modified_at: last_modified_at(file_element),
+ created_by_name: created_by(file_element),
+ location:,
+ permissions: permissions(file_element)
+ )
+ end
- def id(element)
- element
- .xpath(".//oc:fileid")
- .map(&:inner_text)
- .reject(&:empty?)
- .first
- end
+ def id(element)
+ element
+ .xpath(".//oc:fileid")
+ .map(&:inner_text)
+ .reject(&:empty?)
+ .first
+ end
- def location(element)
- texts = element
- .xpath("d:href")
- .map(&:inner_text)
+ def location(element)
+ texts = element
+ .xpath("d:href")
+ .map(&:inner_text)
- return nil if texts.empty?
+ return nil if texts.empty?
- element_name = texts.first.delete_prefix(@location_prefix)
+ element_name = texts.first.delete_prefix(@location_prefix)
- return element_name if element_name == "/"
+ return element_name if element_name == "/"
- element_name.delete_suffix("/")
- end
+ element_name.delete_suffix("/")
+ end
- def size(element)
- element
- .xpath(".//oc:size")
- .map(&:inner_text)
- .map { |e| Integer(e) }
- .first
- end
+ def size(element)
+ element
+ .xpath(".//oc:size")
+ .map(&:inner_text)
+ .map { |e| Integer(e) }
+ .first
+ end
- def mime_type(element)
- element
- .xpath(".//d:getcontenttype")
- .map(&:inner_text)
- .reject(&:empty?)
- .first || "application/x-op-directory"
- end
+ def mime_type(element)
+ element
+ .xpath(".//d:getcontenttype")
+ .map(&:inner_text)
+ .reject(&:empty?)
+ .first || "application/x-op-directory"
+ end
- def last_modified_at(element)
- element
- .xpath(".//d:getlastmodified")
- .map { |e| DateTime.parse(e) }
- .first
- end
+ def last_modified_at(element)
+ element
+ .xpath(".//d:getlastmodified")
+ .map { |e| DateTime.parse(e) }
+ .first
+ end
- def created_by(element)
- element
- .xpath(".//oc:owner-display-name")
- .map(&:inner_text)
- .reject(&:empty?)
- .first
- end
+ def created_by(element)
+ element
+ .xpath(".//oc:owner-display-name")
+ .map(&:inner_text)
+ .reject(&:empty?)
+ .first
+ end
- def permissions(element)
- permissions_string =
- element
- .xpath(".//oc:permissions")
- .map(&:inner_text)
- .reject(&:empty?)
- .first
-
- # Nextcloud Dav permissions:
- # https://github.com/nextcloud/server/blob/66648011c6bc278ace57230db44fd6d63d67b864/lib/public/Files/DavUtil.php
- result = []
- result << :readable if permissions_string.include?("G")
- result << :writeable if %w[CK W].reduce(false) { |s, v| s || permissions_string.include?(v) }
- result
+ def permissions(element)
+ permissions_string =
+ element
+ .xpath(".//oc:permissions")
+ .map(&:inner_text)
+ .reject(&:empty?)
+ .first
+
+ # Nextcloud Dav permissions:
+ # https://github.com/nextcloud/server/blob/66648011c6bc278ace57230db44fd6d63d67b864/lib/public/Files/DavUtil.php
+ result = []
+ result << :readable if permissions_string.include?("G")
+ result << :writeable if %w[CK W].reduce(false) { |s, v| s || permissions_string.include?(v) }
+ result
+ end
+ end
+ end
end
end
end
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.rb
index 90a18bf3ca7..55c319bb6cb 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
@@ -33,7 +33,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
using Storages::Peripherals::ServiceResultRefinements
def initialize(storage)
- @uri = storage.uri
+ @storage = storage
@username = storage.username
@password = storage.password
end
@@ -48,7 +48,13 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
.httpx
.basic_auth(@username, @password)
.with(headers: { "OCS-APIRequest" => "true" })
- .get(Util.join_uri_path(@uri, "ocs/v1.php/cloud/groups", CGI.escapeURIComponent(group)))
+ .get(
+ Storages::Peripherals::StorageInteraction::RequestUrlBuilder.build(
+ @storage,
+ "ocs/v1.php/cloud/groups",
+ CGI.escapeURIComponent(group)
+ )
+ )
error_data = Storages::StorageErrorData.new(source: self.class, payload: response)
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.rb
index d3b2d37e099..f09231b839e 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
@@ -42,15 +42,13 @@ module Storages
def call(auth_strategy:, location:)
origin_user_id = Util.origin_user_id(caller: self.class, storage: @storage, auth_strategy:)
- if origin_user_id.failure?
- return origin_user_id
- end
+ .on_failure { |error| return error }
+ .result
Authentication[auth_strategy].call(storage: @storage) do |http|
- handle_response http.delete(Util.join_uri_path(@storage.uri,
- "remote.php/dav/files",
- CGI.escapeURIComponent(origin_user_id.result),
- Util.escape_path(location)))
+ handle_response http.delete(
+ RequestUrlBuilder.build(@storage, "remote.php/dav/files", origin_user_id, location)
+ )
end
end
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.rb
index 445342bc46f..311d2d29564 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,7 +73,10 @@ module Storages
end
def call(http:, username:, path:, props:)
- request_uri = Util.join_uri_path(base_uri, CGI.escapeURIComponent(username), Util.escape_path(path))
+ request_uri = RequestUrlBuilder.build(@storage,
+ "remote.php/dav/files",
+ username,
+ path)
response = http.request(:propfind, request_uri, xml: request_body(props))
handle_response(response, username)
@@ -125,11 +128,9 @@ module Storages
# rubocop:enable Metrics/AbcSize
- def base_uri = "#{@storage.uri}remote.php/dav/files"
-
def resource_path(section, username)
path = CGI.unescape(section.xpath("d:href").text.strip)
- .gsub!(Util.join_uri_path(URI(base_uri).path, username), "")
+ .gsub!(RequestUrlBuilder.path(@storage.uri.path, "remote.php/dav/files", username), "")
path.end_with?("/") && path.length > 1 ? path.chop : path
end
diff --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.rb
index cb8043a6d90..014e6cf16f6 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
@@ -28,114 +28,118 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Storages::Peripherals::StorageInteraction::Nextcloud::Internal
- class PropfindQueryLegacy
- UTIL = ::Storages::Peripherals::StorageInteraction::Nextcloud::Util
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module Nextcloud
+ module Internal
+ class PropfindQueryLegacy
+ # Only for information purposes currently.
+ # Probably a bit later we could validate `#call` parameters.
+ #
+ # DEPTH = %w[0 1 infinity].freeze
+ # POSSIBLE_PROPS = %w[
+ # d:getlastmodified
+ # d:getetag
+ # d:getcontenttype
+ # d:resourcetype
+ # d:getcontentlength
+ # d:permissions
+ # d:size
+ # oc:id
+ # oc:fileid
+ # oc:favorite
+ # oc:comments-href
+ # oc:comments-count
+ # oc:comments-unread
+ # oc:owner-id
+ # oc:owner-display-name
+ # oc:share-types
+ # oc:checksums
+ # oc:size
+ # nc:has-preview
+ # nc:rich-workspace
+ # nc:contained-folder-count
+ # nc:contained-file-count
+ # nc:acl-list
+ # ].freeze
- # Only for information purposes currently.
- # Probably a bit later we could validate `#call` parameters.
- #
- # DEPTH = %w[0 1 infinity].freeze
- # POSSIBLE_PROPS = %w[
- # d:getlastmodified
- # d:getetag
- # d:getcontenttype
- # d:resourcetype
- # d:getcontentlength
- # d:permissions
- # d:size
- # oc:id
- # oc:fileid
- # oc:favorite
- # oc:comments-href
- # oc:comments-count
- # oc:comments-unread
- # oc:owner-id
- # oc:owner-display-name
- # oc:share-types
- # oc:checksums
- # oc:size
- # nc:has-preview
- # nc:rich-workspace
- # nc:contained-folder-count
- # nc:contained-file-count
- # nc:acl-list
- # ].freeze
+ def initialize(storage)
+ @storage = storage
+ @username = storage.username
+ @password = storage.password
+ @group = storage.group
+ end
- def initialize(storage)
- @uri = storage.uri
- @username = storage.username
- @password = storage.password
- @group = storage.group
- end
+ def self.call(storage:, depth:, path:, props:)
+ new(storage).call(depth:, path:, props:)
+ end
- def self.call(storage:, depth:, path:, props:)
- new(storage).call(depth:, path:, props:)
- end
+ # rubocop:disable Metrics/AbcSize
+ def call(depth:, path:, props:)
+ body = Nokogiri::XML::Builder.new do |xml|
+ xml["d"].propfind(
+ "xmlns:d" => "DAV:",
+ "xmlns:oc" => "http://owncloud.org/ns",
+ "xmlns:nc" => "http://nextcloud.org/ns"
+ ) do
+ xml["d"].prop do
+ props.each do |prop|
+ namespace, property = prop.split(":")
+ xml[namespace].send(property)
+ end
+ end
+ end
+ end.to_xml
- # rubocop:disable Metrics/AbcSize
- def call(depth:, path:, props:)
- body = Nokogiri::XML::Builder.new do |xml|
- xml["d"].propfind(
- "xmlns:d" => "DAV:",
- "xmlns:oc" => "http://owncloud.org/ns",
- "xmlns:nc" => "http://nextcloud.org/ns"
- ) do
- xml["d"].prop do
- props.each do |prop|
- namespace, property = prop.split(":")
- xml[namespace].send(property)
- end
- end
- end
- end.to_xml
+ response = OpenProject
+ .httpx
+ .basic_auth(@username, @password)
+ .with(headers: { "Depth" => depth })
+ .request(
+ "PROPFIND",
+ RequestUrlBuilder.build(@storage,
+ "remote.php/dav/files",
+ @username,
+ path),
+ xml: body
+ )
+
+ error_data = StorageErrorData.new(source: self.class, payload: response)
- response = OpenProject
- .httpx
- .basic_auth(@username, @password)
- .with(headers: { "Depth" => depth })
- .request(
- "PROPFIND",
- UTIL.join_uri_path(
- @uri,
- "remote.php/dav/files",
- CGI.escapeURIComponent(@username),
- UTIL.escape_path(path)
- ),
- xml: body
- )
+ case response
+ in { status: 200..299 }
+ doc = 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)
+ resource = CGI.unescape(resource_section.xpath("d:href").text.strip).gsub!(source_path, "")
- error_data = Storages::StorageErrorData.new(source: self.class, payload: response)
+ result[resource] = {}
- case response
- in { status: 200..299 }
- doc = Nokogiri::XML(response.body.to_s)
- result = {}
- doc.xpath("/d:multistatus/d:response").each do |resource_section|
- resource = CGI.unescape(resource_section.xpath("d:href").text.strip)
- .gsub!(UTIL.join_uri_path(@uri.path, "/remote.php/dav/files/#{@username}/"), "")
+ # In future it could be useful to respond not only with found, but not found props as well
+ # resource_section.xpath("d:propstat[d:status[text() = 'HTTP/1.1 404 Not Found']]/d:prop/*")
+ resource_section.xpath("d:propstat[d:status[text() = 'HTTP/1.1 200 OK']]/d:prop/*").each do |node|
+ result[resource][node.name.to_s] = node.text.strip
+ end
+ end
- result[resource] = {}
+ ServiceResult.success(result:)
+ in { status: 405 }
+ Util.error(:not_allowed, "Outbound request method not allowed", error_data)
+ in { status: 401 }
+ Util.error(:unauthorized, "Outbound request not authorized", error_data)
+ in { status: 404 }
+ Util.error(:not_found, "Outbound request destination not found", error_data)
+ else
+ Util.error(:error, "Outbound request failed", error_data)
+ end
+ end
- # In future it could be useful to respond not only with found, but not found props as well
- # resource_section.xpath("d:propstat[d:status[text() = 'HTTP/1.1 404 Not Found']]/d:prop/*")
- resource_section.xpath("d:propstat[d:status[text() = 'HTTP/1.1 200 OK']]/d:prop/*").each do |node|
- result[resource][node.name.to_s] = node.text.strip
+ # rubocop:enable Metrics/AbcSize
end
end
-
- ServiceResult.success(result:)
- in { status: 405 }
- UTIL.error(:not_allowed, "Outbound request method not allowed", error_data)
- in { status: 401 }
- UTIL.error(:unauthorized, "Outbound request not authorized", error_data)
- in { status: 404 }
- UTIL.error(:not_found, "Outbound request destination not found", error_data)
- else
- UTIL.error(:error, "Outbound request failed", error_data)
end
end
-
- # rubocop:enable Metrics/AbcSize
end
end
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.rb
index fa40a136097..5ad857f0a8c 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,8 @@ module Storages
# rubocop:disable Lint/UnusedMethodArgument
def call(auth_strategy:, file_id:, open_location: false)
location_flag = open_location ? 0 : 1
- ServiceResult.success(result: Util.join_uri_path(@storage.uri, "index.php/f/#{file_id}?openfile=#{location_flag}"))
+ url = RequestUrlBuilder.build(@storage, "index.php/f/#{file_id}") + "?openfile=#{location_flag}"
+ ServiceResult.success(result: url)
end
# rubocop:enable Lint/UnusedMethodArgument
diff --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.rb
index 0fb0f431a1e..79c97bcd059 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/UnusedMethodArgument
def call(auth_strategy:)
- ServiceResult.success(result: Util.join_uri_path(@storage.uri, "index.php/apps/files"))
+ ServiceResult.success(result: RequestUrlBuilder.build(@storage, "index.php/apps/files"))
end
# rubocop:enable Lint/UnusedMethodArgument
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.rb
index 167dbc50557..ad865088ba8 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
@@ -31,7 +31,7 @@
module Storages::Peripherals::StorageInteraction::Nextcloud
class RemoveUserFromGroupCommand
def initialize(storage)
- @uri = storage.uri
+ @storage = storage
@username = storage.username
@password = storage.password
@group = storage.group
@@ -48,10 +48,12 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
.basic_auth(@username, @password)
.with(headers: { "OCS-APIRequest" => "true" })
.delete(
- Util.join_uri_path(@uri,
- "ocs/v1.php/cloud/users",
- CGI.escapeURIComponent(user),
- "groups?groupid=#{CGI.escapeURIComponent(group)}")
+ Storages::Peripherals::StorageInteraction::RequestUrlBuilder.build(
+ @storage,
+ "ocs/v1.php/cloud/users",
+ user,
+ "groups"
+ ) + "?groupid=#{CGI.escapeURIComponent(group)}"
)
error_data = Storages::StorageErrorData.new(source: self.class, payload: response)
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.rb
index b30ae1537f4..2b025793110 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,14 @@ module Storages
private
def make_request(auth_strategy, user, file_info, name)
- source_path = Util.join_uri_path(@storage.uri,
- "remote.php/dav/files",
- user,
- file_info.location)
- destination = Util.join_uri_path(@storage.uri.path,
- "remote.php/dav/files",
- user,
- target_path(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)))
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.rb
index 09f239dd6d9..6f09f7ed991 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
@@ -33,7 +33,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
using Storages::Peripherals::ServiceResultRefinements
def initialize(storage)
- @uri = storage.uri
+ @storage = storage
@username = storage.username
@password = storage.password
end
@@ -85,10 +85,8 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
.basic_auth(@username, @password)
.request(
"PROPPATCH",
- Util.join_uri_path(@uri,
- "remote.php/dav/files",
- CGI.escapeURIComponent(@username),
- Util.escape_path(path)),
+ Storages::Peripherals::StorageInteraction::RequestUrlBuilder
+ .build(@storage, "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.rb
index 31e66bfe79c..bf66441be32 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
@@ -57,9 +57,13 @@ module Storages
private
- def base_uri = "#{@storage.uri}index.php/apps/integration_openproject/direct-upload-token"
+ def base_uri
+ RequestUrlBuilder.build(@storage, "index.php/apps/integration_openproject/direct-upload-token")
+ end
- def upload_base_uri = "#{@storage.uri}index.php/apps/integration_openproject/direct-upload"
+ def upload_base_uri
+ RequestUrlBuilder.build(@storage, "index.php/apps/integration_openproject/direct-upload")
+ end
def upload_data_failure
Util.failure(code: :error,
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.rb
index 5e88a3acc36..281b871c86a 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
@@ -36,12 +36,6 @@ module Storages
using ServiceResultRefinements
class << self
- def escape_path(path)
- escaped_path = path.split("/").map { |i| CGI.escapeURIComponent(i) }.join("/")
- escaped_path << "/" if path[-1] == "/"
- escaped_path
- end
-
def ocs_api_request
{ headers: { "OCS-APIRequest" => "true" } }
end
@@ -68,14 +62,6 @@ module Storages
)
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 OpenProject
- # Server is not run on a Windows context.
- # URI::join cannot be used, as it behaves very different for the path parts depending on trailing slashes.
- File.join(uri.to_s, *)
- end
-
def token(user:, configuration:, &)
connection_manager = OAuthClients::ConnectionManager.new(user:, configuration:)
connection_manager.get_access_token.match(
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/request_url.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/request_url_builder.rb
similarity index 51%
rename from modules/storages/app/common/storages/peripherals/storage_interaction/request_url.rb
rename to modules/storages/app/common/storages/peripherals/storage_interaction/request_url_builder.rb
index 96356a86496..e13c98f33ff 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/request_url.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/request_url_builder.rb
@@ -31,26 +31,45 @@
module Storages
module Peripherals
module StorageInteraction
- module RequestUrl
- Builder = ->(storage, *path_fragments) do
- host_uri = storage.uri
+ class RequestUrlBuilder
+ class << self
+ def build(storage, *path_fragments)
+ host_uri = storage.uri
- ensure_sub_path = ->(fragment) { fragment.ends_with?("/") ? fragment : "#{fragment}/" }
- ensure_relative_path = ->(fragment) { fragment.starts_with?("/") ? fragment[1..] : fragment }
+ 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
- ensure_fragments_are_relative_sub_paths = ->(fragments) do
- return nil if fragments.nil?
+ def ensure_sub_path(fragment)
+ fragment.ends_with?("/") ? fragment : "#{fragment}/"
+ end
+
+ def split_and_escape(fragments)
+ return fragments if fragments.empty?
- fragments[..-2]
- .map(&ensure_sub_path)
- .push(fragments.last)
- .map(&ensure_relative_path)
+ 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
- URI.join(host_uri.origin,
- ensure_sub_path.(host_uri.path),
- *ensure_fragments_are_relative_sub_paths.(path_fragments))
- .to_s
+ def ensure_unescaped_fragments(fragment)
+ raise ArgumentError, "URL-escaped character found: #{fragment}" if CGI.unescape(fragment) != fragment
+ end
end
end
end
diff --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.rb
index ceb3803fe69..ce7b1fee7b1 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
@@ -94,8 +94,8 @@ module Storages::Admin::Forms
def provider_credentials_instructions_link
render(
Primer::Beta::Link.new(
- href: Storages::Peripherals::StorageInteraction::Nextcloud::Util.join_uri_path(storage.host,
- "settings/admin/openproject"),
+ href: Storages::Peripherals::StorageInteraction::RequestUrlBuilder.build(storage,
+ "settings/admin/openproject"),
target: "_blank"
)
) { I18n.t("storages.instructions.#{storage.short_provider_type}.integration") }
diff --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.rb
index 40680de2c83..57be26c54ef 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,8 @@ module Storages::Admin::Forms
end
def nextcloud_integration_link(target: "_blank")
- href = Storages::Peripherals::StorageInteraction::Nextcloud::Util
- .join_uri_path(storage.host, "settings/admin/openproject")
+ href = Storages::Peripherals::StorageInteraction::RequestUrlBuilder
+ .build(storage, "settings/admin/openproject")
render(Primer::Beta::Link.new(href:, target:)) { I18n.t("storages.instructions.nextcloud.integration") }
end
diff --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.rb
index c80bef345ac..5b37b6e92a4 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,8 +46,10 @@ module Storages::Admin
def oauth_application_details_link
render(
Primer::Beta::Link.new(
- href: ::Storages::Peripherals::StorageInteraction::Nextcloud::Util.join_uri_path(storage.host,
- "settings/admin/openproject"),
+ href: ::Storages::Peripherals::StorageInteraction::RequestUrlBuilder.build(
+ storage,
+ "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.rb
index 2825ea15ccc..78b72512b35 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,8 @@ module Storages::Admin::ManagedProjectFolders
def provider_type_link
render(
Primer::Beta::Link.new(
- href: Storages::Peripherals::StorageInteraction::Nextcloud::Util.join_uri_path(@storage.host,
- "settings/admin/openproject"),
+ href: Storages::Peripherals::StorageInteraction::RequestUrlBuilder.build(@storage,
+ "settings/admin/openproject"),
target: "_blank"
)
) { I18n.t("storages.instructions.#{@storage.short_provider_type}.integration") }
diff --git a/modules/storages/app/models/storages/project_storage.rb b/modules/storages/app/models/storages/project_storage.rb
index ee7c6485686..aa1420da726 100644
--- a/modules/storages/app/models/storages/project_storage.rb
+++ b/modules/storages/app/models/storages/project_storage.rb
@@ -124,7 +124,7 @@ module Storages
end
def escape_path(path)
- Peripherals::StorageInteraction::Nextcloud::Util.escape_path(path)
+ Peripherals::StorageInteraction::RequestUrlBuilder.path(path)
end
end
end
diff --git a/modules/storages/app/models/storages/storage_files.rb b/modules/storages/app/models/storages/storage_files.rb
index 600d9856637..c8252afebbd 100644
--- a/modules/storages/app/models/storages/storage_files.rb
+++ b/modules/storages/app/models/storages/storage_files.rb
@@ -26,12 +26,14 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Storages::StorageFiles
- attr_reader :files, :parent, :ancestors
+module Storages
+ class StorageFiles
+ attr_reader :files, :parent, :ancestors
- def initialize(files, parent, ancestors)
- @files = files
- @parent = parent
- @ancestors = ancestors
+ def initialize(files, parent, ancestors)
+ @files = files
+ @parent = parent
+ @ancestors = ancestors
+ end
end
end
diff --git a/modules/storages/app/services/storages/nextcloud_group_folder_properties_sync_service.rb b/modules/storages/app/services/storages/nextcloud_group_folder_properties_sync_service.rb
index 508fa6b8aca..e99bbd56c8c 100644
--- a/modules/storages/app/services/storages/nextcloud_group_folder_properties_sync_service.rb
+++ b/modules/storages/app/services/storages/nextcloud_group_folder_properties_sync_service.rb
@@ -159,7 +159,7 @@ module Storages
def hide_inactive_folders(remote_folders)
project_folder_ids = active_project_storages_scope.pluck(:project_folder_id).compact
- remote_folders.except("#{@storage.group_folder}/").each do |(path, attrs)|
+ remote_folders.except("/#{@storage.group_folder}/").each do |(path, attrs)|
next if project_folder_ids.include?(attrs["fileid"])
command_params = {
diff --git a/modules/storages/app/validator/nextcloud_application_credentials_validator.rb b/modules/storages/app/validator/nextcloud_application_credentials_validator.rb
index ca95a43c1c3..7deae539322 100644
--- a/modules/storages/app/validator/nextcloud_application_credentials_validator.rb
+++ b/modules/storages/app/validator/nextcloud_application_credentials_validator.rb
@@ -26,13 +26,12 @@
# See COPYRIGHT and LICENSE files for more details.
#++
class NextcloudApplicationCredentialsValidator
- UTIL = Storages::Peripherals::StorageInteraction::Nextcloud::Util
+ BUILDER = Storages::Peripherals::StorageInteraction::RequestUrlBuilder
attr_reader :contract, :uri
def initialize(contract)
@contract = contract
- @uri = URI(contract.host).normalize
end
# rubocop:disable Metrics/AbcSize
@@ -42,7 +41,7 @@ class NextcloudApplicationCredentialsValidator
response = OpenProject
.httpx
.basic_auth(contract.username, contract.password)
- .head(UTIL.join_uri_path(uri, "remote.php/dav"))
+ .head(BUILDER.build(contract.model, "remote.php/dav"))
case response
in { status: 200..299 }
true
diff --git a/modules/storages/spec/common/storages/peripherals/registry_spec.rb b/modules/storages/spec/common/storages/peripherals/registry_spec.rb
index 340607402d3..3cc5797e9b5 100644
--- a/modules/storages/spec/common/storages/peripherals/registry_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/registry_spec.rb
@@ -489,13 +489,13 @@ RSpec.describe Storages::Peripherals::Registry, :webmock do
result = registry.resolve("nextcloud.queries.file_ids")
.call(storage:, path: "OpenProject")
.result
- expect(result).to eq({ "OpenProject/" => { "fileid" => "349" },
- "OpenProject/Project #2/" => { "fileid" => "381" },
- "OpenProject/Project#1/" => { "fileid" => "773" },
- "OpenProject/Project#2/" => { "fileid" => "398" },
- "OpenProject/asd/" => { "fileid" => "783" },
- "OpenProject/qwe/" => { "fileid" => "767" },
- "OpenProject/qweekk/" => { "fileid" => "802" } })
+ expect(result).to eq({ "/OpenProject/" => { "fileid" => "349" },
+ "/OpenProject/Project #2/" => { "fileid" => "381" },
+ "/OpenProject/Project#1/" => { "fileid" => "773" },
+ "/OpenProject/Project#2/" => { "fileid" => "398" },
+ "/OpenProject/asd/" => { "fileid" => "783" },
+ "/OpenProject/qwe/" => { "fileid" => "767" },
+ "/OpenProject/qweekk/" => { "fileid" => "802" } })
end
end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command_spec.rb
index 4360ddf5791..37db0352d5b 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command_spec.rb
@@ -39,10 +39,10 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::CopyTemplat
let(:origin_user_id) { "OpenProject" }
let(:storage) { build(:nextcloud_storage, :as_automatically_managed, host: url, password: "OpenProjectSecurePassword") }
- let(:source_path) { "source-of-fun" }
- let(:destination_path) { "boring-destination" }
- let(:source_url) { "#{url}/remote.php/dav/files/#{CGI.escape(origin_user_id)}/#{source_path}" }
- let(:destination_url) { "#{url}/remote.php/dav/files/#{CGI.escape(origin_user_id)}/#{destination_path}" }
+ let(:source_path) { "/source-of-fun" }
+ let(:destination_path) { "/boring-destination" }
+ let(:source_url) { "#{url}/remote.php/dav/files/#{CGI.escape(origin_user_id)}#{source_path}" }
+ let(:destination_url) { "#{url}/remote.php/dav/files/#{CGI.escape(origin_user_id)}#{destination_path}" }
let(:auth_strategy) { Storages::Peripherals::StorageInteraction::AuthenticationStrategies::NextcloudStrategies::UserLess.call }
subject { described_class.new(storage) }
@@ -52,14 +52,14 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::CopyTemplat
describe "parameter validation" do
it "source_path cannot be blank" do
- result = subject.call(auth_strategy:, source_path: "", destination_path: "destination")
+ result = subject.call(auth_strategy:, source_path: "", destination_path: "/destination")
expect(result).to be_failure
expect(result.errors.log_message).to eq("Source and destination paths must be present.")
end
it "destination_path cannot blank" do
- result = subject.call(auth_strategy:, source_path: "source", destination_path: "")
+ result = subject.call(auth_strategy:, source_path: "/source", destination_path: "")
expect(result).to be_failure
expect(result.errors.log_message).to eq("Source and destination paths must be present.")
@@ -86,7 +86,7 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::CopyTemplat
xmlns:oc="http://owncloud.org/ns"
xmlns:nc="http://nextcloud.org/ns">
<d:response>
- <d:href>/remote.php/dav/files/#{CGI.escape(origin_user_id)}/#{destination_path}</d:href>
+ <d:href>/remote.php/dav/files/#{CGI.escape(origin_user_id)}#{destination_path}</d:href>
<d:propstat>
<d:prop>
<oc:fileid>349</oc:fileid>
@@ -95,7 +95,7 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::CopyTemplat
</d:propstat>
</d:response>
<d:response>
- <d:href>/remote.php/dav/files/#{CGI.escape(origin_user_id)}/#{destination_path}/Dinge/</d:href>
+ <d:href>/remote.php/dav/files/#{CGI.escape(origin_user_id)}#{destination_path}/Dinge/</d:href>
<d:propstat>
<d:prop>
<oc:fileid>783</oc:fileid>
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/request_url_builder_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/request_url_builder_spec.rb
new file mode 100644
index 00000000000..657213f6c27
--- /dev/null
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/request_url_builder_spec.rb
@@ -0,0 +1,136 @@
+# 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.
+#++
+
+require "spec_helper"
+
+RSpec.describe Storages::Peripherals::StorageInteraction::RequestUrlBuilder do
+ describe "build" do
+ context "if storage is of Nextcloud provider type" do
+ context "with a standard host url" do
+ let(: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.build(storage, "path", "/another/fragment/"))
+ .to eq("https://example.com/path/another/fragment")
+ expect(described_class.build(storage, "/path/", "/another/fragment/"))
+ .to eq("https://example.com/path/another/fragment")
+ expect(described_class.build(storage, "/path/", "another/fragment"))
+ .to eq("https://example.com/path/another/fragment")
+ expect(described_class.build(storage, "/path/", "/another/", "/fragment/"))
+ .to eq("https://example.com/path/another/fragment")
+
+ expect(described_class.build(storage, "path", "//with-double-slash/"))
+ .to eq("https://example.com/path/with-double-slash")
+
+ expect(described_class.build(storage, "path", "new folder/stærforge"))
+ .to eq("https://example.com/path/new%20folder/st%C3%A6rforge")
+ end
+ end
+
+ context "with a host url without a trailing slash (legacy)" do
+ let(: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")
+ end
+ end
+
+ context "with a host url with path prefix" do
+ let(: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")
+ end
+ end
+
+ context "with a host url with path prefix and no trailing slash (legacy)" do
+ let(: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")
+ end
+ end
+ end
+
+ context "if storage is of OneDrive/SharePoint provider type" do
+ let(: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.build(storage, "path", "/to/", "/request"))
+ .to eq("https://graph.microsoft.com/path/to/request")
+ end
+ end
+
+ context "if a fragment with an url escaped character is given" do
+ let(:storage) { create(:nextcloud_storage) }
+
+ it "raises an exception" do
+ expect { described_class.build(storage, "/path/", "/i%20am%20escaped/") }.to raise_error(ArgumentError)
+ end
+ end
+
+ context "if no fragments are given" do
+ let(: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/")
+ end
+ end
+ end
+
+ describe "path" do
+ it "returns a correct path concatenation" do
+ expect(described_class.path("path")).to eq("/path")
+ expect(described_class.path("path/")).to eq("/path")
+ expect(described_class.path("/path")).to eq("/path")
+ expect(described_class.path("/path/")).to eq("/path")
+
+ expect(described_class.path("path", "to", "file")).to eq("/path/to/file")
+ expect(described_class.path("path/", "/to", "file/")).to eq("/path/to/file")
+ expect(described_class.path("path", "/to/", "/file")).to eq("/path/to/file")
+ expect(described_class.path("/path/", "/to", "file/")).to eq("/path/to/file")
+
+ expect(described_class.path("/path/", "/new folder/stærforge/")).to eq("/path/new%20folder/st%C3%A6rforge")
+ end
+ end
+end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/request_url_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/request_url_spec.rb
deleted file mode 100644
index e15b408a89b..00000000000
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/request_url_spec.rb
+++ /dev/null
@@ -1,104 +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.
-#++
-
-require "spec_helper"
-
-RSpec.describe Storages::Peripherals::StorageInteraction::RequestUrl do
- describe "Builder" do
- context "if storage is of Nextcloud provider type" do
- context "with a standard host url" do
- let(:storage) { create(:nextcloud_storage, host: "https://example.com/") }
-
- it "returns the correct request URL" do
- expect(described_class::Builder.call(storage, "/path/")).to eq("https://example.com/path/")
- expect(described_class::Builder.call(storage, "/path")).to eq("https://example.com/path")
- expect(described_class::Builder.call(storage, "path/")).to eq("https://example.com/path/")
- expect(described_class::Builder.call(storage, "path")).to eq("https://example.com/path")
-
- expect(described_class::Builder.call(storage, "path", "/another/fragment/"))
- .to eq("https://example.com/path/another/fragment/")
- expect(described_class::Builder.call(storage, "/path/", "/another/fragment/"))
- .to eq("https://example.com/path/another/fragment/")
- expect(described_class::Builder.call(storage, "/path/", "another/fragment"))
- .to eq("https://example.com/path/another/fragment")
- expect(described_class::Builder.call(storage, "/path/", "/another/", "/fragment/"))
- .to eq("https://example.com/path/another/fragment/")
- end
-
- it "returns wrong request URLs if interface uses double slashes" do
- # so ... don't use them if you want good results ...
- expect(described_class::Builder.call(storage, "path", "//with-double-slash/"))
- .not_to eq("https://example.com/path//with-double-slash/")
- end
- end
-
- context "with a host url without a trailing slash (legacy)" do
- let(:storage) { create(:nextcloud_storage, host: "https://example.com") }
-
- it "returns the correct request URL" do
- expect(described_class::Builder.call(storage, "/path/")).to eq("https://example.com/path/")
- expect(described_class::Builder.call(storage, "path")).to eq("https://example.com/path")
- end
- end
-
- context "with a host url with path prefix" do
- let(:storage) { create(:nextcloud_storage, host: "https://example.com/html/") }
-
- it "returns the correct request URL" do
- expect(described_class::Builder.call(storage, "/path/")).to eq("https://example.com/html/path/")
- expect(described_class::Builder.call(storage, "path")).to eq("https://example.com/html/path")
- end
- end
-
- context "with a host url with path prefix and no trailing slash (legacy)" do
- let(:storage) { create(:nextcloud_storage, host: "https://example.com/html") }
-
- it "returns the correct request URL" do
- expect(described_class::Builder.call(storage, "/path/")).to eq("https://example.com/html/path/")
- expect(described_class::Builder.call(storage, "path")).to eq("https://example.com/html/path")
- end
- end
- end
-
- context "if storage is of OneDrive/SharePoint provider type" do
- let(:storage) { create(:one_drive_storage) }
-
- it "returns the correct request URL" do
- expect(described_class::Builder.call(storage, "/path/")).to eq("https://graph.microsoft.com/path/")
- expect(described_class::Builder.call(storage, "/path")).to eq("https://graph.microsoft.com/path")
- expect(described_class::Builder.call(storage, "path/")).to eq("https://graph.microsoft.com/path/")
- expect(described_class::Builder.call(storage, "path")).to eq("https://graph.microsoft.com/path")
-
- expect(described_class::Builder.call(storage, "path", "/to/", "/request"))
- .to eq("https://graph.microsoft.com/path/to/request")
- end
- end
- end
-end
diff --git a/modules/storages/spec/features/create_file_links_spec.rb b/modules/storages/spec/features/create_file_links_spec.rb
index 2b87c0286ed..2beec9ef0e9 100644
--- a/modules/storages/spec/features/create_file_links_spec.rb
+++ b/modules/storages/spec/features/create_file_links_spec.rb
@@ -66,7 +66,7 @@ RSpec.describe "Managing file links in work package", :js, :webmock do
->(_) { ServiceResult.success }
)
- stub_request(:propfind, "#{storage.host}/remote.php/dav/files/#{oauth_client_token.origin_user_id}/")
+ stub_request(:propfind, "#{storage.host}/remote.php/dav/files/#{oauth_client_token.origin_user_id}")
.to_return(status: 207, body: root_xml_response, headers: {})
stub_request(:propfind, "#{storage.host}/remote.php/dav/files/#{oauth_client_token.origin_user_id}/Folder1")
.to_return(status: 207, body: folder1_xml_response, headers: {})
diff --git a/modules/storages/spec/features/manage_project_storage_spec.rb b/modules/storages/spec/features/manage_project_storage_spec.rb
index 961bab1a55b..86827287247 100644
--- a/modules/storages/spec/features/manage_project_storage_spec.rb
+++ b/modules/storages/spec/features/manage_project_storage_spec.rb
@@ -84,7 +84,7 @@ RSpec.describe("Activation of storages in projects",
before do
oauth_client_token
- stub_request(:propfind, "#{storage.host}/remote.php/dav/files/#{oauth_client_token.origin_user_id}/")
+ stub_request(:propfind, "#{storage.host}/remote.php/dav/files/#{oauth_client_token.origin_user_id}")
.to_return(status: 207, body: root_xml_response, headers: {})
stub_request(:propfind, "#{storage.host}/remote.php/dav/files/#{oauth_client_token.origin_user_id}/Folder1")
.to_return(status: 207, body: folder1_xml_response, headers: {})
@@ -93,7 +93,7 @@ RSpec.describe("Activation of storages in projects",
stub_request(:get, "#{storage.host}/ocs/v1.php/cloud/user").to_return(status: 200, body: "{}")
stub_request(
:delete,
- "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/Project%20name%20without%20sequence%20(#{project.id})/"
+ "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/Project%20name%20without%20sequence%20(#{project.id})"
).to_return(status: 200, body: "", headers: {})
storage
@@ -104,7 +104,7 @@ RSpec.describe("Activation of storages in projects",
it "adds, edits and removes storages to projects" do
# Go to Projects -> Settings -> File Storages
visit project_settings_general_path(project)
- page.click_link("Files")
+ page.click_on("Files")
# Check for an empty table in Project -> Settings -> File storages
expect(page).to have_title("Files")
@@ -115,7 +115,7 @@ RSpec.describe("Activation of storages in projects",
# Can cancel the creation of a new file storage
expect(page).to have_current_path new_project_settings_project_storage_path(project_id: project)
expect(page).to have_text("Add a file storage")
- page.click_link("Cancel")
+ page.click_on("Cancel")
expect(page).to have_current_path external_file_storages_project_settings_project_storages_path(project)
# Enable one file storage together with a project folder mode
@@ -124,7 +124,7 @@ RSpec.describe("Activation of storages in projects",
expect(page).to have_text("Add a file storage")
expect(page).to have_select("storages_project_storage_storage_id",
options: ["#{storage.name} (#{storage.short_provider_type})"])
- page.click_button("Continue")
+ page.click_on("Continue")
# by default automatic have to be choosen if storage has automatic management enabled
expect(page).to have_checked_field("New folder with automatically managed permissions")
@@ -133,7 +133,7 @@ RSpec.describe("Activation of storages in projects",
# Select project folder
expect(page).to have_text("No selected folder")
- page.click_button("Select folder")
+ page.click_on("Select folder")
location_picker.expect_open
using_wait_time(20) do
location_picker.wait_for_folder_loaded
@@ -144,7 +144,7 @@ RSpec.describe("Activation of storages in projects",
# Add storage
expect(page).to have_text("Folder1")
- page.click_button("Add")
+ page.click_on("Add")
# The list of enabled file storages should now contain Storage 1
expect(page).to have_css("h1", text: "Files")
@@ -152,9 +152,10 @@ RSpec.describe("Activation of storages in projects",
# Press Edit icon to change the project folder mode to inactive
page.find(".icon.icon-edit").click
- expect(page).to have_current_path edit_project_settings_project_storage_path(project_id: project,
- id: Storages::ProjectStorage.last,
- storages_project_storage: { project_folder_mode: "manual" })
+ path = edit_project_settings_project_storage_path(project_id: project,
+ id: Storages::ProjectStorage.last,
+ storages_project_storage: { project_folder_mode: "manual" })
+ expect(page).to have_current_path(path)
expect(page).to have_text("Edit the file storage to this project")
expect(page).to have_no_select("storages_project_storage_storage_id")
expect(page).to have_text(storage.name)
@@ -164,7 +165,7 @@ RSpec.describe("Activation of storages in projects",
# Change the project folder mode to inactive, project folder is hidden but retained
page.find_by_id("storages_project_storage_project_folder_mode_inactive").click
expect(page).to have_no_text("Folder1")
- page.click_button("Save")
+ page.click_on("Save")
# The list of enabled file storages should still contain Storage 1
expect(page).to have_css("h1", text: "Files")
@@ -172,11 +173,12 @@ RSpec.describe("Activation of storages in projects",
# Click Edit icon again but cancel the edit
page.find(".icon.icon-edit").click
- expect(page).to have_current_path edit_project_settings_project_storage_path(project_id: project,
- id: Storages::ProjectStorage.last,
- storages_project_storage: { project_folder_mode: "inactive" })
+ path = edit_project_settings_project_storage_path(project_id: project,
+ id: Storages::ProjectStorage.last,
+ storages_project_storage: { project_folder_mode: "inactive" })
+ expect(page).to have_current_path(path)
expect(page).to have_text("Edit the file storage to this project")
- page.click_link("Cancel")
+ page.click_on("Cancel")
expect(page).to have_current_path external_file_storages_project_settings_project_storages_path(project)
# Press Delete icon to remove the storage from the project
@@ -188,14 +190,14 @@ RSpec.describe("Activation of storages in projects",
expect(page).to have_button("Delete", disabled: true)
# Cancel Confirmation
- page.click_link("Cancel")
+ page.click_on("Cancel")
expect(page).to have_current_path external_file_storages_project_settings_project_storages_path(project)
page.find(".icon.icon-delete").click
# Approve Confirmation
page.fill_in "delete_confirmation", with: storage.name
- page.click_button("Delete")
+ page.click_on("Delete")
# List of ProjectStorages empty again
expect(page).to have_current_path external_file_storages_project_settings_project_storages_path(project)
diff --git a/modules/storages/spec/services/storages/nextcloud_group_folder_properties_sync_service_spec.rb b/modules/storages/spec/services/storages/nextcloud_group_folder_properties_sync_service_spec.rb
index 9bf3bde81e1..7066d0f1249 100644
--- a/modules/storages/spec/services/storages/nextcloud_group_folder_properties_sync_service_spec.rb
+++ b/modules/storages/spec/services/storages/nextcloud_group_folder_properties_sync_service_spec.rb
@@ -764,7 +764,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
request_stubs[2] = stub_request(
:mkcol,
"#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \
- "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})/"
+ "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})"
).with(
headers: {
"Authorization" => "Basic T3BlblByb2plY3Q6MTIzNDU2Nzg="
@@ -789,7 +789,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
expect(OpenProject.logger)
.to have_received(:warn)
- .with(folder: "OpenProject/[Sample] Project Name | Ehuu (#{project1.id})/",
+ .with(folder: "/OpenProject/[Sample] Project Name | Ehuu (#{project1.id})/",
command: Storages::Peripherals::StorageInteraction::Nextcloud::CreateFolderCommand,
message: "Outbound request destination not found!",
data: "not found")
@@ -831,7 +831,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
before do
request_stubs[6] = stub_request(:proppatch,
"#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \
- "Lost%20Jedi%20Project%20Folder%20%232/")
+ "Lost%20Jedi%20Project%20Folder%20%232")
.with(body: hide_folder_set_permissions_request_body,
headers: {
"Authorization" => "Basic T3BlblByb2plY3Q6MTIzNDU2Nzg="
@@ -852,7 +852,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
expect(OpenProject.logger)
.to have_received(:warn)
.with(context: "hide_folder",
- folder: "OpenProject/Lost Jedi Project Folder #2/",
+ folder: "/OpenProject/Lost Jedi Project Folder #2/",
command: Storages::Peripherals::StorageInteraction::Nextcloud::SetPermissionsCommand,
message: "Outbound request failed",
data: { status: 500, body: "A server error occurred" })
@@ -863,7 +863,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
before do
request_stubs[8] = stub_request(:proppatch,
"#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \
- "Jedi%20Project%20Folder%20%7C%7C%7C%20%28#{project2.id}%29/")
+ "Jedi%20Project%20Folder%20%7C%7C%7C%20%28#{project2.id}%29")
.with(body: set_permissions_request_body,
headers: { "Authorization" => "Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=" })
.to_return(status: 500,
@@ -883,7 +883,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
expect(OpenProject.logger)
.to have_received(:warn)
- .with(folder: "OpenProject/Jedi Project Folder ||| (#{project2.id})/",
+ .with(folder: "/OpenProject/Jedi Project Folder ||| (#{project2.id})/",
command: Storages::Peripherals::StorageInteraction::Nextcloud::SetPermissionsCommand,
message: "Outbound request failed",
data: { status: 500, body: "Divide by cucumber error. Please reinstall universe and reboot." })
@@ -990,7 +990,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
request_stubs << stub_request(
:mkcol,
"#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \
- "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})/"
+ "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})"
).with(
headers: {
"Authorization" => "Basic T3BlblByb2plY3Q6MTIzNDU2Nzg="
@@ -1001,7 +1001,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
request_stubs << stub_request(
:propfind,
"#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \
- "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})/"
+ "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})"
).with(
body: propfind_folder_info_request_body,
headers: {
@@ -1039,7 +1039,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
request_stubs << stub_request(
:proppatch,
"#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \
- "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})/"
+ "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})"
).with(
body: created_folder_set_permissions_request_body,
headers: {
@@ -1052,7 +1052,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
# 7 - Hide Unknown Inactive Folder
request_stubs << stub_request(
:proppatch,
- "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/Lost%20Jedi%20Project%20Folder%20%232/"
+ "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/Lost%20Jedi%20Project%20Folder%20%232"
).with(
body: hide_folder_set_permissions_request_body,
headers: {
@@ -1065,7 +1065,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
# 8 - Hide Inactive Project Folder
request_stubs << stub_request(
:proppatch,
- "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/NOT%20ACTIVE%20PROJECT/"
+ "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/NOT%20ACTIVE%20PROJECT"
).with(
body: set_permissions_request_body5,
headers: {
@@ -1077,7 +1077,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
request_stubs << stub_request(
:proppatch,
"#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \
- "Jedi%20Project%20Folder%20%7C%7C%7C%20%28#{project2.id}%29/"
+ "Jedi%20Project%20Folder%20%7C%7C%7C%20%28#{project2.id}%29"
).with(
body: set_permissions_request_body,
headers: {
@@ -1088,7 +1088,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
# 10 - Set public project folder permissions
request_stubs << stub_request(
:proppatch,
- "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/PUBLIC%20PROJECT%20%28#{project_public.id}%29/"
+ "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/PUBLIC%20PROJECT%20%28#{project_public.id}%29"
).with(
body: set_permissions_request_body6,
headers: {
@@ -1099,7 +1099,7 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
# 11
request_stubs << stub_request(
:proppatch,
- "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/Project3%20%28#{project3.id}%29/"
+ "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/Project3%20%28#{project3.id}%29"
).with(
body: set_permissions_request_body,
headers: {
diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/file_path_to_id_map_query_root.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/file_path_to_id_map_query_root.yml
index ba95d5d2c2a..562e2ad833f 100644
--- a/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/file_path_to_id_map_query_root.yml
+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/file_path_to_id_map_query_root.yml
@@ -2,7 +2,7 @@
http_interactions:
- request:
method: propfind
- uri: https://nextcloud.local/remote.php/dav/files/admin/
+ uri: https://nextcloud.local/remote.php/dav/files/admin
body:
encoding: UTF-8
string: |
diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/files_query_root.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/files_query_root.yml
index 6ce2880d83a..36f74cde53d 100644
--- a/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/files_query_root.yml
+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/files_query_root.yml
@@ -2,7 +2,7 @@
http_interactions:
- request:
method: propfind
- uri: https://nextcloud.local/remote.php/dav/files/admin/
+ uri: https://nextcloud.local/remote.php/dav/files/admin
body:
encoding: UTF-8
string: |
diff --git a/modules/storages/spec/workers/storages/copy_project_folders_job_spec.rb b/modules/storages/spec/workers/storages/copy_project_folders_job_spec.rb
index 5e6f3ff2462..09a4588b6ea 100644
--- a/modules/storages/spec/workers/storages/copy_project_folders_job_spec.rb
+++ b/modules/storages/spec/workers/storages/copy_project_folders_job_spec.rb
@@ -157,7 +157,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock, with_good_job_ba
GoodJob.perform_inline
Storages::FileLink.where(container: target_work_packages).find_each do |file_link|
- expect(file_link.origin_id).to eq(target_deep_file_ids["/#{target.managed_project_folder_path}#{file_link.name}"].id)
+ expect(file_link.origin_id).to eq(target_deep_file_ids["#{target.managed_project_folder_path}#{file_link.name}"].id)
end
end