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 almost all mentions of StorageRequests

Marcello Rochaca744bfd6f47
diff --git a/modules/storages/app/common/storages/errors.rb b/modules/storages/app/common/storages/errors.rb
new file mode 100644
index 00000000000..f98e05e725e
--- /dev/null
+++ b/modules/storages/app/common/storages/errors.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Storages
+ module Errors
+ class OperationNotSupported < StandardError; end
+ end
+end
diff --git a/modules/storages/app/common/storages/peripherals/registry.rb b/modules/storages/app/common/storages/peripherals/registry.rb
index d981961b139..32f0713ce1e 100644
--- a/modules/storages/app/common/storages/peripherals/registry.rb
+++ b/modules/storages/app/common/storages/peripherals/registry.rb
@@ -1,7 +1,48 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
module Storages
module Peripherals
class Registry
extend Dry::Container::Mixin
+
+ class Resolver < Dry::Container::Resolver
+ def call(container, key)
+ super
+ rescue Dry::Container::KeyError
+ _, storage, operation = key.split('.')
+ raise ::Storages::Errors::OperationNotSupported, "Operation #{operation} not support by provider: #{storage}"
+ end
+ end
+
+ config.resolver = Resolver.new
end
Registry.import StorageInteraction::Nextcloud::Queries
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 12ac996d1d1..4cb4ebf8ba3 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb
@@ -34,27 +34,27 @@ module Storages
module Nextcloud
Queries = Dry::Container::Namespace.new('queries') do
namespace('nextcloud') do
- register(:download_link_query, DownloadLinkQuery)
- register(:file_ids_query, FileIdsQuery)
- register(:files_info_query, FilesInfoQuery)
- register(:files_query, FilesQuery)
+ register(:download_link, DownloadLinkQuery)
+ register(:file_ids, FileIdsQuery)
+ register(:files_info, FilesInfoQuery)
+ register(:files, FilesQuery)
register(:folder_files_file_ids_deep_query, FolderFilesFileIdsDeepQuery)
- register(:propfind_query, Internal::PropfindQuery)
- register(:group_users_query, GroupUsersQuery)
- register(:upload_link_query, UploadLinkQuery)
+ register(:propfind, Internal::PropfindQuery)
+ register(:group_users, GroupUsersQuery)
+ register(:upload_link, 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)
+ register(:add_user_to_group, AddUserToGroupCommand)
+ register(:copy_template_folder, CopyTemplateFolderCommand)
+ register(:create_folder, CreateFolderCommand)
+ register(:delete_entity, Internal::DeleteEntityCommand)
+ register(:delete_folder, DeleteFolderCommand)
+ register(:remove_user_from_group, RemoveUserFromGroupCommand)
+ register(:rename_file, RenameFileCommand)
+ register(:set_permissions, SetPermissionsCommand)
end
end
end
diff --git a/modules/storages/app/services/storages/file_link_sync_service.rb b/modules/storages/app/services/storages/file_link_sync_service.rb
index 89f38bc67b1..7758ba25cf3 100644
--- a/modules/storages/app/services/storages/file_link_sync_service.rb
+++ b/modules/storages/app/services/storages/file_link_sync_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
@@ -50,12 +52,11 @@ class Storages::FileLinkSyncService
private
def sync_nextcloud(storage_id, file_links)
- ::Storages::Peripherals::StorageRequests
- .call(
- storage: ::Storages::Storage.find(storage_id),
- operation: :files_info_query,
- user: @user, file_ids: file_links.map(&:origin_id)
- ).map { |file_infos| to_hash(file_infos) }
+ storage = ::Storages::Storage.find(storage_id)
+ ::Storages::Peripherals::Registry
+ .resolve("queries.#{storage.short_provider_type}.files_info")
+ .call(storage:, user: @user, file_ids: file_links.map(&:origin_id))
+ .map { |file_infos| to_hash(file_infos) }
.match(
on_success: set_file_link_permissions(file_links),
on_failure: ->(_) {
diff --git a/modules/storages/app/services/storages/group_folder_properties_sync_service.rb b/modules/storages/app/services/storages/group_folder_properties_sync_service.rb
index 877b187da7e..9121bca2638 100644
--- a/modules/storages/app/services/storages/group_folder_properties_sync_service.rb
+++ b/modules/storages/app/services/storages/group_folder_properties_sync_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
@@ -91,8 +93,8 @@ class Storages::GroupFolderPropertiesSyncService
groups: { @group.to_sym => PERMISSIONS_MAP[:read_files] }
}
}
- Storages::Peripherals::StorageRequests
- .call(storage: @storage, operation: :set_permissions_command, **command_params)
+ Storages::Peripherals::Registry.resolve("commands.#{@storage.short_provider_type}.set_permissions")
+ .call(storage: @storage, **command_params)
.on_failure(&failure_handler('set_permissions_command', command_params))
end
@@ -120,20 +122,21 @@ class Storages::GroupFolderPropertiesSyncService
def folders_properties
@folders_properties ||=
- Storages::Peripherals::StorageRequests
- .call(storage: @storage, operation: :file_ids_query, path: @group_folder)
+ Storages::Peripherals::Registry.resolve("queries.#{@storage.short_provider_type}.file_ids")
+ .call(storage: @storage, path: @group_folder)
.on_failure(&failure_handler('file_ids_query', { path: @group_folder }))
.result
end
def rename_folder(source:, target:)
- Storages::Peripherals::StorageRequests
- .call(storage: @storage, operation: :rename_file_command, source:, target:)
+ Storages::Peripherals::Registry.resolve("commands.#{@storage.short_provider_type}.rename_file")
+ .call(storage: @storage, source:, target:)
.on_failure(&failure_handler('rename_file_command', { source:, target: }))
end
def create_folder(path:, project_storage:)
- Storages::Peripherals::StorageRequests.call(storage: @storage, operation: :create_folder_command, folder_path: path)
+ Storages::Peripherals::Registry.resolve("commands.#{@storage.short_provider_type}.create_folder")
+ .call(storage: @storage, folder_path: path)
.match(
on_success: ->(_) { ServiceResult.success(result: [project_storage, path]) },
on_failure: failure_handler('create_folder_command', { folder_path: path })
@@ -148,8 +151,8 @@ class Storages::GroupFolderPropertiesSyncService
def obtain_file_id
->((project_storage, path)) do
- Storages::Peripherals::StorageRequests
- .call(storage: @storage, operation: :file_ids_query, path:)
+ Storages::Peripherals::Registry.resolve("queries.#{@storage.short_provider_type}.file_ids")
+ .call(storage: @storage, path:)
.match(
on_success: ->(file_ids) { ServiceResult.success(result: [project_storage, file_ids.dig(path, 'fileid')]) },
on_failure: failure_handler('file_id_query', { path: })
@@ -178,16 +181,16 @@ class Storages::GroupFolderPropertiesSyncService
path:,
permissions: project_folder_permissions(project:)
}
- Storages::Peripherals::StorageRequests
- .call(storage: @storage, operation: :set_permissions_command, **command_params)
+ Storages::Peripherals::Registry.resolve("commands.#{@storage.short_provider_type}.set_permissions")
+ .call(storage: @storage, **command_params)
.on_failure(&failure_handler('set_permissions_command', command_params))
end
def group_users
@group_users ||= begin
query_params = { group: @group }
- Storages::Peripherals::StorageRequests
- .call(storage: @storage, operation: :group_users_query, **query_params)
+ Storages::Peripherals::Registry.resolve("queries.#{@storage.short_provider_type}.group_users")
+ .call(storage: @storage, **query_params)
.on_failure(&failure_handler('group_users_query', query_params))
.result
end
@@ -229,8 +232,8 @@ class Storages::GroupFolderPropertiesSyncService
@nextcloud_usernames_used_in_openproject.each do |nextcloud_username|
if group_users.exclude?(nextcloud_username)
query_params = { user: nextcloud_username }
- Storages::Peripherals::StorageRequests
- .call(storage: @storage, operation: :add_user_to_group_command, **query_params)
+ Storages::Peripherals::Registry.resolve("commands.#{@storage.short_provider_type}.add_user_to_group")
+ .call(storage: @storage, **query_params)
.on_failure(&failure_handler('add_user_to_group_command', query_params))
end
end
@@ -243,8 +246,8 @@ class Storages::GroupFolderPropertiesSyncService
end
def remove_user_from_group(user)
- Storages::Peripherals::StorageRequests
- .call(storage: @storage, operation: :remove_user_from_group_command, user:)
+ Storages::Peripherals::Registry.resolve("commands.#{@storage.short_provider_type}.remove_user_from_group")
+ .call(storage: @storage, user:)
.on_failure do |service_result|
::OpenProject.logger.warn(
"Nextcloud user #{user} has not been removed from Nextcloud group #{@group}: '#{service_result.errors.log_message}'"
@@ -270,8 +273,8 @@ class Storages::GroupFolderPropertiesSyncService
groups: { "#{@group}": NO_PERMISSIONS }
}
}
- Storages::Peripherals::StorageRequests
- .call(storage: @storage, operation: :set_permissions_command, **command_params)
+ Storages::Peripherals::Registry.resolve("commands.#{@storage.short_provider_type}.set_permissions")
+ .call(storage: @storage, **command_params)
.on_failure(&failure_handler('set_permissions_command', command_params))
end
diff --git a/modules/storages/app/services/storages/project_storages/delete_service.rb b/modules/storages/app/services/storages/project_storages/delete_service.rb
index fbf8b74b1c5..212d84e9057 100644
--- a/modules/storages/app/services/storages/project_storages/delete_service.rb
+++ b/modules/storages/app/services/storages/project_storages/delete_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
@@ -57,8 +59,8 @@ module Storages::ProjectStorages
private
def delete_project_folder
- Storages::Peripherals::StorageRequests
- .call(storage: model.storage, operation: :delete_folder_command, location: model.project_folder_path)
+ Storages::Peripherals::Registry.resolve("commands.#{model.storage.short_provider_type}.delete_folder")
+ .call(storage: model.storage, location: model.project_folder_path)
end
# Delete FileLinks with the same Storage as the ProjectStorage.
diff --git a/modules/storages/lib/api/v3/file_links/file_links_download_api.rb b/modules/storages/lib/api/v3/file_links/file_links_download_api.rb
index d2760fb561c..d8e014cefb1 100644
--- a/modules/storages/lib/api/v3/file_links/file_links_download_api.rb
+++ b/modules/storages/lib/api/v3/file_links/file_links_download_api.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
@@ -32,12 +34,10 @@ class API::V3::FileLinks::FileLinksDownloadAPI < API::OpenProjectAPI
resources :download do
get do
- Storages::Peripherals::StorageRequests
- .call(
- storage: @file_link.storage,
- operation: :download_link_query,
- user: User.current, file_link: @file_link
- ).match(
+ Storages::Peripherals::Registry
+ .resolve("queries.#{@file_link.storage.short_provider_type}.download_link")
+ .call(storage: @file_link.storage, user: User.current, file_link: @file_link)
+ .match(
on_success: ->(url) do
redirect(url, body: "The requested resource can be downloaded from #{url}")
status(303)
diff --git a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
index eeb2e34cded..ac7990aafbd 100644
--- a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
+++ b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
@@ -33,11 +35,11 @@ module API::V3::StorageFiles
resources :files do
get do
- Storages::Peripherals::StorageRequests
- .new(storage: @storage)
- .files_query
- .call(user: current_user, folder: params[:parent])
- .match(
+ Storages::Peripherals::Registry.resolve("queries.#{@storage.short_provider_type}.files")
+ .call(
+ storage: @storage,
+ user: current_user, folder: params[:parent]
+ ).match(
on_success: ->(files) { API::V3::StorageFiles::StorageFilesRepresenter.new(files, @storage, current_user:) },
on_failure: ->(error) { raise_error(error) }
)
@@ -45,12 +47,11 @@ module API::V3::StorageFiles
route_param :file_id, type: String, desc: 'Storage file id' do
get do
- service_result = Storages::Peripherals::StorageRequests
- .call(
- storage: @storage,
- operation: :files_info_query,
- user: current_user, file_ids: [params[:file_id]]
- ).map(&:first)
+ service_result = Storages::Peripherals::Registry.resolve("queries.#{@storage.short_provider_type}.files_info")
+ .call(
+ storage: @storage,
+ user: current_user, file_ids: [params[:file_id]]
+ ).map(&:first)
if service_result.success? && service_result.result.status_code == 403
storage_error = Storages::StorageError.new(code: :forbidden, log_message: 'no access to file', data: nil)
@@ -79,11 +80,11 @@ module API::V3::StorageFiles
end
validate.call(request_body) >> ->(data) do
- Storages::Peripherals::StorageRequests
- .new(storage: @storage)
- .upload_link_query
- .call(user: current_user, data:)
- .match(
+ Storages::Peripherals::Registry.resolve("queries.#{@storage.short_provider_type}.upload_link")
+ .call(
+ storage: @storage,
+ user: current_user, data:
+ ).match(
on_success: ->(link) { API::V3::StorageFiles::StorageUploadLinkRepresenter.new(link, current_user:) },
on_failure: ->(error) { raise_error(error) }
)
diff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
index 65844334f8b..65494239fb9 100644
--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
@@ -36,7 +38,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
let(:origin_user_id) { 'admin' }
let(:storage) { build(:nextcloud_storage, :as_automatically_managed, host: url, password: 'OpenProjectSecurePassword') }
- subject { described_class }
+ subject(:registry) { Storages::Peripherals::Registry }
context 'when requests depend on OAuth token' do
let(:token) do
@@ -84,7 +86,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with Nextcloud storage type selected' do
it 'must return a download link URL' do
- result = subject.call(operation: :download_link_query, storage:, user:, file_link:)
+ result = registry.resolve("queries.nextcloud.download_link").call(storage:, user:, file_link:)
expect(result).to be_success
expect(result.result).to eql(uri)
end
@@ -93,7 +95,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
let(:url) { 'https://example.com/html' }
it 'must return a download link URL' do
- result = subject.call(operation: :download_link_query, storage:, user:, file_link:)
+ result = registry.resolve('queries.nextcloud.download_link').call(storage:, user:, file_link:)
expect(result).to be_success
expect(result.result).to eql(uri)
end
@@ -102,11 +104,11 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with not supported storage type selected' do
before do
- allow(storage).to receive(:provider_type).and_return('not_supported_storage_type'.freeze)
+ allow(storage).to receive(:provider_type).and_return('not_supported_storage_type')
end
it 'must raise ArgumentError' do
- expect { subject.call(storage:, operation: :download_link_query) }.to raise_error(ArgumentError)
+ expect { registry.resolve('queries.nextcloud.download_link').call(storage:) }.to raise_error(ArgumentError)
end
end
@@ -118,7 +120,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'must return ":not_authorized" ServiceResult' do
- result = subject.call(operation: :download_link_query, storage:, user:, file_link:)
+ result = registry.resolve('queries.nextcloud.download_link').call(storage:, user:, file_link:)
expect(result).to be_failure
expect(result.errors.code).to be(:not_authorized)
end
@@ -130,7 +132,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'must return :not_authorized ServiceResult' do
- result = subject.call(operation: :download_link_query, user:, file_link:, storage:)
+ result = registry.resolve('queries.nextcloud.download_link').call(user:, file_link:, storage:)
expect(result).to be_failure
expect(result.errors.code).to be(:not_authorized)
end
@@ -143,7 +145,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it "must return :#{symbol} ServiceResult" do
- result = subject.call(operation: :download_link_query, user:, file_link:, storage:)
+ result = registry.resolve('queries.nextcloud.download_link').call(user:, file_link:, storage:)
expect(result).to be_failure
expect(result.errors.code).to eq(symbol)
end
@@ -177,7 +179,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with Nextcloud storage type selected' do
it 'returns a list files directories with names and permissions' do
- result = subject.call(storage:, operation: :files_query, folder: nil, user:)
+ result = registry.resolve('queries.nextcloud.files').call(storage:, folder: nil, user:)
expect(result).to be_success
query_result = result.result
@@ -203,7 +205,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
let(:xml) { create(:webdav_data, origin_user_id:) }
it do
- result = subject.call(operation: :files_query, folder: parent, user:, storage:)
+ result = registry.resolve('queries.nextcloud.files').call(folder: parent, user:, storage:)
expect(result.result.files[0].location).to eq('/Folder1')
assert_requested(:propfind, request_url)
@@ -214,7 +216,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
let(:parent) { '/Photos/Birds' }
it do
- result = subject.call(operation: :files_query, folder: parent, user:, storage:)
+ result = registry.resolve('queries.nextcloud.files').call(folder: parent, user:, storage:)
expect(result.result.files[2].location).to eq('/Photos/Birds/README.md')
expect(result.result.ancestors[0].location).to eq('/')
expect(result.result.ancestors[1].location).to eq('/Photos')
@@ -227,7 +229,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
let(:root_path) { '/storage' }
it do
- result = subject.call(operation: :files_query, folder: nil, user:, storage:)
+ result = registry.resolve('queries.nextcloud.files').call(folder: nil, user:, storage:)
expect(result.result.files[2].location).to eq('/README.md')
assert_requested(:propfind, request_url)
end
@@ -238,7 +240,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
let(:parent) { '/Photos/Birds' }
it do
- result = subject.call(operation: :files_query, folder: parent, user:, storage:)
+ result = registry.resolve('queries.nextcloud.files').call(folder: parent, user:, storage:)
expect(result.result.files[2].location).to eq('/Photos/Birds/README.md')
assert_requested(:propfind, request_url)
@@ -248,11 +250,11 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with not supported storage type selected' do
before do
- allow(storage).to receive(:provider_type).and_return('not_supported_storage_type'.freeze)
+ allow(storage).to receive(:provider_type).and_return('not_supported_storage_type')
end
it 'must raise ArgumentError' do
- expect { subject.call(storage:, operation: :files_query) }.to raise_error(ArgumentError)
+ expect { registry.resolve('queries.nextcloud.files').call(storage:) }.to raise_error(ArgumentError)
end
end
@@ -264,7 +266,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'must return ":not_authorized" ServiceResult' do
- result = subject.call(operation: :files_query, folder: parent, user:, storage:)
+ result = registry.resolve('queries.nextcloud.files').call(folder: parent, user:, storage:)
expect(result).to be_failure
expect(result.errors.code).to be(:not_authorized)
end
@@ -278,7 +280,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it "must return :#{symbol} ServiceResult" do
- result = subject.call(operation: :files_query, folder: parent, user:, storage:)
+ result = registry.resolve('queries.nextcloud.files').call(folder: parent, user:, storage:)
expect(result).to be_failure
expect(result.errors.code).to be(symbol)
end
@@ -308,7 +310,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with Nextcloud storage type selected' do
it 'must return an upload link URL' do
- link = subject.call(operation: :upload_link_query, storage:, user:, data: query_payload)
+ link = registry.resolve('queries.nextcloud.upload_link').call(storage:, user:, data: query_payload)
.result
expect(link.destination.path).to eql("/index.php/apps/integration_openproject/direct-upload/#{upload_token}")
expect(link.destination.host).to eql(URI(url).host)
@@ -321,11 +323,11 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with not supported storage type selected' do
before do
- allow(storage).to receive(:provider_type).and_return('not_supported_storage_type'.freeze)
+ allow(storage).to receive(:provider_type).and_return('not_supported_storage_type')
end
it 'must raise ArgumentError' do
- expect { subject.call(operation: :upload_link_query, storage:, user:) }.to raise_error(ArgumentError)
+ expect { registry.resolve('queries.nextcloud.upload_link').call(storage:, user:) }.to raise_error(ArgumentError)
end
end
@@ -337,7 +339,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'must return ":not_authorized" ServiceResult' do
- result = subject.call(operation: :upload_link_query, storage:, user:, data: query_payload)
+ result = registry.resolve('queries.nextcloud.upload_link').call(storage:, user:, data: query_payload)
expect(result).to be_failure
expect(result.errors.code).to be(:not_authorized)
end
@@ -350,7 +352,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it "must return :#{symbol} ServiceResult" do
- result = subject.call(operation: :upload_link_query, storage:, user:, data: query_payload)
+ result = registry.resolve('queries.nextcloud.upload_link').call(storage:, user:, data: query_payload)
expect(result).to be_failure
expect(result.errors.code).to be(symbol)
end
@@ -408,7 +410,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'responds with a strings array with group users' do
- result = subject.call(operation: :group_users_query, storage:)
+ result = registry.resolve('queries.nextcloud.group_users').call(storage:)
expect(result).to be_success
expect(result.result).to eq(["admin", "OpenProject", "reader", "TestUser", "TestUser34"])
end
@@ -450,7 +452,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'adds user to the group' do
- result = subject.call(operation: :add_user_to_group_command, storage:, user: origin_user_id)
+ result = registry.resolve('commands.nextcloud.add_user_to_group').call(storage:, user: origin_user_id)
expect(result).to be_success
expect(result.message).to eq("User has been added successfully")
end
@@ -492,7 +494,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'removes user from the group' do
- result = subject.call(operation: :remove_user_from_group_command, storage:, user: origin_user_id)
+ result = registry.resolve('commands.nextcloud.remove_user_from_group').call(storage:, user: origin_user_id)
expect(result).to be_success
expect(result.message).to eq("User has been removed from group")
end
@@ -550,7 +552,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'creates a folder and responds with a success' do
- result = subject.call(operation: :create_folder_command, storage:, folder_path:)
+ result = registry.resolve('commands.nextcloud.create_folder').call(storage:, folder_path:)
expect(result).to be_success
expect(result.message).to eq("Folder was successfully created.")
end
@@ -575,7 +577,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'does not create a folder and responds with a success' do
- result = subject.call(operation: :create_folder_command, storage:, folder_path:)
+ result = registry.resolve('commands.nextcloud.create_folder').call(storage:, folder_path:)
expect(result).to be_success
expect(result.message).to eq("Folder already exists.")
end
@@ -600,7 +602,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'does not create a folder and responds with a failure' do
- result = subject.call(operation: :create_folder_command, storage:, folder_path:)
+ result = registry.resolve('commands.nextcloud.create_folder').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')
@@ -704,7 +706,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'returns success when permissions can be set' do
- result = subject.call(operation: :set_permissions_command, storage:, path:, permissions:)
+ result = registry.resolve('commands.nextcloud.set_permissions').call(storage:, path:, permissions:)
expect(result).to be_success
end
end
@@ -730,7 +732,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'returns failure' do
- result = subject.call(operation: :set_permissions_command, storage:, path:, permissions:)
+ result = registry.resolve('commands.nextcloud.set_permissions').call(storage:, path:, permissions:)
expect(result).to be_failure
end
end
@@ -756,7 +758,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
it 'returns failure' do
- result = subject.call(operation: :set_permissions_command, storage:, path:, permissions:)
+ result = registry.resolve('commands.nextcloud.set_permissions').call(storage:, path:, permissions:)
expect(result).to be_failure
end
end
@@ -765,13 +767,13 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
context 'when forbidden values are given as folder' do
it 'raises an ArgumentError on nil' do
expect do
- subject.call(operation: :set_permissions_command, storage:, path: nil, permissions:)
+ registry.resolve('commands.nextcloud.set_permissions').call(storage:, path: nil, permissions:)
end.to raise_error(ArgumentError)
end
it 'raises an ArgumentError on empty string' do
expect do
- subject.call(operation: :set_permissions_command, path: '', permissions:)
+ registry.resolve('commands.nextcloud.set_permissions').call(path: '', permissions:)
end.to raise_error(ArgumentError)
end
end
@@ -878,7 +880,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
shared_examples 'a file_ids_query response' do
it 'responds with a list of paths and attributes for each of them' do
- result = subject.call(operation: :file_ids_query, storage:, path: 'OpenProject')
+ result = registry.resolve('queries.nextcloud.file_ids').call(storage:, path: 'OpenProject')
.result
expect(result).to eq({ "OpenProject/" => { "fileid" => "349" },
"OpenProject/Project #2/" => { "fileid" => "381" },
@@ -912,7 +914,8 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with Nextcloud storage type selected' do
it 'moves the file' do
- result = subject.call(operation: :rename_file_command, storage:, source: 'OpenProject/asd', target: 'OpenProject/qwe')
+ result = registry.resolve('commands.nextcloud.rename_file').call(storage:, source: 'OpenProject/asd',
+ target: 'OpenProject/qwe')
expect(result).to be_success
end
end
@@ -927,7 +930,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
describe 'with Nextcloud storage type selected' do
it 'deletes the folder' do
- result = subject.call(operation: :delete_folder_command, storage:, location: 'OpenProject/Folder 1')
+ result = registry.resolve('commands.nextcloud.delete_folder').call(storage:, location: 'OpenProject/Folder 1')
expect(result).to be_success
end
end
diff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb
index 7857f548a7a..a0ec5bf7efd 100644
--- a/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb
+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
@@ -74,13 +76,8 @@ RSpec.describe 'API v3 file links resource' do
allow(OAuthClients::ConnectionManager)
.to receive(:new).and_return(connection_manager)
allow(connection_manager)
- .to receive(:get_access_token)
- .and_return(ServiceResult.success(result: oauth_client_token))
- allow(connection_manager)
- .to receive(:authorization_state).and_return(:connected)
-
- allow(connection_manager)
- .to receive(:get_authorization_uri).and_return('https://example.com/authorize')
+ .to receive_messages(get_access_token: ServiceResult.success(result: oauth_client_token), authorization_state: :connected,
+ get_authorization_uri: 'https://example.com/authorize')
# Mock FileLinkSyncService as if Nextcloud would respond positively
allow(Storages::FileLinkSyncService)
@@ -559,7 +556,7 @@ RSpec.describe 'API v3 file links resource' do
describe 'with successful response' do
before do
Storages::Peripherals::Registry.stub(
- 'queries.nextcloud.download_link_query',
+ 'queries.nextcloud.download_link',
->(_) { ServiceResult.success(result: url) }
)
end
@@ -575,7 +572,7 @@ RSpec.describe 'API v3 file links resource' do
describe 'with query failed' do
before do
Storages::Peripherals::Registry.stub(
- 'queries.nextcloud.download_link_query',
+ 'queries.nextcloud.download_link',
->(_) { ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error)) }
)
diff --git a/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb
index a1d46287d24..75eee505a14 100644
--- a/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb
+++ b/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
@@ -108,7 +110,7 @@ RSpec.describe 'API v3 storage files', content_type: :json, webmock: true do
context 'with successful response' do
before do
Storages::Peripherals::Registry.stub(
- 'queries.nextcloud.files_query',
+ 'queries.nextcloud.files',
->(_) { ServiceResult.success(result: response) }
)
end
@@ -131,7 +133,7 @@ RSpec.describe 'API v3 storage files', content_type: :json, webmock: true do
context 'with query failed' do
before do
Storages::Peripherals::Registry.stub(
- 'queries.nextcloud.files_query',
+ 'queries.nextcloud.files',
->(_) { ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error)) }
)
end
@@ -288,7 +290,7 @@ RSpec.describe 'API v3 storage files', content_type: :json, webmock: true do
describe 'with successful response' do
before do
Storages::Peripherals::Registry.stub(
- 'queries.nextcloud.upload_link_query',
+ 'queries.nextcloud.upload_link',
->(_) { ServiceResult.success(result: upload_link) }
)
end
@@ -309,7 +311,7 @@ RSpec.describe 'API v3 storage files', content_type: :json, webmock: true do
context 'with query failed' do
before do
Storages::Peripherals::Registry.stub(
- 'queries.nextcloud.upload_link_query',
+ 'queries.nextcloud.upload_link',
->(_) { ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error)) }
)
end
diff --git a/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb b/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb
index 60f3b7caf8c..6cd47ec1b3e 100644
--- a/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb
+++ b/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb
@@ -53,7 +53,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do
before do
Storages::Peripherals::Registry
- .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })
+ .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })
end
it 'updates all origin_* fields' do
@@ -76,7 +76,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do
before do
Storages::Peripherals::Registry
- .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })
+ .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })
end
it 'returns a FileLink with #origin_permission :not_allowed' do
@@ -96,7 +96,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do
before do
Storages::Peripherals::Registry
- .stub('queries.nextcloud.files_info_query',
+ .stub('queries.nextcloud.files_info',
->(_) { ServiceResult.success(result: [file_info_one, file_info_two]) })
end
@@ -116,7 +116,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do
before do
Storages::Peripherals::Registry
- .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })
+ .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })
end
it 'deletes the file link' do
@@ -132,7 +132,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do
before do
Storages::Peripherals::Registry
- .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })
+ .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })
end
it 'returns the file link with a permission set to :error' do
@@ -146,7 +146,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do
context 'with files_info_query failing' do
before do
Storages::Peripherals::Registry
- .stub('queries.nextcloud.files_info_query',
+ .stub('queries.nextcloud.files_info',
->(_) { ServiceResult.failure(result: :error, errors: Storages::StorageError.new(code: :error)) })
end
@@ -162,7 +162,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do
before do
Storages::Peripherals::Registry
- .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })
+ .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })
end
it 'returns an empty list of FileLinks' do