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

All command and queries migrated

Marcello Rochad505ec6388dd
diff --git a/modules/storages/app/common/storages/peripherals/registry.rb b/modules/storages/app/common/storages/peripherals/registry.rb
index 32b687d8db3..d981961b139 100644
--- a/modules/storages/app/common/storages/peripherals/registry.rb
+++ b/modules/storages/app/common/storages/peripherals/registry.rb
@@ -5,5 +5,6 @@ module Storages
end
Registry.import StorageInteraction::Nextcloud::Queries
+ Registry.import StorageInteraction::Nextcloud::Commands
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb
index 108cf84aea1..dd2cbe4454b 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb
@@ -44,6 +44,19 @@ module Storages
register(:upload_link_query, UploadLinkQuery)
end
end
+
+ Commands = Dry::Container::Namespace.new('commands') do
+ namespace('nextcloud') do
+ register(:delete_entity_command, Internal::DeleteEntityCommand)
+ register(:add_user_to_group_command, AddUserToGroupCommand)
+ register(:copy_template_folder_command, CopyTemplateFolderCommand)
+ register(:create_folder_command, CreateFolderCommand)
+ register(:delete_folder_command, DeleteFolderCommand)
+ register(:set_permissions_command, SetPermissionsCommand)
+ register(:remove_user_from_group_command, RemoveUserFromGroupCommand)
+ register(:rename_file_command, RenameFileCommand)
+ end
+ end
end
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 c396e4585c9..67ecdd2bb2d 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
@@ -36,6 +36,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
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 = Util.http(@uri).post(
Util.join_uri_path(@uri, 'ocs/v1.php/cloud/users', CGI.escapeURIComponent(user), 'groups'),
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 5957746bbc3..ddda8a14381 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
@@ -36,6 +36,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
@password = storage.password
end
+ def self.call(storage:, source_path:, destination_path:)
+ new(storage).call(source_path:, destination_path:)
+ end
+
def call(source_path:, destination_path:)
validate_inputs(source_path, destination_path) >>
build_origin_paths >>
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 92411b1205a..a309f9c31f4 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
@@ -36,6 +36,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
@password = storage.password
end
+ def self.call(storage:, folder_path:)
+ new(storage).call(folder_path:)
+ end
+
# rubocop:disable Metrics/AbcSize
def call(folder_path:)
response = Util.http(@uri).mkcol(
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/delete_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/delete_folder_command.rb
index 78117222220..4bd735295e8 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/delete_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/delete_folder_command.rb
@@ -32,6 +32,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
@delegate = Internal::DeleteEntityCommand.new(storage)
end
+ def self.call(storage:, location:)
+ new(storage).call(location:)
+ end
+
def call(location:)
@delegate.call(location:)
end
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 da930005c6c..08013648406 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
@@ -37,6 +37,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Internal
@password = storage.password
end
+ def self.call(storage:, location:)
+ new(storage).call(location:)
+ end
+
def call(location:)
response = UTIL.http(@uri).delete(
UTIL.join_uri_path(@base_path, UTIL.escape_path(location)),
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 619946c55a1..7bc4a2b3d83 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
@@ -35,6 +35,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
@group = storage.group
end
+ def self.call(storage:, user:, group: storage.group)
+ new(storage).call(user:, group:)
+ end
+
# rubocop:disable Metrics/AbcSize
def call(user:, group: @group)
response = Util.http(@uri).delete(
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 fa61398218e..2626a9dcea5 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
@@ -37,6 +37,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
@password = storage.password
end
+ def self.call(storage:, source:, target:)
+ new(storage).call(source:, target:)
+ end
+
def call(source:, target:)
response = Util.http(@uri).move(
Util.join_uri_path(@base_path, Util.escape_path(source)),
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 add141ff236..2ce10695d95 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
@@ -36,6 +36,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
@password = storage.password
end
+ def self.call(storage:, path:, permissions:)
+ new(storage).call(path:, permissions:)
+ end
+
# rubocop:disable Metrics/AbcSize
def call(path:, permissions:)
raise ArgumentError if path.blank?
diff --git a/modules/storages/app/common/storages/peripherals/storage_requests.rb b/modules/storages/app/common/storages/peripherals/storage_requests.rb
index 0f62d6f16af..af0071cc819 100644
--- a/modules/storages/app/common/storages/peripherals/storage_requests.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_requests.rb
@@ -28,42 +28,26 @@
module Storages::Peripherals
class StorageRequests
- COMMANDS = %i[
- set_permissions_command
- create_folder_command
- add_user_to_group_command
- delete_folder_command
- remove_user_from_group_command
- rename_file_command
- copy_template_folder_command
- ].freeze
-
def initialize(storage:)
@storage = storage
end
- #
+
# def self.call(storage:, operation:, **)
# Registry.resolve("queries.#{storage.short_provider_type}.#{operation}").call(storage:, **)
# end
- COMMANDS.each do |request|
- define_method(request) do
- clazz = "::Storages::Peripherals::StorageInteraction::" \
- "#{@storage.short_provider_type.capitalize}::#{request.to_s.classify}".constantize
- clazz.new(@storage).method(:call).to_proc
- end
- end
-
private
def method_missing(name, *args)
- Registry.resolve("queries.#{@storage.short_provider_type}.#{name}")
+ resource_type = name.to_s.split('_').last.pluralize
+ Registry.resolve("#{resource_type}.#{@storage.short_provider_type}.#{name}")
rescue Dry::Container::KeyError
super
end
def respond_to_missing?(name)
- !!Registry.resolve("queries.#{@storage.short_provider_type}.#{name}")
+ resource_type = name.to_s.split('_').last.pluralize
+ !!Registry.resolve("#{resource_type}.#{@storage.short_provider_type}.#{name}")
rescue Dry::Container::KeyError
super
end
diff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
index 49c96b997ac..db212e97d8e 100644
--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
@@ -482,7 +482,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'adds user to the group' do
result = subject
.add_user_to_group_command
- .call(user: origin_user_id)
+ .call(storage:, user: origin_user_id)
expect(result).to be_success
expect(result.message).to eq("User has been added successfully")
end
@@ -526,7 +526,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'removes user from the group' do
result = subject
.remove_user_from_group_command
- .call(user: origin_user_id)
+ .call(storage:, user: origin_user_id)
expect(result).to be_success
expect(result.message).to eq("User has been removed from group")
end
@@ -586,7 +586,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'creates a folder and responds with a success' do
result = subject
.create_folder_command
- .call(folder_path:)
+ .call(storage:, folder_path:)
expect(result).to be_success
expect(result.message).to eq("Folder was successfully created.")
end
@@ -613,7 +613,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'does not create a folder and responds with a success' do
result = subject
.create_folder_command
- .call(folder_path:)
+ .call(storage:, folder_path:)
expect(result).to be_success
expect(result.message).to eq("Folder already exists.")
end
@@ -640,7 +640,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'does not create a folder and responds with a failure' do
result = subject
.create_folder_command
- .call(folder_path:)
+ .call(storage:, folder_path:)
expect(result).to be_failure
expect(result.result).to eq(:conflict)
expect(result.errors.log_message).to eq('Parent node does not exist')
@@ -746,7 +746,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'returns success when permissions can be set' do
result = subject
.set_permissions_command
- .call(path:, permissions:)
+ .call(storage:, path:, permissions:)
expect(result).to be_success
end
end
@@ -774,7 +774,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'returns failure' do
result = subject
.set_permissions_command
- .call(path:, permissions:)
+ .call(storage:, path:, permissions:)
expect(result).to be_failure
end
end
@@ -802,7 +802,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'returns failure' do
result = subject
.set_permissions_command
- .call(path:, permissions:)
+ .call(storage:, path:, permissions:)
expect(result).to be_failure
end
end
@@ -813,7 +813,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
expect do
subject
.set_permissions_command
- .call(path: nil, permissions:)
+ .call(storage:, path: nil, permissions:)
end.to raise_error(ArgumentError)
end
@@ -966,7 +966,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'moves the file' do
result = subject
.rename_file_command
- .call(source: 'OpenProject/asd', target: 'OpenProject/qwe')
+ .call(storage:, source: 'OpenProject/asd', target: 'OpenProject/qwe')
expect(result).to be_success
end
end
@@ -983,7 +983,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
it 'deletes the folder' do
result = subject
.delete_folder_command
- .call(location: 'OpenProject/Folder 1')
+ .call(storage:, location: 'OpenProject/Folder 1')
expect(result).to be_success
end
end