Commit 46164319 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'remove-overwrite-on-propagate-integrations' into 'master'

Remove overwrite param on propagate integrations

See merge request gitlab-org/gitlab!40381
parents 0347681c 9a026201
...@@ -16,12 +16,11 @@ module IntegrationsActions ...@@ -16,12 +16,11 @@ module IntegrationsActions
def update def update
saved = integration.update(service_params[:service]) saved = integration.update(service_params[:service])
overwrite = Gitlab::Utils.to_boolean(params[:overwrite])
respond_to do |format| respond_to do |format|
format.html do format.html do
if saved if saved
PropagateIntegrationWorker.perform_async(integration.id, overwrite) PropagateIntegrationWorker.perform_async(integration.id, false)
redirect_to scoped_edit_integration_path(integration), notice: success_message redirect_to scoped_edit_integration_path(integration), notice: success_message
else else
render 'shared/integrations/edit' render 'shared/integrations/edit'
......
...@@ -6,42 +6,30 @@ module Admin ...@@ -6,42 +6,30 @@ module Admin
delegate :data_fields_present?, to: :integration delegate :data_fields_present?, to: :integration
def self.propagate(integration:, overwrite:) def self.propagate(integration)
new(integration, overwrite).propagate new(integration).propagate
end end
def initialize(integration, overwrite) def initialize(integration)
@integration = integration @integration = integration
@overwrite = overwrite
end end
def propagate def propagate
if overwrite update_inherited_integrations
update_integration_for_all_projects
else
update_integration_for_inherited_projects
end
create_integration_for_projects_without_integration create_integration_for_projects_without_integration
end end
private private
attr_reader :integration, :overwrite attr_reader :integration
# rubocop: disable Cop/InBatches # rubocop: disable Cop/InBatches
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def update_integration_for_inherited_projects def update_inherited_integrations
Service.where(type: integration.type, inherit_from_id: integration.id).in_batches(of: BATCH_SIZE) do |batch| Service.where(type: integration.type, inherit_from_id: integration.id).in_batches(of: BATCH_SIZE) do |batch|
bulk_update_from_integration(batch) bulk_update_from_integration(batch)
end end
end end
def update_integration_for_all_projects
Service.where(type: integration.type).in_batches(of: BATCH_SIZE) do |batch|
bulk_update_from_integration(batch)
end
end
# rubocop: enable Cop/InBatches # rubocop: enable Cop/InBatches
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -7,10 +7,8 @@ class PropagateIntegrationWorker ...@@ -7,10 +7,8 @@ class PropagateIntegrationWorker
idempotent! idempotent!
loggable_arguments 1 loggable_arguments 1
def perform(integration_id, overwrite) # Keep overwrite parameter for backwards compatibility.
Admin::PropagateIntegrationService.propagate( def perform(integration_id, overwrite = nil)
integration: Service.find(integration_id), Admin::PropagateIntegrationService.propagate(Service.find(integration_id))
overwrite: overwrite
)
end end
end end
...@@ -28,7 +28,7 @@ RSpec.describe Admin::IntegrationsController do ...@@ -28,7 +28,7 @@ RSpec.describe Admin::IntegrationsController do
before do before do
allow(PropagateIntegrationWorker).to receive(:perform_async) allow(PropagateIntegrationWorker).to receive(:perform_async)
put :update, params: { id: integration.class.to_param, overwrite: true, service: { url: url } } put :update, params: { id: integration.class.to_param, service: { url: url } }
end end
context 'valid params' do context 'valid params' do
...@@ -40,7 +40,7 @@ RSpec.describe Admin::IntegrationsController do ...@@ -40,7 +40,7 @@ RSpec.describe Admin::IntegrationsController do
end end
it 'calls to PropagateIntegrationWorker' do it 'calls to PropagateIntegrationWorker' do
expect(PropagateIntegrationWorker).to have_received(:perform_async).with(integration.id, true) expect(PropagateIntegrationWorker).to have_received(:perform_async).with(integration.id, false)
end end
end end
......
...@@ -43,7 +43,7 @@ RSpec.describe Admin::PropagateIntegrationService do ...@@ -43,7 +43,7 @@ RSpec.describe Admin::PropagateIntegrationService do
) )
end end
let!(:another_inherited_integration) do let!(:different_type_inherited_integration) do
BambooService.create!( BambooService.create!(
project: create(:project), project: create(:project),
inherit_from_id: instance_integration.id, inherit_from_id: instance_integration.id,
...@@ -59,7 +59,7 @@ RSpec.describe Admin::PropagateIntegrationService do ...@@ -59,7 +59,7 @@ RSpec.describe Admin::PropagateIntegrationService do
shared_examples 'inherits settings from integration' do shared_examples 'inherits settings from integration' do
it 'updates the inherited integrations' do it 'updates the inherited integrations' do
described_class.propagate(integration: instance_integration, overwrite: overwrite) described_class.propagate(instance_integration)
expect(integration.reload.inherit_from_id).to eq(instance_integration.id) expect(integration.reload.inherit_from_id).to eq(instance_integration.id)
expect(integration.attributes.except(*excluded_attributes)) expect(integration.attributes.except(*excluded_attributes))
...@@ -70,7 +70,7 @@ RSpec.describe Admin::PropagateIntegrationService do ...@@ -70,7 +70,7 @@ RSpec.describe Admin::PropagateIntegrationService do
let(:excluded_attributes) { %w[id service_id created_at updated_at] } let(:excluded_attributes) { %w[id service_id created_at updated_at] }
it 'updates the data fields from inherited integrations' do it 'updates the data fields from inherited integrations' do
described_class.propagate(integration: instance_integration, overwrite: overwrite) described_class.propagate(instance_integration)
expect(integration.reload.data_fields.attributes.except(*excluded_attributes)) expect(integration.reload.data_fields.attributes.except(*excluded_attributes))
.to eq(instance_integration.data_fields.attributes.except(*excluded_attributes)) .to eq(instance_integration.data_fields.attributes.except(*excluded_attributes))
...@@ -80,7 +80,7 @@ RSpec.describe Admin::PropagateIntegrationService do ...@@ -80,7 +80,7 @@ RSpec.describe Admin::PropagateIntegrationService do
shared_examples 'does not inherit settings from integration' do shared_examples 'does not inherit settings from integration' do
it 'does not update the not inherited integrations' do it 'does not update the not inherited integrations' do
described_class.propagate(integration: instance_integration, overwrite: overwrite) described_class.propagate(instance_integration)
expect(integration.reload.attributes.except(*excluded_attributes)) expect(integration.reload.attributes.except(*excluded_attributes))
.not_to eq(instance_integration.attributes.except(*excluded_attributes)) .not_to eq(instance_integration.attributes.except(*excluded_attributes))
...@@ -88,8 +88,6 @@ RSpec.describe Admin::PropagateIntegrationService do ...@@ -88,8 +88,6 @@ RSpec.describe Admin::PropagateIntegrationService do
end end
context 'update only inherited integrations' do context 'update only inherited integrations' do
let(:overwrite) { false }
it_behaves_like 'inherits settings from integration' do it_behaves_like 'inherits settings from integration' do
let(:integration) { inherited_integration } let(:integration) { inherited_integration }
end end
...@@ -99,27 +97,7 @@ RSpec.describe Admin::PropagateIntegrationService do ...@@ -99,27 +97,7 @@ RSpec.describe Admin::PropagateIntegrationService do
end end
it_behaves_like 'does not inherit settings from integration' do it_behaves_like 'does not inherit settings from integration' do
let(:integration) { another_inherited_integration } let(:integration) { different_type_inherited_integration }
end
it_behaves_like 'inherits settings from integration' do
let(:integration) { project.jira_service }
end
end
context 'update all integrations' do
let(:overwrite) { true }
it_behaves_like 'inherits settings from integration' do
let(:integration) { inherited_integration }
end
it_behaves_like 'inherits settings from integration' do
let(:integration) { not_inherited_integration }
end
it_behaves_like 'does not inherit settings from integration' do
let(:integration) { another_inherited_integration }
end end
it_behaves_like 'inherits settings from integration' do it_behaves_like 'inherits settings from integration' do
...@@ -128,7 +106,7 @@ RSpec.describe Admin::PropagateIntegrationService do ...@@ -128,7 +106,7 @@ RSpec.describe Admin::PropagateIntegrationService do
end end
it 'updates project#has_external_issue_tracker for issue tracker services' do it 'updates project#has_external_issue_tracker for issue tracker services' do
described_class.propagate(integration: instance_integration, overwrite: true) described_class.propagate(instance_integration)
expect(project.reload.has_external_issue_tracker).to eq(true) expect(project.reload.has_external_issue_tracker).to eq(true)
end end
...@@ -141,7 +119,7 @@ RSpec.describe Admin::PropagateIntegrationService do ...@@ -141,7 +119,7 @@ RSpec.describe Admin::PropagateIntegrationService do
external_wiki_url: 'http://external-wiki-url.com' external_wiki_url: 'http://external-wiki-url.com'
) )
described_class.propagate(integration: instance_integration, overwrite: true) described_class.propagate(instance_integration)
expect(project.reload.has_external_wiki).to eq(true) expect(project.reload.has_external_wiki).to eq(true)
end end
......
...@@ -17,8 +17,13 @@ RSpec.describe PropagateIntegrationWorker do ...@@ -17,8 +17,13 @@ RSpec.describe PropagateIntegrationWorker do
end end
it 'calls the propagate service with the integration' do it 'calls the propagate service with the integration' do
expect(Admin::PropagateIntegrationService).to receive(:propagate) expect(Admin::PropagateIntegrationService).to receive(:propagate).with(integration)
.with(integration: integration, overwrite: true)
subject.perform(integration.id)
end
it 'ignores overwrite parameter from previous version' do
expect(Admin::PropagateIntegrationService).to receive(:propagate).with(integration)
subject.perform(integration.id, true) subject.perform(integration.id, true)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment