Commit 3967412f authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '39676-wiki-api-problems-on-update-parameters-and-500-error' into 'master'

Only require one parameter when updating a Wiki via the API

Closes #39676

See merge request gitlab-org/gitlab-ce!25191
parents bd17881b 5b29f066
---
title: 'API: Require only one parameter when updating a wiki'
merge_request: 25191
author: Robert Schilling
type: fixed
......@@ -11,9 +11,7 @@ module API
}
end
params :wiki_page_params do
requires :content, type: String, desc: 'Content of a wiki page'
requires :title, type: String, desc: 'Title of a wiki page'
params :common_wiki_page_params do
optional :format,
type: String,
values: ProjectWiki::MARKUPS.values.map(&:to_s),
......@@ -54,7 +52,9 @@ module API
success Entities::WikiPage
end
params do
use :wiki_page_params
requires :title, type: String, desc: 'Title of a wiki page'
requires :content, type: String, desc: 'Content of a wiki page'
use :common_wiki_page_params
end
post ':id/wikis' do
authorize! :create_wiki, user_project
......@@ -72,7 +72,10 @@ module API
success Entities::WikiPage
end
params do
use :wiki_page_params
optional :title, type: String, desc: 'Title of a wiki page'
optional :content, type: String, desc: 'Content of a wiki page'
use :common_wiki_page_params
at_least_one_of :content, :title, :format
end
put ':id/wikis/:slug' do
authorize! :create_wiki, user_project
......
......@@ -100,6 +100,8 @@ describe API::Wikis do
shared_examples_for 'updates wiki page' do
it 'updates the wiki page' do
put(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(4)
expect(json_response.keys).to match_array(expected_keys_with_content)
......@@ -107,6 +109,16 @@ describe API::Wikis do
expect(json_response['slug']).to eq(payload[:title].tr(' ', '-'))
expect(json_response['title']).to eq(payload[:title])
end
[:title, :content, :format].each do |part|
it "it updates with wiki with missing #{part}" do
payload.delete(part)
put(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(200)
end
end
end
shared_examples_for '403 Forbidden' do
......@@ -528,8 +540,6 @@ describe API::Wikis do
context 'when user is developer' do
before do
project.add_developer(user)
put(api(url, user), params: payload)
end
include_examples 'updates wiki page'
......@@ -537,6 +547,10 @@ describe API::Wikis do
context 'when page is not existing' do
let(:url) { "/projects/#{project.id}/wikis/unknown" }
before do
put(api(url, user), params: payload)
end
include_examples '404 Wiki Page Not Found'
end
end
......@@ -544,8 +558,6 @@ describe API::Wikis do
context 'when user is maintainer' do
before do
project.add_maintainer(user)
put(api(url, user), params: payload)
end
include_examples 'updates wiki page'
......@@ -553,6 +565,10 @@ describe API::Wikis do
context 'when page is not existing' do
let(:url) { "/projects/#{project.id}/wikis/unknown" }
before do
put(api(url, user), params: payload)
end
include_examples '404 Wiki Page Not Found'
end
end
......@@ -572,8 +588,6 @@ describe API::Wikis do
context 'when user is developer' do
before do
project.add_developer(user)
put(api(url, user), params: payload)
end
include_examples 'updates wiki page'
......@@ -581,6 +595,10 @@ describe API::Wikis do
context 'when page is not existing' do
let(:url) { "/projects/#{project.id}/wikis/unknown" }
before do
put(api(url, user), params: payload)
end
include_examples '404 Wiki Page Not Found'
end
end
......@@ -588,8 +606,6 @@ describe API::Wikis do
context 'when user is maintainer' do
before do
project.add_maintainer(user)
put(api(url, user), params: payload)
end
include_examples 'updates wiki page'
......@@ -597,6 +613,10 @@ describe API::Wikis do
context 'when page is not existing' do
let(:url) { "/projects/#{project.id}/wikis/unknown" }
before do
put(api(url, user), params: payload)
end
include_examples '404 Wiki Page Not Found'
end
end
......@@ -605,10 +625,6 @@ describe API::Wikis do
context 'when wiki belongs to a group project' do
let(:project) { create(:project, :wiki_repo, namespace: group) }
before do
put(api(url, user), params: payload)
end
include_examples 'updates wiki page'
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