Commit e186a47d authored by Arturo Herrero's avatar Arturo Herrero

Update project callbacks if integration is active

Originally, we only call here to propagate service templates if they are
active. Now, we are propagating instance-level integrations and
group-level integrations (active or not).

has_external_issue_tracker and has_external_wiki assume that the
integration is active. So, we only need to update the project callbacks
if the integration is active.
parent c2b330dc
......@@ -34,11 +34,11 @@ class BulkCreateIntegrationService
end
def run_callbacks(batch)
if integration.issue_tracker?
if integration.issue_tracker? && integration.active?
batch.update_all(has_external_issue_tracker: true)
end
if integration.type == 'ExternalWikiService'
if integration.type == 'ExternalWikiService' && integration.active?
batch.update_all(has_external_wiki: true)
end
end
......
......@@ -10,8 +10,10 @@ FactoryBot.define do
factory :project, class: 'Project' do
sequence(:name) { |n| "project#{n}" }
path { name.downcase.gsub(/\s/, '_') }
# Behaves differently to nil due to cache_has_external_issue_tracker
# Behaves differently to nil due to cache_has_external_* methods.
has_external_issue_tracker { false }
has_external_wiki { false }
# Associations
namespace
......
......@@ -890,7 +890,7 @@ RSpec.describe API::Projects do
expect(response).to have_gitlab_http_status(:created)
project.each_pair do |k, v|
next if %i[has_external_issue_tracker issues_enabled merge_requests_enabled wiki_enabled storage_version].include?(k)
next if %i[has_external_issue_tracker has_external_wiki issues_enabled merge_requests_enabled wiki_enabled storage_version].include?(k)
expect(json_response[k.to_s]).to eq(v)
end
......@@ -1309,7 +1309,7 @@ RSpec.describe API::Projects do
expect(response).to have_gitlab_http_status(:created)
project.each_pair do |k, v|
next if %i[has_external_issue_tracker path storage_version].include?(k)
next if %i[has_external_issue_tracker has_external_wiki path storage_version].include?(k)
expect(json_response[k.to_s]).to eq(v)
end
......
......@@ -41,7 +41,7 @@ RSpec.describe BulkCreateIntegrationService do
end
end
shared_examples 'runs project callbacks' do
shared_examples 'updates project callbacks' do
it 'updates projects#has_external_issue_tracker for issue tracker services' do
described_class.new(integration, batch, association).execute
......@@ -53,7 +53,6 @@ RSpec.describe BulkCreateIntegrationService do
ExternalWikiService.create!(
instance: true,
active: true,
push_events: false,
external_wiki_url: 'http://external-wiki-url.com'
)
end
......@@ -66,6 +65,30 @@ RSpec.describe BulkCreateIntegrationService do
end
end
shared_examples 'does not update project callbacks' do
it 'does not update projects#has_external_issue_tracker for issue tracker services' do
described_class.new(integration, batch, association).execute
expect(project.reload.has_external_issue_tracker).to eq(false)
end
context 'with an inactive external wiki integration' do
let(:integration) do
ExternalWikiService.create!(
instance: true,
active: false,
external_wiki_url: 'http://external-wiki-url.com'
)
end
it 'does not update projects#has_external_wiki for external wiki services' do
described_class.new(integration, batch, association).execute
expect(project.reload.has_external_wiki).to eq(false)
end
end
end
context 'with an instance-level integration' do
let(:integration) { instance_integration }
......@@ -77,7 +100,15 @@ RSpec.describe BulkCreateIntegrationService do
it_behaves_like 'creates integration from batch ids'
it_behaves_like 'updates inherit_from_id'
it_behaves_like 'runs project callbacks'
it_behaves_like 'updates project callbacks'
context 'when integration is not active' do
before do
integration.update!(active: false)
end
it_behaves_like 'does not update project callbacks'
end
end
context 'with a group association' do
......@@ -101,7 +132,7 @@ RSpec.describe BulkCreateIntegrationService do
let(:association) { 'project' }
it_behaves_like 'creates integration from batch ids'
it_behaves_like 'runs project callbacks'
it_behaves_like 'updates project callbacks'
end
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