Commit 9a026201 authored by Arturo Herrero's avatar Arturo Herrero

Remove overwrite param on propagate integrations

Initially we developed the functionality to propagate integration
settings to all projects, but we are not going to use this
functionality.
parent 7d6a27e2
......@@ -16,12 +16,11 @@ module IntegrationsActions
def update
saved = integration.update(service_params[:service])
overwrite = Gitlab::Utils.to_boolean(params[:overwrite])
respond_to do |format|
format.html do
if saved
PropagateIntegrationWorker.perform_async(integration.id, overwrite)
PropagateIntegrationWorker.perform_async(integration.id, false)
redirect_to scoped_edit_integration_path(integration), notice: success_message
else
render 'shared/integrations/edit'
......
......@@ -6,42 +6,30 @@ module Admin
delegate :data_fields_present?, to: :integration
def self.propagate(integration:, overwrite:)
new(integration, overwrite).propagate
def self.propagate(integration)
new(integration).propagate
end
def initialize(integration, overwrite)
def initialize(integration)
@integration = integration
@overwrite = overwrite
end
def propagate
if overwrite
update_integration_for_all_projects
else
update_integration_for_inherited_projects
end
update_inherited_integrations
create_integration_for_projects_without_integration
end
private
attr_reader :integration, :overwrite
attr_reader :integration
# rubocop: disable Cop/InBatches
# 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|
bulk_update_from_integration(batch)
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 CodeReuse/ActiveRecord
......
......@@ -7,10 +7,8 @@ class PropagateIntegrationWorker
idempotent!
loggable_arguments 1
def perform(integration_id, overwrite)
Admin::PropagateIntegrationService.propagate(
integration: Service.find(integration_id),
overwrite: overwrite
)
# Keep overwrite parameter for backwards compatibility.
def perform(integration_id, overwrite = nil)
Admin::PropagateIntegrationService.propagate(Service.find(integration_id))
end
end
......@@ -28,7 +28,7 @@ RSpec.describe Admin::IntegrationsController do
before do
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
context 'valid params' do
......@@ -40,7 +40,7 @@ RSpec.describe Admin::IntegrationsController do
end
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
......
......@@ -43,7 +43,7 @@ RSpec.describe Admin::PropagateIntegrationService do
)
end
let!(:another_inherited_integration) do
let!(:different_type_inherited_integration) do
BambooService.create!(
project: create(:project),
inherit_from_id: instance_integration.id,
......@@ -59,7 +59,7 @@ RSpec.describe Admin::PropagateIntegrationService do
shared_examples 'inherits settings from integration' 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.attributes.except(*excluded_attributes))
......@@ -70,7 +70,7 @@ RSpec.describe Admin::PropagateIntegrationService do
let(:excluded_attributes) { %w[id service_id created_at updated_at] }
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))
.to eq(instance_integration.data_fields.attributes.except(*excluded_attributes))
......@@ -80,7 +80,7 @@ RSpec.describe Admin::PropagateIntegrationService do
shared_examples 'does not inherit settings from integration' 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))
.not_to eq(instance_integration.attributes.except(*excluded_attributes))
......@@ -88,8 +88,6 @@ RSpec.describe Admin::PropagateIntegrationService do
end
context 'update only inherited integrations' do
let(:overwrite) { false }
it_behaves_like 'inherits settings from integration' do
let(:integration) { inherited_integration }
end
......@@ -99,27 +97,7 @@ RSpec.describe Admin::PropagateIntegrationService do
end
it_behaves_like 'does not inherit settings from integration' do
let(:integration) { another_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 }
let(:integration) { different_type_inherited_integration }
end
it_behaves_like 'inherits settings from integration' do
......@@ -128,7 +106,7 @@ RSpec.describe Admin::PropagateIntegrationService do
end
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)
end
......@@ -141,7 +119,7 @@ RSpec.describe Admin::PropagateIntegrationService do
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)
end
......
......@@ -17,8 +17,13 @@ RSpec.describe PropagateIntegrationWorker do
end
it 'calls the propagate service with the integration' do
expect(Admin::PropagateIntegrationService).to receive(:propagate)
.with(integration: integration, overwrite: true)
expect(Admin::PropagateIntegrationService).to receive(:propagate).with(integration)
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)
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