Commit 5b29f066 authored by Robert Schilling's avatar Robert Schilling Committed by Rémy Coutable

Only require one parameter when updating a Wiki via the API

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