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

remove comments and unnecessary files

Marcello Rochabeeacef69e80
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 0157f0fb6cc..19dd527df74 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
@@ -26,102 +26,109 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Storages::Peripherals::StorageInteraction::Nextcloud
- class CopyTemplateFolderCommand
- using Storages::Peripherals::ServiceResultRefinements
-
- def self.call(storage:, source_path:, destination_path:)
- new(storage).call(source_path:, destination_path:)
- end
-
- def initialize(storage)
- @storage = storage
- end
-
- def call(source_path:, destination_path:)
- valid_input_result = validate_inputs(source_path, destination_path).on_failure { |failure| return failure }
-
- remote_urls = build_origin_urls(**valid_input_result.result)
-
- remote_folder_does_not_exist?(remote_urls[:destination_url]).on_failure { |failure| return failure }
-
- copy_folder(**remote_urls).on_failure { |failure| return failure }
-
- get_folder_id(valid_input_result.result[:destination_path]).on_success do |command_result|
- return ServiceResult
- .success(result: { id: command_result.result[destination_path]['fileid'], url: remote_urls[:destination_url] })
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module Nextcloud
+ class CopyTemplateFolderCommand
+ using ServiceResultRefinements
+
+ def self.call(storage:, source_path:, destination_path:)
+ new(storage).call(source_path:, destination_path:)
+ end
+
+ def initialize(storage)
+ @storage = storage
+ @data = ResultData::CopyTemplateFolder.new(id: nil, polling_url: nil, requires_polling: false)
+ end
+
+ def call(source_path:, destination_path:)
+ valid_input_result = validate_inputs(source_path, destination_path).on_failure { |failure| return failure }
+
+ remote_urls = build_origin_urls(**valid_input_result.result)
+
+ remote_folder_does_not_exist?(remote_urls[:destination_url]).on_failure { |failure| return failure }
+
+ copy_folder(**remote_urls).on_failure { |failure| return failure }
+
+ get_folder_id(valid_input_result.result[:destination_path]).on_success do |command_result|
+ return ServiceResult
+ .success(result: @data.with(id: command_result.result[destination_path]["fileid"]))
+ end
+ end
+
+ private
+
+ def validate_inputs(source_path, destination_path)
+ if source_path.blank? || destination_path.blank?
+ return Util.error(:error, "Source and destination paths must be present.")
+ end
+
+ ServiceResult.success(result: { source_path:, destination_path: })
+ 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:, destination_url: }
+ end
+
+ def remote_folder_does_not_exist?(destination_url)
+ response = OpenProject.httpx.basic_auth(@storage.username, @storage.password).head(destination_url)
+
+ case response
+ in { status: 200..299 }
+ Util.error(:conflict, "Destination folder already exists.")
+ in { status: 401 }
+ Util.error(:unauthorized, "unauthorized (validate_destination)")
+ in { status: 404 }
+ ServiceResult.success
+ else
+ Util.error(:unknown, "Unexpected response (validate_destination): #{response.code}", response)
+ end
+ end
+
+ def copy_folder(source_url:, destination_url:)
+ response = OpenProject
+ .httpx
+ .basic_auth(@storage.username, @storage.password)
+ .request("COPY", source_url, headers: { "Destination" => destination_url, "Depth" => "infinity" })
+
+ case response
+ in { status: 200..299 }
+ ServiceResult.success(message: "Folder was successfully copied")
+ in { status: 401 }
+ Util.error(:unauthorized, "Unauthorized (copy_folder)")
+ in { status: 404 }
+ Util.error(:not_found, "Project folder not found (copy_folder)")
+ in { status: 409 }
+ Util.error(:conflict, Util.error_text_from_response(response))
+ else
+ Util.error(:unknown, "Unexpected response (copy_folder): #{response.status}", response)
+ end
+ end
+
+ def get_folder_id(destination_path)
+ Registry
+ .resolve("#{@storage.short_provider_type}.queries.file_ids")
+ .call(storage: @storage, path: destination_path)
+ end
+ end
end
end
-
- private
-
- def validate_inputs(source_path, destination_path)
- if source_path.blank? || destination_path.blank?
- return Util.error(:error, 'Source and destination paths must be present.')
- end
-
- ServiceResult.success(result: { source_path:, destination_path: })
- 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:, destination_url: }
- end
-
- def remote_folder_does_not_exist?(destination_url)
- response = OpenProject.httpx.basic_auth(@storage.username, @storage.password).head(destination_url)
-
- case response
- in { status: 200..299 }
- Util.error(:conflict, 'Destination folder already exists.')
- in { status: 401 }
- Util.error(:unauthorized, "unauthorized (validate_destination)")
- in { status: 404 }
- ServiceResult.success
- else
- Util.error(:unknown, "Unexpected response (validate_destination): #{response.code}", response)
- end
- end
-
- def copy_folder(source_url:, destination_url:)
- response = OpenProject
- .httpx
- .basic_auth(@storage.username, @storage.password)
- .request('COPY', source_url, headers: { 'Destination' => destination_url, 'Depth' => 'infinity' })
-
- case response
- in { status: 200..299 }
- ServiceResult.success(message: 'Folder was successfully copied')
- in { status: 401 }
- Util.error(:unauthorized, "Unauthorized (copy_folder)")
- in { status: 404 }
- Util.error(:not_found, "Project folder not found (copy_folder)")
- in { status: 409 }
- Util.error(:conflict, Util.error_text_from_response(response))
- else
- Util.error(:unknown, "Unexpected response (copy_folder): #{response.status}", response)
- end
- end
-
- def get_folder_id(destination_path)
- Storages::Peripherals::Registry
- .resolve("#{@storage.short_provider_type}.queries.file_ids")
- .call(storage: @storage, path: destination_path)
- end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/copy_template_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/copy_template_folder_command.rb
index 1a226667ed8..30fc2a1a397 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/copy_template_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/copy_template_folder_command.rb
@@ -38,7 +38,7 @@ module Storages
return ServiceResult.failure(
result: :error,
errors: StorageError.new(code: :error,
- log_message: 'Both source and destination paths need to be present')
+ log_message: "Both source and destination paths need to be present")
)
end
@@ -47,6 +47,7 @@ module Storages
def initialize(storage)
@storage = storage
+ @data = ResultData::CopyTemplateFolder.new(id: nil, polling_url: nil, requires_polling: true)
end
def call(source_location:, destination_name:)
@@ -62,15 +63,15 @@ module Storages
def handle_response(response)
case response
in { status: 202 }
- ServiceResult.success(result: { id: nil, url: response.headers[:location] })
+ ServiceResult.success(result: @data.with(polling_url: response.headers[:location]))
in { status: 401 }
ServiceResult.failure(result: :unauthorized)
in { status: 403 }
ServiceResult.failure(result: :forbidden)
in { status: 404 }
- ServiceResult.failure(result: :not_found, message: 'Template folder not found')
+ ServiceResult.failure(result: :not_found, message: "Template folder not found")
in { status: 409 }
- ServiceResult.failure(result: :conflict, message: 'The copy would overwrite an already existing folder')
+ ServiceResult.failure(result: :conflict, message: "The copy would overwrite an already existing folder")
else
ServiceResult.failure(result: :error)
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/result_data/copy_template_folder.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/result_data/copy_template_folder.rb
new file mode 100644
index 00000000000..efacc4cb360
--- /dev/null
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/result_data/copy_template_folder.rb
@@ -0,0 +1,11 @@
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module ResultData
+ CopyTemplateFolder = Data.define(:id, :polling_url, :requires_polling) do
+ def requires_polling? = !!requires_polling
+ end
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/services/projects/copy/file_links_dependent_service.rb b/modules/storages/app/services/projects/copy/file_links_dependent_service.rb
deleted file mode 100644
index 27b28a51eaa..00000000000
--- a/modules/storages/app/services/projects/copy/file_links_dependent_service.rb
+++ /dev/null
@@ -1,140 +0,0 @@
-# frozen_string_literal: true
-
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2024 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-module Projects::Copy
- class FileLinksDependentService < Dependency
- def self.human_name
- I18n.t(:"projects.copy.work_package_file_links")
- end
-
- def source_count
- source.work_packages.joins(:file_links).count("file_links.id")
- end
-
- protected
-
- # rubocop:disable Metrics/AbcSize
- # rubocop:disable Metrics/PerceivedComplexity
- def copy_dependency(*)
- # If no work packages were copied, we cannot copy their file_links
- return unless state.work_package_id_lookup
-
- source_wp_ids = state.work_package_id_lookup.keys
- Storages::FileLink
- .where(container_id: source_wp_ids, container_type: "WorkPackage")
- .group_by(&:storage_id)
- .select { |_storage_id, source_file_links| source_file_links.any? }
- .each do |(storage_id, source_file_links)|
- tmp = state
- .copied_project_storages
- .find { |item| item["source"].storage_id == storage_id }
- source_project_storage = tmp["source"]
- target_project_storage = tmp["target"]
- storage = source_project_storage.storage
-
- if source_project_storage.project_folder_mode == "automatic"
- files_info_query_result = files_info_query(storage:,
- file_ids: source_file_links.map(&:origin_id))
- folder_files_file_ids_deep_query_result = folder_files_file_ids_deep_query(
- storage:,
- location: target_project_storage.managed_project_folder_path
- )
- source_file_links.each do |old_file_link|
- attributes = {
- storage_id: old_file_link.storage_id,
- creator_id: User.current.id,
- container_id: state.work_package_id_lookup[old_file_link.container_id.to_s],
- container_type: "WorkPackage",
- origin_name: old_file_link.origin_name,
- origin_mime_type: old_file_link.origin_mime_type
- }
-
- original_file_location = files_info_query_result
- .find { |i| i.id.to_i == old_file_link.origin_id.to_i }
- .location
-
- attributes["origin_id"] =
- if source_project_storage.file_inside_project_folder?(original_file_location)
- new_file_location = original_file_location.gsub(
- source_project_storage.project_folder_path_escaped,
- target_project_storage.project_folder_path_escaped
- )
- new_file_location = CGI.unescape(new_file_location[1..])
- folder_files_file_ids_deep_query_result[new_file_location].id
- else
- old_file_link.origin_id
- end
- Storages::FileLinks::CreateService.new(user: User.current).call(attributes)
- end
- else
- source_file_links.each do |old_file_link|
- attributes = {
- storage_id: old_file_link.storage_id,
- creator_id: User.current.id,
- container_id: state.work_package_id_lookup[old_file_link.container_id.to_s],
- container_type: "WorkPackage",
- origin_name: old_file_link.origin_name,
- origin_mime_type: old_file_link.origin_mime_type,
- origin_id: old_file_link.origin_id
- }
- Storages::FileLinks::CreateService.new(user: User.current).call(attributes)
- end
- end
- end
- end
-
- # rubocop:enable Metrics/AbcSize
- # rubocop:enable Metrics/PerceivedComplexity
-
- def files_info_query(storage:, file_ids:)
- Storages::Peripherals::Registry
- .resolve("#{storage.short_provider_type}.queries.files_info")
- .call(storage:, auth_strategy:, file_ids:)
- .on_failure { |r| add_error!("files_info_query", r.to_active_model_errors) }
- .result
- end
-
- def folder_files_file_ids_deep_query(storage:, location:)
- Storages::Peripherals::Registry
- .resolve("#{storage.short_provider_type}.queries.folder_files_file_ids_deep_query")
- .call(storage:, folder: Storages::Peripherals::ParentFolder.new(location))
- .on_failure { |r| add_error!("folder_files_file_ids_deep_query", r.to_active_model_errors) }
- .result
- end
-
- private
-
- def auth_strategy
- Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken
- .strategy
- .with_user(User.current)
- end
- end
-end
diff --git a/modules/storages/app/services/projects/copy/storage_project_folders_dependent_service.rb b/modules/storages/app/services/projects/copy/storage_project_folders_dependent_service.rb
deleted file mode 100644
index 4f62f4e06e9..00000000000
--- a/modules/storages/app/services/projects/copy/storage_project_folders_dependent_service.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-# frozen_string_literal: true
-
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2024 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-module Projects::Copy
- class StorageProjectFoldersDependentService < Dependency
- using Storages::Peripherals::ServiceResultRefinements
-
- def self.human_name
- I18n.t(:label_project_storage_project_folder)
- end
-
- def source_count
- # we copy the same amount of project folders as storages
- source.storages.count
- end
-
- protected
-
- def copy_dependency(*)
- return unless state.copied_project_storages
-
- GoodJob::Batches.enqueue(on_success: NotifyCopyCompletedJob, project_storages: state.copied_project_storages) do
- state.copied_project_storages.each do |project_storages|
- ::Storages::CopyProjectFoldersJob.enqueue(project_storages[:source], project_storages[:target])
- end
- end
-
- state.copied_project_storages.each do |copied_project_storage|
- source = copied_project_storage[:source]
- target = copied_project_storage[:target]
- if source.project_folder_automatic?
- copy_project_folder(source, target).on_success do |copy_result|
- target.update!(project_folder_id: copy_result.result[:id], project_folder_mode: 'automatic')
- end
- elsif source.project_folder_manual?
- target.update!(project_folder_id: source.project_folder_id, project_folder_mode: 'manual')
- end
- end
- end
-
- private
-
- def copy_project_folder(source_project_storage, destination_project_storage)
- source_folder_name = source_project_storage.project_folder_location
- destination_folder_name = destination_project_storage.managed_project_folder_path
-
- Storages::Peripherals::Registry
- .resolve("#{source_project_storage.storage.short_provider_type}.commands.copy_template_folder")
- .call(
- storage: source_project_storage.storage,
- source_path: source_folder_name,
- destination_path: destination_folder_name
- ).on_failure { |r| add_error!(source_folder_name, r.to_active_model_errors) }
- end
- end
-end
diff --git a/modules/storages/app/services/storages/file_links/copy_file_links_service.rb b/modules/storages/app/services/storages/file_links/copy_file_links_service.rb
index 1c50496786c..dd85313c58b 100644
--- a/modules/storages/app/services/storages/file_links/copy_file_links_service.rb
+++ b/modules/storages/app/services/storages/file_links/copy_file_links_service.rb
@@ -47,29 +47,30 @@ module Storages
.includes(:creator)
.where(container_id: @work_packages_map.keys, container_type: "WorkPackage")
- return create_unmanaged_file_links(source_file_links) if @source.project_folder_manual?
-
- create_managed_file_links(source_file_links)
+ if @source.project_folder_automatic?
+ create_managed_file_links(source_file_links)
+ else
+ create_unmanaged_file_links(source_file_links)
+ end
end
private
def create_managed_file_links(source_file_links)
- target_files = target_files_map.result
- source_files = source_files_info(source_file_links).result
-
- location_map = build_location_map(source_files, target_files)
+ location_map = build_location_map(
+ source_files_info(source_file_links).result,
+ target_files_map.result
+ )
source_file_links.find_each do |source_link|
attributes = source_link.dup.attributes
-
attributes.merge!(
- 'creator_id' => @user.id,
- 'container_id' => @work_packages_map[source_link.container_id],
- 'origin_id' => location_map[source_link.origin_id]
+ "creator_id" => @user.id,
+ "container_id" => @work_packages_map[source_link.container_id],
+ "origin_id" => location_map[source_link.origin_id]
)
- FileLinks::CreateService.new(user: @user).call(attributes)
+ CreateService.new(user: @user).call(attributes).on_failure { |failed| log_errors(failed) }
end
end
@@ -99,13 +100,16 @@ module Storages
source_file_links.find_each do |source_file_link|
attributes = source_file_link.dup.attributes
- attributes['creator_id'] = @user.id
- attributes['container_id'] = @work_packages_map[source_file_link.container_id]
+ attributes["creator_id"] = @user.id
+ attributes["container_id"] = @work_packages_map[source_file_link.container_id]
- # TODO: Do something when this fails
- ::Storages::FileLinks::CreateService.new(user: @user).call(attributes)
+ FileLinks::CreateService.new(user: @user).call(attributes).on_failure { |failed| log_errors(failed) }
end
end
+
+ def log_errors(failure)
+ OpenProject.logger.warn failure.errors.inspect
+ end
end
end
end
diff --git a/modules/storages/app/services/storages/project_storages/copy_project_folders_service.rb b/modules/storages/app/services/storages/project_storages/copy_project_folders_service.rb
index 2cb9af09f5e..3957ffe04b1 100644
--- a/modules/storages/app/services/storages/project_storages/copy_project_folders_service.rb
+++ b/modules/storages/app/services/storages/project_storages/copy_project_folders_service.rb
@@ -31,14 +31,18 @@
module Storages
module ProjectStorages
class CopyProjectFoldersService
- # We might need the User too
def self.call(source:, target:)
new.call(source, target)
end
+ def initialize
+ @data = Peripherals::StorageInteraction::ResultData::CopyTemplateFolder
+ .new(id: nil, polling_url: nil, requires_polling: false)
+ end
+
def call(source, target)
- return ServiceResult.success(result: { id: nil }) if source.project_folder_inactive?
- return ServiceResult.success(result: { id: source.project_folder_id }) if source.project_folder_manual?
+ return ServiceResult.success(result: @data) if source.project_folder_inactive?
+ return ServiceResult.success(result: @data.with(id: source.project_folder_id)) if source.project_folder_manual?
Peripherals::Registry
.resolve("#{source.storage.short_provider_type}.commands.copy_template_folder")
diff --git a/modules/storages/app/workers/storages/copy_project_folders_job.rb b/modules/storages/app/workers/storages/copy_project_folders_job.rb
index 7f0a2f1ec3e..3c71890ceb8 100644
--- a/modules/storages/app/workers/storages/copy_project_folders_job.rb
+++ b/modules/storages/app/workers/storages/copy_project_folders_job.rb
@@ -30,41 +30,37 @@
module Storages
class CopyProjectFoldersJob < ApplicationJob
- # include GoodJob::ActiveJobExtensions::Batches
-
- retry_on Errors::PollingRequired, wait: 3, attempts: :unlimited
- # discard_on HTTPX::HTTPError
+ retry_on Errors::PollingRequired, wait: 3, attempts: (Rails.env.test? ? 3 : :unlimited)
+ discard_on HTTPX::HTTPError
def perform(user_id:, source_id:, target_id:, work_package_map:)
target = ProjectStorage.find(target_id)
source = ProjectStorage.find(source_id)
user = User.find(user_id)
- # TODO: Do Something when this fails
- project_folder_result = if polling?
- results_from_polling
- else
- ProjectStorages::CopyProjectFoldersService
- .call(source:, target:)
- .on_success { |success| prepare_polling(success.result) }
- end
+ project_folder_result = results_from_polling || initiate_copy(source, target)
- # TODO: Do Something when this fails
ProjectStorages::UpdateService.new(user:, model: target)
- .call(project_folder_id: project_folder_result.result[:id],
+ .call(project_folder_id: project_folder_result.result.id,
project_folder_mode: source.project_folder_mode)
+ .on_failure { |failed| log_failure(failed) and return failed }
- # TODO: Collect errors
FileLinks::CopyFileLinksService.call(source:, target:, user:, work_packages_map: work_package_map)
end
private
- def prepare_polling(result)
- return if result[:id]
+ def initiate_copy(source, target)
+ ProjectStorages::CopyProjectFoldersService
+ .call(source:, target:)
+ .on_success { |success| prepare_polling(success.result, source) }
+ end
+
+ def prepare_polling(result, source)
+ return unless result.requires_polling?
- Thread.current[job_id] = result[:url]
- raise Errors::PollingRequired, "#{job_id} Storage requires polling"
+ Thread.current[job_id] = result.polling_url
+ raise Errors::PollingRequired, "Storage #{source.storage.name} requires polling"
end
def polling?
@@ -72,13 +68,23 @@ module Storages
end
def results_from_polling
- # TODO: Maybe Transform this in a Query
+ return unless polling?
+
response = OpenProject.httpx.get(Thread.current[job_id]).json(symbolize_keys: true)
- raise(Errors::PollingRequired, "#{job_id} Polling not completed yet") if response[:status] != 'completed'
+ # FIXME: We may want to discard in case some other error is raised
+ raise(Errors::PollingRequired, "#{job_id} Polling not completed yet") if response[:status] != "completed"
Thread.current[job_id] = nil
- ServiceResult.success(result: { id: response[:resourceId] })
+ result = Peripherals::StorageInteraction::ResultData::CopyTemplateFolder.new(response[:resourceId], nil, false)
+
+ ServiceResult.success(result:)
+ end
+
+ def log_failure(failed)
+ return if failed.success?
+
+ OpenProject.logger.warn failed.errors.inspect.to_s
end
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 ec589c584fa..eae9d44e0a4 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
@@ -115,8 +115,7 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::CopyTemplat
result = subject.call(source_path:, destination_path:)
expect(result).to be_success
- expect(result.result[:id]).to eq('349')
- expect(result.result[:url]).to eq(destination_url)
+ expect(result.result.id).to eq('349')
end
end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/copy_template_folder_command_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/copy_template_folder_command_spec.rb
index 932e03acbff..ad073967001 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/copy_template_folder_command_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/copy_template_folder_command_spec.rb
@@ -95,9 +95,10 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::CopyTemplate
command_result = described_class.call(storage:, source_path:, destination_path: 'My New Folder')
expect(command_result).to be_success
- expect(command_result.result[:url]).to match %r</drives/#{storage.drive_id}/items/.+\?.+$>
+ expect(command_result.result.requires_polling?).to be_truthy
+ expect(command_result.result.polling_url).to match %r</drives/#{storage.drive_id}/items/.+\?.+$>
ensure
- delete_copied_folder(command_result.result[:url])
+ delete_copied_folder(command_result.result.polling_url)
end
describe 'error handling' do
diff --git a/modules/storages/spec/services/storages/project_storages/copy_project_folders_service_spec.rb b/modules/storages/spec/services/storages/project_storages/copy_project_folders_service_spec.rb
index 2e9179302b7..aae1dbce88c 100644
--- a/modules/storages/spec/services/storages/project_storages/copy_project_folders_service_spec.rb
+++ b/modules/storages/spec/services/storages/project_storages/copy_project_folders_service_spec.rb
@@ -35,6 +35,7 @@ RSpec.describe Storages::ProjectStorages::CopyProjectFoldersService, :webmock do
let(:storage) { create(:nextcloud_storage, :as_automatically_managed) }
let(:target) { create(:project_storage, storage:) }
let(:system_user) { create(:system) }
+ let(:result_data) { Storages::Peripherals::StorageInteraction::ResultData::CopyTemplateFolder.new(nil, nil, false) }
subject(:service) { described_class }
@@ -50,13 +51,14 @@ RSpec.describe Storages::ProjectStorages::CopyProjectFoldersService, :webmock do
expect(destination_path).to eq(target.managed_project_folder_path)
# Return a success for the provider copy with no polling required
- ServiceResult.success(result: { id: nil, url: 'https://polling.url.de/cool/subresources' })
+ ServiceResult.success(result: result_data.with(polling_url: 'https://polling.url.de/cool/subresources'))
end)
result = service.call(source:, target:)
expect(result).to be_success
- expect(result.result).to eq({ id: nil, url: 'https://polling.url.de/cool/subresources' })
+ expect(result.result.to_h).to eq({ id: nil, polling_url: 'https://polling.url.de/cool/subresources',
+ requires_polling: false })
end
end
@@ -71,7 +73,7 @@ RSpec.describe Storages::ProjectStorages::CopyProjectFoldersService, :webmock do
it 'returns the source folder id' do
result = service.call(source:, target:)
- expect(result.result[:id]).to eq(source.project_folder_id)
+ expect(result.result.id).to eq(source.project_folder_id)
end
end
@@ -85,7 +87,7 @@ RSpec.describe Storages::ProjectStorages::CopyProjectFoldersService, :webmock do
it 'returns the origin folder id (nil)' do
result = service.call(source:, target:)
- expect(result.result[:id]).to eq(source.project_folder_id)
+ expect(result.result.id).to eq(source.project_folder_id)
end
end
end
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 4d479773ef1..b5b2a2d8311 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
@@ -52,6 +52,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock do
end
let(:polling_url) { 'https://polling.url.de/cool/subresources' }
+ let(:copy_result) { Storages::Peripherals::StorageInteraction::ResultData::CopyTemplateFolder.new(nil, nil, false) }
let(:target_deep_file_ids) do
source_file_links.each_with_object({}) do |fl, hash|
@@ -129,7 +130,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock do
Storages::Peripherals::Registry
.stub("#{storage.short_provider_type}.commands.copy_template_folder", ->(storage:, source_path:, destination_path:) {
- ServiceResult.success(result: { id: 'copied-folder', url: 'resource-url' })
+ ServiceResult.success(result: copy_result.with(id: 'copied-folder', polling_url:))
})
end
@@ -158,7 +159,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock do
before do
Storages::Peripherals::Registry
.stub("#{storage.short_provider_type}.commands.copy_template_folder", ->(storage:, source_path:, destination_path:) {
- ServiceResult.success(result: { id: nil, url: polling_url })
+ ServiceResult.success(result: copy_result.with(polling_url:, requires_polling: true))
})
Storages::Peripherals::Registry
diff --git a/spec/features/projects/copy_spec.rb b/spec/features/projects/copy_spec.rb
index 825d4f7f506..3ecd33e6a01 100644
--- a/spec/features/projects/copy_spec.rb
+++ b/spec/features/projects/copy_spec.rb
@@ -137,7 +137,10 @@ RSpec.describe "Projects copy", :js, :with_cuprite do
let(:parent_field) { FormFields::SelectFormField.new :parent }
let(:storage) { create(:nextcloud_storage) }
- let(:project_storage) { create(:project_storage, project:, storage:) }
+ let(:project_storage) do
+ create(:project_storage, project:, storage:)
+ end
+
let(:file_link) { create(:file_link, container: work_package, storage:) }
before do