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
Start spreading the changes
Marcello Rochaae16c39ca83c
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rbindex dd2cbe4454b..12ac996d1d1 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb@@ -36,7 +36,7 @@ module Storagesnamespace('nextcloud') doregister(:download_link_query, DownloadLinkQuery)register(:file_ids_query, FileIdsQuery)- register(:file_info_query, FilesInfoQuery)+ register(:files_info_query, FilesInfoQuery)register(:files_query, FilesQuery)register(:folder_files_file_ids_deep_query, FolderFilesFileIdsDeepQuery)register(:propfind_query, Internal::PropfindQuery)diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rbindex 9fe5ac3ddef..26783fdf6bc 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb@@ -37,6 +37,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud@oauth_client = storage.oauth_clientend+ def self.call(storage:, user:, file_ids: [])+ new(storage).call(user:, file_ids:)+ end+def call(user:, file_ids: [])if file_ids.nil?return Util.error(:error, 'File IDs can not be nil', file_ids)diff --git a/modules/storages/app/services/storages/file_link_sync_service.rb b/modules/storages/app/services/storages/file_link_sync_service.rbindex 8c484fb84d2..89f38bc67b1 100644--- a/modules/storages/app/services/storages/file_link_sync_service.rb+++ b/modules/storages/app/services/storages/file_link_sync_service.rb@@ -51,10 +51,11 @@ class Storages::FileLinkSyncServicedef sync_nextcloud(storage_id, file_links)::Storages::Peripherals::StorageRequests- .new(storage: ::Storages::Storage.find(storage_id))- .files_info_query- .call(user: @user, file_ids: file_links.map(&:origin_id))- .map { |file_infos| to_hash(file_infos) }+ .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) }.match(on_success: set_file_link_permissions(file_links),on_failure: ->(_) {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.rbindex 9d5a28132de..440ad7a4c02 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@@ -29,6 +29,7 @@#++require 'spec_helper'+require 'dry/container/stub'RSpec.describe Storages::FileLinkSyncService, type: :model dolet(:user) { create(:user) }@@ -44,15 +45,10 @@ RSpec.describe Storages::FileLinkSyncService, type: :model dolet(:file_links) { [file_link_one] }- let(:files_info_query) { instance_double(Storages::Peripherals::StorageInteraction::Nextcloud::FilesInfoQuery) }+ subject(:service) { described_class.new(user:).call(file_links) }- subject { described_class.new(user:).call(file_links) }-- before do- storage_requests = instance_double(Storages::Peripherals::StorageRequests)- allow(storage_requests).to receive(:files_info_query).and_return(files_info_query)- allow(Storages::Peripherals::StorageRequests).to receive(:new).and_return(storage_requests)- end+ before { Storages::Peripherals::Registry.enable_stubs! }+ after { Storages::Peripherals::Registry.unstub }describe '#call' docontext 'with one file link' do@@ -60,20 +56,21 @@ RSpec.describe Storages::FileLinkSyncService, type: :model dolet(:file_link_one) { create(:file_link, origin_id: file_info.id, storage: storage_one, container: work_package) }before do- allow(files_info_query).to receive(:call).and_return(ServiceResult.success(result: [file_info]))+ Storages::Peripherals::Registry+ .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })endit 'updates all origin_* fields' do- expect(subject.success).to be_truthy- expect(subject.result.count).to be 1- expect(subject.result.first).to be_a Storages::FileLink-- expect(subject.result.first.origin_id).to eql file_info.id- expect(subject.result.first.origin_created_at).to eql file_info.created_at- expect(subject.result.first.origin_updated_at).to eql file_info.last_modified_at- expect(subject.result.first.origin_mime_type).to eql file_info.mime_type- expect(subject.result.first.origin_name).to eql file_info.name- expect(subject.result.first.origin_created_by_name).to eql file_info.owner_name+ expect(service.success).to be_truthy+ expect(service.result.count).to be 1+ expect(service.result.first).to be_a Storages::FileLink++ expect(service.result.first.origin_id).to eql file_info.id+ expect(service.result.first.origin_created_at).to eql file_info.created_at+ expect(service.result.first.origin_updated_at).to eql file_info.last_modified_at+ expect(service.result.first.origin_mime_type).to eql file_info.mime_type+ expect(service.result.first.origin_name).to eql file_info.name+ expect(service.result.first.origin_created_by_name).to eql file_info.owner_nameendend@@ -82,12 +79,13 @@ RSpec.describe Storages::FileLinkSyncService, type: :model dolet(:file_link_one) { create(:file_link, origin_id: file_info.id, storage: storage_one, container: work_package) }before do- allow(files_info_query).to receive(:call).and_return(ServiceResult.success(result: [file_info]))+ Storages::Peripherals::Registry+ .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })endit 'returns a FileLink with #origin_permission :not_allowed' do- expect(subject.success).to be_truthy- expect(subject.result.first.origin_permission).to be :not_allowed+ expect(service.success).to be_truthy+ expect(service.result.first.origin_permission).to be :not_allowedendend@@ -101,16 +99,18 @@ RSpec.describe Storages::FileLinkSyncService, type: :model dolet(:file_links) { [file_link_one, file_link_two] }before do- allow(files_info_query).to receive(:call).and_return(ServiceResult.success(result: [file_info_one, file_info_two]))+ Storages::Peripherals::Registry+ .stub('queries.nextcloud.files_info_query',+ ->(_) { ServiceResult.success(result: [file_info_one, file_info_two]) })endit 'returns a successful result with two file links with different permissions' do- expect(subject.success).to be_truthy- expect(subject.result.count).to be 2- expect(subject.result[0].origin_id).to eql file_info_one.id- expect(subject.result[1].origin_id).to eql file_info_two.id- expect(subject.result[0].origin_permission).to be :view- expect(subject.result[1].origin_permission).to be :not_allowed+ expect(service.success).to be_truthy+ expect(service.result.count).to be 2+ expect(service.result[0].origin_id).to eql file_info_one.id+ expect(service.result[1].origin_id).to eql file_info_two.id+ expect(service.result[0].origin_permission).to be :view+ expect(service.result[1].origin_permission).to be :not_allowedendend@@ -119,12 +119,13 @@ RSpec.describe Storages::FileLinkSyncService, type: :model dolet(:file_link_one) { create(:file_link, origin_id: file_info.id, storage: storage_one, container: work_package) }before do- allow(files_info_query).to receive(:call).and_return(ServiceResult.success(result: [file_info]))+ Storages::Peripherals::Registry+ .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })endit 'deletes the file link' do- expect(subject.success).to be_truthy- expect(subject.result.count).to be 0+ expect(service.success).to be_truthy+ expect(service.result.count).to be 0expect(Storages::FileLink.all.count).to be 0endend@@ -134,27 +135,28 @@ RSpec.describe Storages::FileLinkSyncService, type: :model dolet(:file_link_one) { create(:file_link, origin_id: file_info.id, storage: storage_one, container: work_package) }before do- allow(files_info_query).to receive(:call).and_return(ServiceResult.success(result: [file_info]))+ Storages::Peripherals::Registry+ .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })endit 'returns the file link with a permission set to :error' do- expect(subject.success).to be_truthy- expect(subject.result.count).to be 1+ expect(service.success).to be_truthy+ expect(service.result.count).to be 1expect(Storages::FileLink.all.count).to be 1- expect(subject.result.first.origin_permission).to be :error+ expect(service.result.first.origin_permission).to be :errorendendcontext 'with files_info_query failing' dobefore do- allow(files_info_query).to receive(:call).and_return(- ServiceResult.failure(result: :error, errors: Storages::StorageError.new(code: :error))- )+ Storages::Peripherals::Registry+ .stub('queries.nextcloud.files_info_query',+ ->(_) { ServiceResult.failure(result: :error, errors: Storages::StorageError.new(code: :error)) })endit 'leaves the list of file_links unchanged with permissions = :error' do- expect(subject.success).to be_truthy- expect(subject.result.first.origin_permission).to be :error+ expect(service.success).to be_truthy+ expect(service.result.first.origin_permission).to be :errorendend@@ -163,13 +165,14 @@ RSpec.describe Storages::FileLinkSyncService, type: :model dolet(:file_link_one) { create(:file_link, origin_id: file_info.id, storage: storage_one, container: work_package) }before do- allow(files_info_query).to receive(:call).and_return(ServiceResult.success(result: [file_info]))+ Storages::Peripherals::Registry+ .stub('queries.nextcloud.files_info_query', ->(_) { ServiceResult.success(result: [file_info]) })endit 'returns an empty list of FileLinks' doexpect(subject).to be_a ServiceResult- expect(subject.success).to be_truthy- expect(subject.result.length).to be 0+ expect(service.success).to be_truthy+ expect(service.result.length).to be 0endendend