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

- Disable the command while we figure out the best approach to handle async copy - Fix old inst_vars references. - Renames parameters on CopyFolder#call - Mirror the project_folder_location on project_folder_path

Marcello Rocha2de3839488c4
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 992d9a2a578..ac669b58017 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb
@@ -84,7 +84,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
end
def remote_folder_does_not_exist?(destination_url)
- response = OpenProject.httpx.basic_auth(@username, @password).head(destination_url)
+ response = OpenProject.httpx.basic_auth(@storage.username, @storage.password).head(destination_url)
case response
in { status: 200..299 }
@@ -101,7 +101,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
def copy_folder(source_url:, destination_url:)
response = OpenProject
.httpx
- .basic_auth(@username, @password)
+ .basic_auth(@storage.username, @storage.password)
.request('COPY', source_url, headers: { 'Destination' => destination_url, 'Depth' => 'infinity' })
case response
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb
index d52ef75cbcd..65de8a06d87 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb
@@ -46,7 +46,6 @@ module Storages
Commands = Dry::Container::Namespace.new('commands') do
namespace('one_drive') do
- register(:copy_template_folder, CopyTemplateFolderCommand)
register(:create_folder, CreateFolderCommand)
register(:delete_folder, DeleteFolderCommand)
register(:rename_file, RenameFileCommand)
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 6f5581f4c94..3c9f58be8b7 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
@@ -34,19 +34,25 @@ module Storages
module OneDrive
class CopyTemplateFolderCommand
def self.call(storage:, source_path:, destination_path:)
- raise ArgumentError if source_path.blank? || destination_path.blank?
+ if source_path.blank? || destination_path.blank?
+ return ServiceResult.failure(
+ result: :error,
+ errors: StorageError.new(code: :error,
+ log_message: 'Both source and destination paths need to be present')
+ )
+ end
- new(storage).call(source_path, destination_path)
+ new(storage).call(source_location: source_path, destination_name: destination_path)
end
def initialize(storage)
@storage = storage
end
- def call(source_path, destination_path)
+ def call(source_location:, destination_name:)
Util.using_admin_token(@storage) do |httpx|
handle_response(
- httpx.post(copy_path_for(source_path), json: payload(destination_path))
+ httpx.post(copy_path_for(source_location), json: { name: destination_name })
)
end
end
@@ -79,10 +85,8 @@ module Storages
match_data[:item_id] if match_data
end
- def payload(destination_path) = { name: destination_path }
-
- def copy_path_for(path)
- "/v1.0/drives/#{@storage.drive_id}/items/#{path}/[email protected]=fail"
+ def copy_path_for(source_location)
+ "/v1.0/drives/#{@storage.drive_id}/items/#{source_location}/[email protected]=fail"
end
end
end
diff --git a/modules/storages/app/models/storages/project_storage.rb b/modules/storages/app/models/storages/project_storage.rb
index 56344dfe59b..f30619398fc 100644
--- a/modules/storages/app/models/storages/project_storage.rb
+++ b/modules/storages/app/models/storages/project_storage.rb
@@ -61,10 +61,14 @@ class Storages::ProjectStorage < ApplicationRecord
end
def project_folder_path
- return "#{storage.group_folder}/#{project.name.tr('/', '|')} (#{project.id})/" if storage.provider_type_nextcloud?
- return "#{project.name.gsub(/[\\<>+?:"|\/]/, '_')} (#{project.id})" if storage.provider_type_one_drive?
-
- raise 'Unknown Storage'
+ case storage.short_provider_type
+ when 'nextcloud'
+ "#{storage.group_folder}/#{project.name.tr('/', '|')} (#{project.id})/"
+ when 'one_drive'
+ "#{project.name.gsub(/[\\<>+?:"|\/]/, '_')} (#{project.id})"
+ else
+ raise 'Unknown Storage'
+ end
end
def project_folder_location
diff --git a/modules/storages/app/models/storages/storage_error.rb b/modules/storages/app/models/storages/storage_error.rb
index cfa9232558d..dd8cdefe63d 100644
--- a/modules/storages/app/models/storages/storage_error.rb
+++ b/modules/storages/app/models/storages/storage_error.rb
@@ -28,32 +28,37 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Storages::StorageError
- extend ActiveModel::Naming
+module Storages
+ class StorageError
+ extend ActiveModel::Naming
- attr_reader :code, :log_message, :data
+ attr_reader :code, :log_message, :data
- def initialize(code:, log_message: nil, data: nil)
- @code = code
- @log_message = log_message
- @data = data
- end
+ def initialize(code:, log_message: nil, data: nil)
+ @code = code
+ @log_message = log_message
+ @data = data
+ end
- def to_active_model_errors
- errors = ActiveModel::Errors.new(self)
- errors.add(:storage_error, code, message: log_message)
- errors
- end
+ def to_active_model_errors
+ errors = ActiveModel::Errors.new(self)
+ errors.add(:storage_error, code, message: log_message)
+ errors
+ end
- def to_s
- output = code.to_s
- output << " | #{log_message}" unless log_message.nil?
- output << " | #{data}" unless data.nil?
- output
- end
+ def to_s
+ output = code.to_s
+ output << " | #{log_message}" unless log_message.nil?
+ output << " | #{data}" unless data.nil?
+ output
+ end
+
+ def storage_error = "storage error"
- def storage_error = "storage error"
- def read_attribute_for_validation(attr) = send(attr)
- def self.human_attribute_name(attr, _options = {}) = attr
- def self.lookup_ancestors = [self]
+ def read_attribute_for_validation(attr) = send(attr)
+
+ def self.human_attribute_name(attr, _options = {}) = attr
+
+ def self.lookup_ancestors = [self]
+ 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 f831d7ffdc2..9a89506fd06 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
@@ -50,7 +50,8 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::CopyTemplate
shared_let(:source_path) { base_template_folder.id }
- it 'is registered under commands.one_drive.copy_template_folder' do
+ it 'is registered under commands.one_drive.copy_template_folder',
+ skip: 'Skipped while we decide on what to do with the copy project folder' do
expect(Storages::Peripherals::Registry.resolve('commands.one_drive.copy_template_folder')).to eq(described_class)
end
@@ -65,7 +66,11 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::CopyTemplate
end
it "destination_path and source_path can't be empty" do
- expect { described_class.call(storage:, source_path: '', destination_path: nil) }.to raise_error ArgumentError
+ missing_source = described_class.call(storage:, source_path: '', destination_path: 'Path')
+ missing_path = described_class.call(storage:, source_path: 'Path', destination_path: nil)
+ missing_both = described_class.call(storage:, source_path: nil, destination_path: '')
+
+ expect([missing_both, missing_path, missing_source]).to all(be_failure)
end
describe '#call' do