Commit 744ae80c authored by Athar Hameed's avatar Athar Hameed Committed by Robert Speicher

Resolve "Changes will be lost if multiple people edit a wiki page"

parent b5be8cd0
...@@ -115,9 +115,6 @@ module WikiActions ...@@ -115,9 +115,6 @@ module WikiActions
@error = response.message @error = response.message
render 'shared/wikis/edit' render 'shared/wikis/edit'
end end
rescue WikiPage::PageChangedError, WikiPage::PageRenameError => e
@error = e.message
render 'shared/wikis/edit'
end end
# rubocop:enable Gitlab/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module WikiPages module WikiPages
class UpdateService < WikiPages::BaseService class UpdateService < WikiPages::BaseService
UpdateError = Class.new(StandardError)
def execute(page) def execute(page)
# this class is not thread safe! # this class is not thread safe!
@old_slug = page.slug @old_slug = page.slug
...@@ -10,11 +12,15 @@ module WikiPages ...@@ -10,11 +12,15 @@ module WikiPages
execute_hooks(page) execute_hooks(page)
ServiceResponse.success(payload: { page: page }) ServiceResponse.success(payload: { page: page })
else else
ServiceResponse.error( raise UpdateError, s_('Could not update wiki page')
message: _('Could not update wiki page'),
payload: { page: page }
)
end end
rescue UpdateError, WikiPage::PageChangedError, WikiPage::PageRenameError => e
page.update_attributes(@params) # rubocop:disable Rails/ActiveRecordAliases
ServiceResponse.error(
message: e.message,
payload: { page: page }
)
end end
def usage_counter_action def usage_counter_action
......
---
title: Preserve user changes in the wiki editor if multiple people edit the page
merge_request: 61120
author:
type: fixed
...@@ -117,14 +117,6 @@ RSpec.shared_examples 'User updates wiki page' do ...@@ -117,14 +117,6 @@ RSpec.shared_examples 'User updates wiki page' do
expect(page).to have_selector('.atwho-view') expect(page).to have_selector('.atwho-view')
end end
it 'shows the error message', :js do
wiki_page.update(content: 'Update') # rubocop:disable Rails/SaveBang
click_button('Save changes')
expect(page).to have_content('Someone edited the page the same time you did.')
end
it 'updates a page', :js do it 'updates a page', :js do
fill_in('Content', with: 'Updated Wiki Content') fill_in('Content', with: 'Updated Wiki Content')
click_on('Save changes') click_on('Save changes')
...@@ -145,6 +137,18 @@ RSpec.shared_examples 'User updates wiki page' do ...@@ -145,6 +137,18 @@ RSpec.shared_examples 'User updates wiki page' do
end end
it_behaves_like 'wiki file attachments' it_behaves_like 'wiki file attachments'
context 'when multiple people edit the page at the same time' do
it 'preserves user changes in the wiki editor', :js do
wiki_page.update(content: 'Some Other Updates') # rubocop:disable Rails/SaveBang
fill_in('Content', with: 'Updated Wiki Content')
click_on('Save changes')
expect(page).to have_content('Someone edited the page the same time you did.')
expect(find('textarea#wiki_content').value).to eq('Updated Wiki Content')
end
end
end end
context 'when the page is in a subdir', :js do context 'when the page is in a subdir', :js do
......
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