Commit f5fb758b authored by Robert Speicher's avatar Robert Speicher

Merge branch '200002-changes-will-be-lost-if-multiple-people-edit-a-wiki-page' into 'master'

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

See merge request gitlab-org/gitlab!61120
parents 91d1c713 744ae80c
......@@ -115,9 +115,6 @@ module WikiActions
@error = response.message
render 'shared/wikis/edit'
end
rescue WikiPage::PageChangedError, WikiPage::PageRenameError => e
@error = e.message
render 'shared/wikis/edit'
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
......
......@@ -2,6 +2,8 @@
module WikiPages
class UpdateService < WikiPages::BaseService
UpdateError = Class.new(StandardError)
def execute(page)
# this class is not thread safe!
@old_slug = page.slug
......@@ -10,12 +12,16 @@ module WikiPages
execute_hooks(page)
ServiceResponse.success(payload: { page: page })
else
raise UpdateError, s_('Could not update wiki page')
end
rescue UpdateError, WikiPage::PageChangedError, WikiPage::PageRenameError => e
page.update_attributes(@params) # rubocop:disable Rails/ActiveRecordAliases
ServiceResponse.error(
message: _('Could not update wiki page'),
message: e.message,
payload: { page: page }
)
end
end
def usage_counter_action
:update
......
---
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
expect(page).to have_selector('.atwho-view')
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
fill_in('Content', with: 'Updated Wiki Content')
click_on('Save changes')
......@@ -145,6 +137,18 @@ RSpec.shared_examples 'User updates wiki page' do
end
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
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