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 ...@@ -34,11 +34,11 @@ class BulkCreateIntegrationService
end end
def run_callbacks(batch) def run_callbacks(batch)
if integration.issue_tracker? if integration.issue_tracker? && integration.active?
batch.update_all(has_external_issue_tracker: true) batch.update_all(has_external_issue_tracker: true)
end end
if integration.type == 'ExternalWikiService' if integration.type == 'ExternalWikiService' && integration.active?
batch.update_all(has_external_wiki: true) batch.update_all(has_external_wiki: true)
end end
end end
......
...@@ -10,8 +10,10 @@ FactoryBot.define do ...@@ -10,8 +10,10 @@ FactoryBot.define do
factory :project, class: 'Project' do factory :project, class: 'Project' do
sequence(:name) { |n| "project#{n}" } sequence(:name) { |n| "project#{n}" }
path { name.downcase.gsub(/\s/, '_') } 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_issue_tracker { false }
has_external_wiki { false }
# Associations # Associations
namespace namespace
......
...@@ -890,7 +890,7 @@ RSpec.describe API::Projects do ...@@ -890,7 +890,7 @@ RSpec.describe API::Projects do
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
project.each_pair do |k, v| 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) expect(json_response[k.to_s]).to eq(v)
end end
...@@ -1309,7 +1309,7 @@ RSpec.describe API::Projects do ...@@ -1309,7 +1309,7 @@ RSpec.describe API::Projects do
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
project.each_pair do |k, v| 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) expect(json_response[k.to_s]).to eq(v)
end end
......
...@@ -41,7 +41,7 @@ RSpec.describe BulkCreateIntegrationService do ...@@ -41,7 +41,7 @@ RSpec.describe BulkCreateIntegrationService do
end end
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 it 'updates projects#has_external_issue_tracker for issue tracker services' do
described_class.new(integration, batch, association).execute described_class.new(integration, batch, association).execute
...@@ -53,7 +53,6 @@ RSpec.describe BulkCreateIntegrationService do ...@@ -53,7 +53,6 @@ RSpec.describe BulkCreateIntegrationService do
ExternalWikiService.create!( ExternalWikiService.create!(
instance: true, instance: true,
active: true, active: true,
push_events: false,
external_wiki_url: 'http://external-wiki-url.com' external_wiki_url: 'http://external-wiki-url.com'
) )
end end
...@@ -66,6 +65,30 @@ RSpec.describe BulkCreateIntegrationService do ...@@ -66,6 +65,30 @@ RSpec.describe BulkCreateIntegrationService do
end end
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 context 'with an instance-level integration' do
let(:integration) { instance_integration } let(:integration) { instance_integration }
...@@ -77,7 +100,15 @@ RSpec.describe BulkCreateIntegrationService do ...@@ -77,7 +100,15 @@ RSpec.describe BulkCreateIntegrationService do
it_behaves_like 'creates integration from batch ids' it_behaves_like 'creates integration from batch ids'
it_behaves_like 'updates inherit_from_id' 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 end
context 'with a group association' do context 'with a group association' do
...@@ -101,7 +132,7 @@ RSpec.describe BulkCreateIntegrationService do ...@@ -101,7 +132,7 @@ RSpec.describe BulkCreateIntegrationService do
let(:association) { 'project' } let(:association) { 'project' }
it_behaves_like 'creates integration from batch ids' it_behaves_like 'creates integration from batch ids'
it_behaves_like 'runs project callbacks' it_behaves_like 'updates project callbacks'
end end
end 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