Create a push event on Geo event log when wiki is updated through UI

parent d8bd743e
...@@ -21,5 +21,15 @@ module WikiPages ...@@ -21,5 +21,15 @@ module WikiPages
@project.execute_hooks(page_data, :wiki_page_hooks) @project.execute_hooks(page_data, :wiki_page_hooks)
@project.execute_services(page_data, :wiki_page_hooks) @project.execute_services(page_data, :wiki_page_hooks)
end end
def process_wiki_changes
if Gitlab::Geo.primary?
# Create wiki update event on Geo event log
Geo::PushEventStore.new(project, source: Geo::PushEvent::WIKI).create
# Triggers repository update on secondary nodes
Gitlab::Geo.notify_wiki_update(project)
end
end
end end
end end
...@@ -6,6 +6,7 @@ module WikiPages ...@@ -6,6 +6,7 @@ module WikiPages
if page.create(@params) if page.create(@params)
execute_hooks(page, 'create') execute_hooks(page, 'create')
process_wiki_changes
end end
page page
......
...@@ -3,9 +3,7 @@ module WikiPages ...@@ -3,9 +3,7 @@ module WikiPages
def execute(page) def execute(page)
if page&.delete if page&.delete
execute_hooks(page, 'delete') execute_hooks(page, 'delete')
process_wiki_changes
# Triggers repository update on secondary nodes when Geo is enabled
Gitlab::Geo.notify_wiki_update(project) if Gitlab::Geo.primary?
end end
page page
......
...@@ -3,6 +3,7 @@ module WikiPages ...@@ -3,6 +3,7 @@ module WikiPages
def execute(page) def execute(page)
if page.update(@params[:content], @params[:format], @params[:message]) if page.update(@params[:content], @params[:format], @params[:message])
execute_hooks(page, 'update') execute_hooks(page, 'update')
process_wiki_changes
end end
page page
......
...@@ -2,7 +2,8 @@ require 'spec_helper' ...@@ -2,7 +2,8 @@ require 'spec_helper'
describe WikiPages::CreateService, services: true do describe WikiPages::CreateService, services: true do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:opts) do let(:opts) do
{ {
title: 'Title', title: 'Title',
...@@ -10,26 +11,43 @@ describe WikiPages::CreateService, services: true do ...@@ -10,26 +11,43 @@ describe WikiPages::CreateService, services: true do
format: 'markdown' format: 'markdown'
} }
end end
let(:service) { described_class.new(project, user, opts) }
subject(:service) { described_class.new(project, user, opts) }
before do
project.add_master(user)
end
describe '#execute' do describe '#execute' do
context "valid params" do it 'creates wiki page with valid attributes' do
page = service.execute
expect(page).to be_valid
expect(page).to have_attributes(title: opts[:title], content: opts[:content], format: opts[:format].to_sym)
end
it 'executes webhooks' do
expect(service).to receive(:execute_hooks).once.with(instance_of(WikiPage), 'create')
service.execute
end
context 'when running on a Geo primary node' do
before do before do
allow(service).to receive(:execute_hooks) allow(Gitlab::Geo).to receive(:primary?) { true }
project.add_master(user)
end end
subject { service.execute } it 'triggers Geo::PushEventStore when Geo is enabled' do
expect(Geo::PushEventStore).to receive(:new).with(instance_of(Project), source: Geo::PushEvent::WIKI).and_call_original
expect_any_instance_of(Geo::PushEventStore).to receive(:create)
it 'creates a valid wiki page' do service.execute
is_expected.to be_valid
expect(subject.title).to eq(opts[:title])
expect(subject.content).to eq(opts[:content])
expect(subject.format).to eq(opts[:format].to_sym)
end end
it 'executes webhooks' do it 'triggers wiki update on secondary nodes' do
expect(service).to have_received(:execute_hooks).once.with(subject, 'create') expect(Gitlab::Geo).to receive(:notify_wiki_update).with(instance_of(Project))
service.execute
end end
end end
end end
......
...@@ -2,20 +2,39 @@ require 'spec_helper' ...@@ -2,20 +2,39 @@ require 'spec_helper'
describe WikiPages::DestroyService, services: true do describe WikiPages::DestroyService, services: true do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:wiki_page) { create(:wiki_page) } let(:page) { create(:wiki_page) }
let(:service) { described_class.new(project, user) }
subject(:service) { described_class.new(project, user) }
before do
project.add_master(user)
end
describe '#execute' do describe '#execute' do
before do it 'executes webhooks' do
allow(service).to receive(:execute_hooks) expect(service).to receive(:execute_hooks).once.with(instance_of(WikiPage), 'delete')
project.add_master(user)
service.execute(page)
end end
it 'executes webhooks' do context 'when running on a Geo primary node' do
service.execute(wiki_page) before do
allow(Gitlab::Geo).to receive(:primary?) { true }
end
it 'triggers Geo::PushEventStore when Geo is enabled' do
expect(Geo::PushEventStore).to receive(:new).with(instance_of(Project), source: Geo::PushEvent::WIKI).and_call_original
expect_any_instance_of(Geo::PushEventStore).to receive(:create)
service.execute(page)
end
it 'triggers wiki update on secondary nodes' do
expect(Gitlab::Geo).to receive(:notify_wiki_update).with(instance_of(Project))
expect(service).to have_received(:execute_hooks).once.with(wiki_page, 'delete') service.execute(page)
end
end end
end end
end end
...@@ -2,8 +2,9 @@ require 'spec_helper' ...@@ -2,8 +2,9 @@ require 'spec_helper'
describe WikiPages::UpdateService, services: true do describe WikiPages::UpdateService, services: true do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:wiki_page) { create(:wiki_page) } let(:page) { create(:wiki_page) }
let(:opts) do let(:opts) do
{ {
content: 'New content for wiki page', content: 'New content for wiki page',
...@@ -11,26 +12,43 @@ describe WikiPages::UpdateService, services: true do ...@@ -11,26 +12,43 @@ describe WikiPages::UpdateService, services: true do
message: 'New wiki message' message: 'New wiki message'
} }
end end
let(:service) { described_class.new(project, user, opts) }
subject(:service) { described_class.new(project, user, opts) }
before do
project.add_master(user)
end
describe '#execute' do describe '#execute' do
context "valid params" do it 'updates the wiki page' do
updated_page = service.execute(page)
expect(updated_page).to be_valid
expect(updated_page).to have_attributes(message: opts[:message], content: opts[:content], format: opts[:format].to_sym)
end
it 'executes webhooks' do
expect(service).to receive(:execute_hooks).once.with(instance_of(WikiPage), 'update')
service.execute(page)
end
context 'when running on a Geo primary node' do
before do before do
allow(service).to receive(:execute_hooks) allow(Gitlab::Geo).to receive(:primary?) { true }
project.add_master(user)
end end
subject { service.execute(wiki_page) } it 'triggers Geo::PushEventStore when Geo is enabled' do
expect(Geo::PushEventStore).to receive(:new).with(instance_of(Project), source: Geo::PushEvent::WIKI).and_call_original
expect_any_instance_of(Geo::PushEventStore).to receive(:create)
it 'updates the wiki page' do service.execute(page)
is_expected.to be_valid
expect(subject.content).to eq(opts[:content])
expect(subject.format).to eq(opts[:format].to_sym)
expect(subject.message).to eq(opts[:message])
end end
it 'executes webhooks' do it 'triggers wiki update on secondary nodes' do
expect(service).to have_received(:execute_hooks).once.with(subject, 'update') expect(Gitlab::Geo).to receive(:notify_wiki_update).with(instance_of(Project))
service.execute(page)
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