Commit f353d63f authored by Michael Kozono's avatar Michael Kozono

Trigger wiki sync when enabled

parent e46cd8b5
......@@ -14,12 +14,17 @@ module EE
end
should_remove_old_approvers = params.delete(:remove_old_approvers)
wiki_was_enabled = project.wiki_enabled?
result = super
cleanup_approvers(project) if should_remove_old_approvers && result[:status] == :success
if result[:status] == :success
cleanup_approvers(project) if should_remove_old_approvers
log_audit_events if result[:status] == :success
log_audit_events
sync_wiki_on_enable if !wiki_was_enabled && project.wiki_enabled?
end
result
end
......@@ -36,6 +41,10 @@ module EE
def log_audit_events
EE::Audit::ProjectChangesAuditor.new(current_user, project).execute
end
def sync_wiki_on_enable
::Geo::RepositoryUpdatedService.new(project, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute
end
end
end
end
---
title: 'Geo: Sync wiki when it is enabled'
merge_request: 5139
author:
type: fixed
require 'spec_helper'
describe Projects::UpdateService, '#execute' do
include EE::GeoHelpers
let(:user) { create(:user) }
let(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
......@@ -123,6 +125,77 @@ describe Projects::UpdateService, '#execute' do
end
end
context 'triggering wiki Geo syncs', :geo do
context 'on a Geo primary' do
set(:primary) { create(:geo_node, :primary) }
set(:secondary) { create(:geo_node) }
before do
stub_current_geo_node(primary)
end
context 'when enabling a wiki' do
it 'creates a RepositoryUpdatedEvent' do
project.project_feature.update(wiki_access_level: ProjectFeature::DISABLED)
project.reload
expect do
result = update_project(project, user, project_feature_attributes: { wiki_access_level: ProjectFeature::ENABLED })
expect(result).to eq({ status: :success })
end.to change { Geo::RepositoryUpdatedEvent.count }.by(1)
expect(project.wiki_enabled?).to be true
end
end
context 'when we update project but not enabling a wiki' do
context 'when the wiki is disabled' do
it 'does not create a RepositoryUpdatedEvent' do
project.project_feature.update(wiki_access_level: ProjectFeature::DISABLED)
expect do
result = update_project(project, user, { name: 'test1' })
expect(result).to eq({ status: :success })
end.not_to change { Geo::RepositoryUpdatedEvent.count }
expect(project.wiki_enabled?).to be false
end
end
context 'when the wiki was already enabled' do
it 'does not create a RepositoryUpdatedEvent' do
project.project_feature.update(wiki_access_level: ProjectFeature::ENABLED)
expect do
result = update_project(project, user, { name: 'test1' })
expect(result).to eq({ status: :success })
end.not_to change { Geo::RepositoryUpdatedEvent.count }
expect(project.wiki_enabled?).to be true
end
end
end
end
context 'not on a Geo node' do
before do
allow(::Gitlab::Geo).to receive(:current_node).and_return(nil)
end
it 'does not create a RepositoryUpdatedEvent when enabling a wiki' do
project.project_feature.update(wiki_access_level: ProjectFeature::DISABLED)
project.reload
expect do
result = update_project(project, user, project_feature_attributes: { wiki_access_level: ProjectFeature::ENABLED })
expect(result).to eq({ status: :success })
end.not_to change { Geo::RepositoryUpdatedEvent.count }
expect(project.wiki_enabled?).to be true
end
end
end
def update_project(project, user, opts)
Projects::UpdateService.new(project, user, opts).execute
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