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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
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.rbnew file mode 100644index 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+enddiff --git a/modules/storages/app/common/storages/peripherals/registry.rb b/modules/storages/app/common/storages/peripherals/registry.rbindex 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 Storagesmodule Peripheralsclass Registryextend 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.newendRegistry.import StorageInteraction::Nextcloud::Queriesdiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rbindex 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 Storagesmodule NextcloudQueries = Dry::Container::Namespace.new('queries') donamespace('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)endendCommands = Dry::Container::Namespace.new('commands') donamespace('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)endendenddiff --git a/modules/storages/app/services/storages/file_link_sync_service.rb b/modules/storages/app/services/storages/file_link_sync_service.rbindex 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::FileLinkSyncServiceprivatedef 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.rbindex 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::GroupFolderPropertiesSyncServicegroups: { @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::GroupFolderPropertiesSyncServicedef 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 })).resultenddef 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: }))enddef 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::GroupFolderPropertiesSyncServicedef 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::GroupFolderPropertiesSyncServicepath:,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))enddef group_users@group_users ||= beginquery_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)).resultend@@ -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))endend@@ -243,8 +246,8 @@ class Storages::GroupFolderPropertiesSyncServiceenddef 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::GroupFolderPropertiesSyncServicegroups: { "#{@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))enddiff --git a/modules/storages/app/services/storages/project_storages/delete_service.rb b/modules/storages/app/services/storages/project_storages/delete_service.rbindex 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::ProjectStoragesprivatedef 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.rbindex 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::OpenProjectAPIresources :download doget 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) doredirect(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.rbindex 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::StorageFilesresources :files doget 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::StorageFilesroute_param :file_id, type: String, desc: 'Storage file id' doget 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 == 403storage_error = Storages::StorageError.new(code: :forbidden, log_message: 'no access to file', data: nil)@@ -79,11 +80,11 @@ module API::V3::StorageFilesendvalidate.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.rbindex 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 dolet(: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' dolet(:token) do@@ -84,7 +86,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit '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_successexpect(result.result).to eql(uri)end@@ -93,7 +95,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dolet(: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_successexpect(result.result).to eql(uri)end@@ -102,11 +104,11 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with not supported storage type selected' dobefore 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')endit '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)endend@@ -118,7 +120,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_failureexpect(result.errors.code).to be(:not_authorized)end@@ -130,7 +132,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_failureexpect(result.errors.code).to be(:not_authorized)end@@ -143,7 +145,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit "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_failureexpect(result.errors.code).to eq(symbol)end@@ -177,7 +179,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit '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_successquery_result = result.result@@ -203,7 +205,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dolet(: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 dolet(: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 dolet(: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 dolet(: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 dodescribe 'with not supported storage type selected' dobefore 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')endit '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)endend@@ -264,7 +266,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_failureexpect(result.errors.code).to be(:not_authorized)end@@ -278,7 +280,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit "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_failureexpect(result.errors.code).to be(symbol)end@@ -308,7 +310,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit '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).resultexpect(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 dodescribe 'with not supported storage type selected' dobefore 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')endit '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)endend@@ -337,7 +339,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_failureexpect(result.errors.code).to be(:not_authorized)end@@ -350,7 +352,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit "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_failureexpect(result.errors.code).to be(symbol)end@@ -408,7 +410,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_successexpect(result.result).to eq(["admin", "OpenProject", "reader", "TestUser", "TestUser34"])end@@ -450,7 +452,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_successexpect(result.message).to eq("User has been added successfully")end@@ -492,7 +494,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_successexpect(result.message).to eq("User has been removed from group")end@@ -550,7 +552,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_successexpect(result.message).to eq("Folder was successfully created.")end@@ -575,7 +577,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_successexpect(result.message).to eq("Folder already exists.")end@@ -600,7 +602,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_failureexpect(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 doendit '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_successendend@@ -730,7 +732,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_failureendend@@ -756,7 +758,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit '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_failureendend@@ -765,13 +767,13 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true docontext 'when forbidden values are given as folder' doit 'raises an ArgumentError on nil' doexpect 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)endit 'raises an ArgumentError on empty string' doexpect do- subject.call(operation: :set_permissions_command, path: '', permissions:)+ registry.resolve('commands.nextcloud.set_permissions').call(path: '', permissions:)end.to raise_error(ArgumentError)endend@@ -878,7 +880,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doshared_examples 'a file_ids_query response' doit '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').resultexpect(result).to eq({ "OpenProject/" => { "fileid" => "349" },"OpenProject/Project #2/" => { "fileid" => "381" },@@ -912,7 +914,8 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit '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_successendend@@ -927,7 +930,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit '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_successendenddiff --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.rbindex 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' doallow(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 positivelyallow(Storages::FileLinkSyncService)@@ -559,7 +556,7 @@ RSpec.describe 'API v3 file links resource' dodescribe 'with successful response' dobefore doStorages::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' dodescribe 'with query failed' dobefore doStorages::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.rbindex 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 docontext 'with successful response' dobefore doStorages::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 docontext 'with query failed' dobefore doStorages::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 dodescribe 'with successful response' dobefore doStorages::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 docontext 'with query failed' dobefore doStorages::Peripherals::Registry.stub(- 'queries.nextcloud.upload_link_query',+ 'queries.nextcloud.upload_link',->(_) { ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error)) })enddiff --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.rbindex 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 dobefore doStorages::Peripherals::Registry- .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })+ .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })endit 'updates all origin_* fields' do@@ -76,7 +76,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model dobefore doStorages::Peripherals::Registry- .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })+ .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })endit 'returns a FileLink with #origin_permission :not_allowed' do@@ -96,7 +96,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model dobefore doStorages::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 dobefore doStorages::Peripherals::Registry- .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })+ .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })endit 'deletes the file link' do@@ -132,7 +132,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model dobefore doStorages::Peripherals::Registry- .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })+ .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })endit 'returns the file link with a permission set to :error' do@@ -146,7 +146,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model docontext 'with files_info_query failing' dobefore doStorages::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 dobefore doStorages::Peripherals::Registry- .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })+ .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })endit 'returns an empty list of FileLinks' do