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
Makes StorageRequests stateless
Marcello Rocha9d658e8e4f73
diff --git a/modules/storages/app/common/storages/peripherals/storage_requests.rb b/modules/storages/app/common/storages/peripherals/storage_requests.rbindex af0071cc819..89e8e4f52f7 100644--- a/modules/storages/app/common/storages/peripherals/storage_requests.rb+++ b/modules/storages/app/common/storages/peripherals/storage_requests.rb@@ -28,28 +28,10 @@module Storages::Peripheralsclass StorageRequests- def initialize(storage:)- @storage = storage- end-- # def self.call(storage:, operation:, **)- # Registry.resolve("queries.#{storage.short_provider_type}.#{operation}").call(storage:, **)- # end-- private-- def method_missing(name, *args)- 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)- resource_type = name.to_s.split('_').last.pluralize- !!Registry.resolve("#{resource_type}.#{@storage.short_provider_type}.#{name}")- rescue Dry::Container::KeyError- super+ def self.call(storage:, operation:, **)+ resource_type = operation.to_s.ends_with?('query') ? 'queries' : 'commands'+ Registry.resolve("#{resource_type}.#{storage.short_provider_type}.#{operation}").call(storage:, **)endendenddiff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rbindex db212e97d8e..cb9005dd95c 100644--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb@@ -36,7 +36,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.new(storage:) }+ subject { described_class }context 'when requests depend on OAuth token' dolet(:token) do@@ -84,9 +84,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit 'must return a download link URL' do- result = subject- .download_link_query- .call(storage:, user:, file_link:)+ result = subject.call(operation: :download_link_query, storage:, user:, file_link:)expect(result).to be_successexpect(result.result).to be_eql(uri)end@@ -95,9 +93,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dolet(:url) { 'https://example.com/html' }it 'must return a download link URL' do- result = subject- .download_link_query- .call(storage:, user:, file_link:)+ result = subject.call(operation: :download_link_query, storage:, user:, file_link:)expect(result).to be_successexpect(result.result).to be_eql(uri)end@@ -110,7 +106,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'must raise ArgumentError' do- expect { subject.download_link_query }.to raise_error(ArgumentError)+ expect { subject.call(storage:, operation: :download_link_query) }.to raise_error(ArgumentError)endend@@ -122,9 +118,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'must return ":not_authorized" ServiceResult' do- result = subject- .download_link_query- .call(storage:, user:, file_link:)+ result = subject.call(operation: :download_link_query, storage:, user:, file_link:)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)end@@ -136,9 +130,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'must return :not_authorized ServiceResult' do- result = subject- .download_link_query- .call(user:, file_link:, storage:)+ result = subject.call(operation: :download_link_query, user:, file_link:, storage:)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)end@@ -151,9 +143,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit "must return :#{symbol} ServiceResult" do- result = subject- .download_link_query- .call(user:, file_link:, storage:)+ result = subject.call(operation: :download_link_query, user:, file_link:, storage:)expect(result).to be_failureexpect(result.errors.code).to be(symbol)end@@ -187,7 +177,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.files_query.call(folder: nil, user:, storage:)+ result = subject.call(storage:, operation: :files_query, folder: nil, user:)expect(result).to be_successquery_result = result.result@@ -213,9 +203,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dolet(:xml) { create(:webdav_data, origin_user_id:) }it do- result = subject- .files_query- .call(folder: parent, user:, storage:)+ result = subject.call(operation: :files_query, folder: parent, user:, storage:)expect(result.result.files[0].location).to eq('/Folder1')assert_requested(:propfind, request_url)@@ -226,9 +214,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dolet(:parent) { '/Photos/Birds' }it do- result = subject- .files_query- .call(folder: parent, user:, storage:)+ result = subject.call(operation: :files_query, 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')@@ -241,9 +227,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dolet(:root_path) { '/storage' }it do- result = subject- .files_query- .call(folder: nil, user:, storage:)+ result = subject.call(operation: :files_query, folder: nil, user:, storage:)expect(result.result.files[2].location).to eq('/README.md')assert_requested(:propfind, request_url)end@@ -254,9 +238,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dolet(:parent) { '/Photos/Birds' }it do- result = subject- .files_query- .call(folder: parent, user:, storage:)+ result = subject.call(operation: :files_query, folder: parent, user:, storage:)expect(result.result.files[2].location).to eq('/Photos/Birds/README.md')assert_requested(:propfind, request_url)@@ -270,7 +252,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'must raise ArgumentError' do- expect { subject.files_query }.to raise_error(ArgumentError)+ expect { subject.call(storage:, operation: :files_query) }.to raise_error(ArgumentError)endend@@ -282,9 +264,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'must return ":not_authorized" ServiceResult' do- result = subject- .files_query- .call(folder: parent, user:, storage:)+ result = subject.call(operation: :files_query, folder: parent, user:, storage:)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)end@@ -298,9 +278,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit "must return :#{symbol} ServiceResult" do- result = subject- .files_query- .call(folder: parent, user:, storage:)+ result = subject.call(operation: :files_query, folder: parent, user:, storage:)expect(result).to be_failureexpect(result.errors.code).to be(symbol)end@@ -330,9 +308,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit 'must return an upload link URL' do- link = subject- .upload_link_query- .call(storage:, user:, data: query_payload)+ link = subject.call(operation: :upload_link_query, storage:, user:, data: query_payload).resultexpect(link.destination.path).to be_eql("/index.php/apps/integration_openproject/direct-upload/#{upload_token}")expect(link.destination.host).to be_eql(URI(url).host)@@ -349,7 +325,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'must raise ArgumentError' do- expect { subject.upload_link_query.call(storage:, user:, path:) }.to raise_error(ArgumentError)+ expect { subject.call(operation: :upload_link_query, storage:, user:) }.to raise_error(ArgumentError)endend@@ -361,9 +337,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'must return ":not_authorized" ServiceResult' do- result = subject- .upload_link_query- .call(storage:, user:, data: query_payload)+ result = subject.call(operation: :upload_link_query, storage:, user:, data: query_payload)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)end@@ -376,9 +350,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit "must return :#{symbol} ServiceResult" do- result = subject- .upload_link_query- .call(storage:, user:, data: query_payload)+ result = subject.call(operation: :upload_link_query, storage:, user:, data: query_payload)expect(result).to be_failureexpect(result.errors.code).to be(symbol)end@@ -436,9 +408,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'responds with a strings array with group users' do- result = subject- .group_users_query- .call(storage:)+ result = subject.call(operation: :group_users_query, storage:)expect(result).to be_successexpect(result.result).to eq(["admin", "OpenProject", "reader", "TestUser", "TestUser34"])end@@ -480,9 +450,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'adds user to the group' do- result = subject- .add_user_to_group_command- .call(storage:, user: origin_user_id)+ result = subject.call(operation: :add_user_to_group_command, storage:, user: origin_user_id)expect(result).to be_successexpect(result.message).to eq("User has been added successfully")end@@ -524,9 +492,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'removes user from the group' do- result = subject- .remove_user_from_group_command- .call(storage:, user: origin_user_id)+ result = subject.call(operation: :remove_user_from_group_command, storage:, user: origin_user_id)expect(result).to be_successexpect(result.message).to eq("User has been removed from group")end@@ -584,9 +550,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'creates a folder and responds with a success' do- result = subject- .create_folder_command- .call(storage:, folder_path:)+ result = subject.call(operation: :create_folder_command, storage:, folder_path:)expect(result).to be_successexpect(result.message).to eq("Folder was successfully created.")end@@ -611,9 +575,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'does not create a folder and responds with a success' do- result = subject- .create_folder_command- .call(storage:, folder_path:)+ result = subject.call(operation: :create_folder_command, storage:, folder_path:)expect(result).to be_successexpect(result.message).to eq("Folder already exists.")end@@ -638,9 +600,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'does not create a folder and responds with a failure' do- result = subject- .create_folder_command- .call(storage:, folder_path:)+ result = subject.call(operation: :create_folder_command, 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')@@ -744,9 +704,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'returns success when permissions can be set' do- result = subject- .set_permissions_command- .call(storage:, path:, permissions:)+ result = subject.call(operation: :set_permissions_command, storage:, path:, permissions:)expect(result).to be_successendend@@ -772,9 +730,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'returns failure' do- result = subject- .set_permissions_command- .call(storage:, path:, permissions:)+ result = subject.call(operation: :set_permissions_command, storage:, path:, permissions:)expect(result).to be_failureendend@@ -800,9 +756,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doendit 'returns failure' do- result = subject- .set_permissions_command- .call(storage:, path:, permissions:)+ result = subject.call(operation: :set_permissions_command, storage:, path:, permissions:)expect(result).to be_failureendend@@ -811,17 +765,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- .set_permissions_command- .call(storage:, path: nil, permissions:)+ subject.call(operation: :set_permissions_command, storage:, path: nil, permissions:)end.to raise_error(ArgumentError)endit 'raises an ArgumentError on empty string' doexpect do- subject- .set_permissions_command- .call(path: '', permissions:)+ subject.call(operation: :set_permissions_command, path: '', permissions:)end.to raise_error(ArgumentError)endend@@ -928,9 +878,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- .file_ids_query- .call(storage:, path: 'OpenProject')+ result = subject.call(operation: :file_ids_query, storage:, path: 'OpenProject').resultexpect(result).to eq({ "OpenProject/" => { "fileid" => "349" },"OpenProject/Project #2/" => { "fileid" => "381" },@@ -964,9 +912,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit 'moves the file' do- result = subject- .rename_file_command- .call(storage:, source: 'OpenProject/asd', target: 'OpenProject/qwe')+ result = subject.call(operation: :rename_file_command, storage:, source: 'OpenProject/asd', target: 'OpenProject/qwe')expect(result).to be_successendend@@ -981,9 +927,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit 'deletes the folder' do- result = subject- .delete_folder_command- .call(storage:, location: 'OpenProject/Folder 1')+ result = subject.call(operation: :delete_folder_command, storage:, location: 'OpenProject/Folder 1')expect(result).to be_successendend