Commit 8306fb5f authored by Markus Koller's avatar Markus Koller

Merge branch 'fj-replace-delete-page-rpc-call' into 'master'

Replace wiki_delete_page RPC [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!56495
parents 0f0f010d a950b6d7
...@@ -196,10 +196,20 @@ class Wiki ...@@ -196,10 +196,20 @@ class Wiki
def delete_page(page, message = nil) def delete_page(page, message = nil)
return unless page return unless page
wiki.delete_page(page.path, commit_details(:deleted, message, page.title)) if Feature.enabled?(:gitaly_replace_wiki_delete_page, user, default_enabled: :yaml)
after_wiki_activity capture_git_error(:deleted) do
repository.delete_file(user, page.path, **multi_commit_options(:deleted, message, page.title))
true after_wiki_activity
true
end
else
wiki.delete_page(page.path, commit_details(:deleted, message, page.title))
after_wiki_activity
true
end
end end
def page_title_and_dir(title) def page_title_and_dir(title)
...@@ -276,8 +286,20 @@ class Wiki ...@@ -276,8 +286,20 @@ class Wiki
private private
def multi_commit_options(action, message = nil, title = nil)
commit_message = build_commit_message(action, message, title)
git_user = Gitlab::Git::User.from_gitlab(user)
{
branch_name: repository.root_ref,
message: commit_message,
author_email: git_user.email,
author_name: git_user.name
}
end
def commit_details(action, message = nil, title = nil) def commit_details(action, message = nil, title = nil)
commit_message = message.presence || default_message(action, title) commit_message = build_commit_message(action, message, title)
git_user = Gitlab::Git::User.from_gitlab(user) git_user = Gitlab::Git::User.from_gitlab(user)
Gitlab::Git::Wiki::CommitDetails.new(user.id, Gitlab::Git::Wiki::CommitDetails.new(user.id,
...@@ -287,9 +309,26 @@ class Wiki ...@@ -287,9 +309,26 @@ class Wiki
commit_message) commit_message)
end end
def build_commit_message(action, message, title)
message.presence || default_message(action, title)
end
def default_message(action, title) def default_message(action, title)
"#{user.username} #{action} page: #{title}" "#{user.username} #{action} page: #{title}"
end end
def capture_git_error(action, &block)
yield block
rescue Gitlab::Git::Index::IndexError,
Gitlab::Git::CommitError,
Gitlab::Git::PreReceiveError,
Gitlab::Git::CommandError,
ArgumentError => error
Gitlab::ErrorTracking.log_exception(error, action: action, wiki_id: id)
false
end
end end
Wiki.prepend_if_ee('EE::Wiki') Wiki.prepend_if_ee('EE::Wiki')
---
name: gitaly_replace_wiki_delete_page
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56495
rollout_issue_url:
milestone: '13.10'
type: development
group: group::editor
default_enabled: false
...@@ -481,28 +481,53 @@ RSpec.shared_examples 'wiki model' do ...@@ -481,28 +481,53 @@ RSpec.shared_examples 'wiki model' do
end end
describe '#delete_page' do describe '#delete_page' do
let(:page) { create(:wiki_page, wiki: wiki) } shared_examples 'delete_page operations' do
let(:page) { create(:wiki_page, wiki: wiki) }
it 'deletes the page' do it 'deletes the page' do
subject.delete_page(page) subject.delete_page(page)
expect(subject.list_pages.count).to eq(0) expect(subject.list_pages.count).to eq(0)
end end
it 'sets the correct commit email' do it 'sets the correct commit email' do
subject.delete_page(page) subject.delete_page(page)
expect(user.commit_email).not_to eq(user.email) expect(user.commit_email).not_to eq(user.email)
expect(commit.author_email).to eq(user.commit_email) expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email) expect(commit.committer_email).to eq(user.commit_email)
end
it 'runs after_wiki_activity callbacks' do
page
expect(subject).to receive(:after_wiki_activity)
subject.delete_page(page)
end
end end
it 'runs after_wiki_activity callbacks' do it_behaves_like 'delete_page operations'
page
expect(subject).to receive(:after_wiki_activity) context 'when an error is raised' do
it 'logs the error and returns false' do
page = build(:wiki_page, wiki: wiki)
exception = Gitlab::Git::Index::IndexError.new('foo')
allow(subject.repository).to receive(:delete_file).and_raise(exception)
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(exception, action: :deleted, wiki_id: wiki.id)
expect(subject.delete_page(page)).to be_falsey
end
end
context 'when feature flag :gitaly_replace_wiki_delete_page is disabled' do
before do
stub_feature_flags(gitaly_replace_wiki_delete_page: false)
end
subject.delete_page(page) it_behaves_like 'delete_page operations'
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