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

[#53345] Synchronize only configured storages.

Pavel Balashou7e6a7fcdfde9
diff --git a/modules/storages/app/workers/storages/manage_nextcloud_integration_job_mixin.rb b/modules/storages/app/workers/storages/manage_nextcloud_integration_job_mixin.rb
index 661930c1e6b..21e096fa375 100644
--- a/modules/storages/app/workers/storages/manage_nextcloud_integration_job_mixin.rb
+++ b/modules/storages/app/workers/storages/manage_nextcloud_integration_job_mixin.rb
@@ -40,6 +40,8 @@ module Storages
transaction: false
) do
::Storages::Storage.automatic_management_enabled.includes(:oauth_client).find_each do |storage|
+ next unless storage.configured?
+
result = service_for(storage).call(storage)
result.match(
on_success: ->(_) do
diff --git a/modules/storages/spec/factories/storage_factory.rb b/modules/storages/spec/factories/storage_factory.rb
index 268c8b1e96b..d6e3a048059 100644
--- a/modules/storages/spec/factories/storage_factory.rb
+++ b/modules/storages/spec/factories/storage_factory.rb
@@ -33,12 +33,13 @@ FactoryBot.define do
sequence(:name) { |n| "Storage #{n}" }
creator factory: :user
- # rubocop:disable FactoryBot/FactoryAssociationWithStrategy
- # For some reason the order of saving breaks STI
trait :with_oauth_client do
- oauth_client { build(:oauth_client) }
+ oauth_client
+ end
+
+ trait :with_oauth_application do
+ oauth_application
end
- # rubocop:enable FactoryBot/FactoryAssociationWithStrategy
trait :as_generic do
provider_type { 'Storages::Storage' }
@@ -65,6 +66,11 @@ FactoryBot.define do
automatically_managed { false }
end
+ trait :configured do
+ with_oauth_application
+ with_oauth_client
+ end
+
trait :as_healthy do
health_status { 'healthy' }
health_reason { nil }
diff --git a/modules/storages/spec/workers/storages/manage_nextcloud_integration_cron_job_spec.rb b/modules/storages/spec/workers/storages/manage_nextcloud_integration_cron_job_spec.rb
index 689dbb1a096..e953913e5a0 100644
--- a/modules/storages/spec/workers/storages/manage_nextcloud_integration_cron_job_spec.rb
+++ b/modules/storages/spec/workers/storages/manage_nextcloud_integration_cron_job_spec.rb
@@ -85,12 +85,13 @@ RSpec.describe Storages::ManageNextcloudIntegrationCronJob, :webmock, type: :job
subject { described_class.new.perform }
context 'when lock is free' do
+ let(:storage1) { create(:nextcloud_storage, :as_automatically_managed, :configured) }
+
it 'responds with true' do
expect(subject).to be(true)
end
it 'calls GroupFolderPropertiesSyncService for each automatically managed storage' do
- storage1 = create(:nextcloud_storage, :as_automatically_managed)
storage2 = create(:nextcloud_storage, :as_not_automatically_managed)
allow(Storages::NextcloudGroupFolderPropertiesSyncService)
@@ -103,8 +104,6 @@ RSpec.describe Storages::ManageNextcloudIntegrationCronJob, :webmock, type: :job
end
it 'marks storage as healthy if sync was successful' do
- storage1 = create(:nextcloud_storage, :as_automatically_managed)
-
allow(Storages::NextcloudGroupFolderPropertiesSyncService)
.to receive(:call).with(storage1).and_return(ServiceResult.success)
@@ -120,10 +119,10 @@ RSpec.describe Storages::ManageNextcloudIntegrationCronJob, :webmock, type: :job
end
it 'marks storage as unhealthy if sync was unsuccessful' do
- storage1 = create(:nextcloud_storage, :as_automatically_managed)
-
allow(Storages::NextcloudGroupFolderPropertiesSyncService)
- .to receive(:call).with(storage1).and_return(ServiceResult.failure(errors: Storages::StorageError.new(code: :not_found)))
+ .to receive(:call)
+ .with(storage1)
+ .and_return(ServiceResult.failure(errors: Storages::StorageError.new(code: :not_found)))
Timecop.freeze('2023-03-14T15:17:00Z') do
expect do