Commit bac60cfb authored by ddash2's avatar ddash2

Update service uses ServiceResponse

parent b70d1130
......@@ -93,9 +93,10 @@ module WikiActions
def update
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(
wiki_page_path(wiki, page),
notice: _('Wiki was successfully updated.')
......
......@@ -8,9 +8,13 @@ module WikiPages
if page.update(@params)
execute_hooks(page)
ServiceResponse.success(payload: { page: page })
else
ServiceResponse.error(
message: _('Could not udpdate wiki page'),
payload: { page: page }
)
end
page
end
def usage_counter_action
......
......@@ -83,11 +83,12 @@ module API
put ':id/wikis/:slug' do
authorize! :create_wiki, container
page = WikiPages::UpdateService
response = WikiPages::UpdateService
.new(container: container, current_user: current_user, params: params)
.execute(wiki_page)
page = response.payload[:page]
if page.valid?
if response.success?
present page, with: Entities::WikiPage
else
render_validation_error!(page)
......
......@@ -7060,6 +7060,9 @@ msgstr ""
msgid "Could not save prometheus manual configuration"
msgstr ""
msgid "Could not udpdate wiki page"
msgstr ""
msgid "Could not update the LDAP settings"
msgstr ""
......
......@@ -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) }
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.message).to eq(opts[:message])
expect(updated_page.content).to eq(opts[:content])
......@@ -81,7 +83,11 @@ RSpec.shared_examples 'WikiPages::UpdateService#execute' do |container_type|
end
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)
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