Commit e29c9ba3 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch '217354-service-response-update' into 'master'

Use ServiceResponse in wiki update service

Closes #217354

See merge request gitlab-org/gitlab!39507
parents 875bbb8e bac60cfb
...@@ -93,9 +93,10 @@ module WikiActions ...@@ -93,9 +93,10 @@ module WikiActions
def update def update
return render('shared/wikis/empty') unless can?(current_user, :create_wiki, container) return render('shared/wikis/empty') unless can?(current_user, :create_wiki, container)
@page = WikiPages::UpdateService.new(container: container, current_user: current_user, params: wiki_params).execute(page) response = WikiPages::UpdateService.new(container: container, current_user: current_user, params: wiki_params).execute(page)
@page = response.payload[:page]
if page.valid? if response.success?
redirect_to( redirect_to(
wiki_page_path(wiki, page), wiki_page_path(wiki, page),
notice: _('Wiki was successfully updated.') notice: _('Wiki was successfully updated.')
......
...@@ -8,9 +8,13 @@ module WikiPages ...@@ -8,9 +8,13 @@ module WikiPages
if page.update(@params) if page.update(@params)
execute_hooks(page) execute_hooks(page)
ServiceResponse.success(payload: { page: page })
else
ServiceResponse.error(
message: _('Could not udpdate wiki page'),
payload: { page: page }
)
end end
page
end end
def usage_counter_action def usage_counter_action
......
...@@ -83,11 +83,12 @@ module API ...@@ -83,11 +83,12 @@ module API
put ':id/wikis/:slug' do put ':id/wikis/:slug' do
authorize! :create_wiki, container authorize! :create_wiki, container
page = WikiPages::UpdateService response = WikiPages::UpdateService
.new(container: container, current_user: current_user, params: params) .new(container: container, current_user: current_user, params: params)
.execute(wiki_page) .execute(wiki_page)
page = response.payload[:page]
if page.valid? if response.success?
present page, with: Entities::WikiPage present page, with: Entities::WikiPage
else else
render_validation_error!(page) render_validation_error!(page)
......
...@@ -7060,6 +7060,9 @@ msgstr "" ...@@ -7060,6 +7060,9 @@ msgstr ""
msgid "Could not save prometheus manual configuration" msgid "Could not save prometheus manual configuration"
msgstr "" msgstr ""
msgid "Could not udpdate wiki page"
msgstr ""
msgid "Could not update the LDAP settings" msgid "Could not update the LDAP settings"
msgstr "" msgstr ""
......
...@@ -19,8 +19,10 @@ RSpec.shared_examples 'WikiPages::UpdateService#execute' do |container_type| ...@@ -19,8 +19,10 @@ RSpec.shared_examples 'WikiPages::UpdateService#execute' do |container_type|
subject(:service) { described_class.new(container: container, current_user: user, params: opts) } subject(:service) { described_class.new(container: container, current_user: user, params: opts) }
it 'updates the wiki page' do it 'updates the wiki page' do
updated_page = service.execute(page) response = service.execute(page)
updated_page = response.payload[:page]
expect(response).to be_success
expect(updated_page).to be_valid expect(updated_page).to be_valid
expect(updated_page.message).to eq(opts[:message]) expect(updated_page.message).to eq(opts[:message])
expect(updated_page.content).to eq(opts[:content]) expect(updated_page.content).to eq(opts[:content])
...@@ -81,7 +83,11 @@ RSpec.shared_examples 'WikiPages::UpdateService#execute' do |container_type| ...@@ -81,7 +83,11 @@ RSpec.shared_examples 'WikiPages::UpdateService#execute' do |container_type|
end end
it 'reports the error' do it 'reports the error' do
expect(service.execute(page)).to be_invalid response = service.execute(page)
page = response.payload[:page]
expect(response).to be_error
expect(page).to be_invalid
.and have_attributes(errors: be_present) .and have_attributes(errors: be_present)
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