Commit 9ca898c4 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'rd-api-request-to-edit-wiki-page-fails-when-project-belongs-to-group' into 'master'

Fix API endpoints to edit wiki pages where project belongs to a group

Closes #40453

See merge request gitlab-org/gitlab-ce!16170
parents fb583c4b cf8f0963
---
title: Fix API endpoints to edit wiki pages where project belongs to a group
merge_request: 16170
author:
type: fixed
...@@ -69,7 +69,7 @@ module API ...@@ -69,7 +69,7 @@ module API
end end
def wiki_page def wiki_page
page = user_project.wiki.find_page(params[:slug]) page = ProjectWiki.new(user_project, current_user).find_page(params[:slug])
page || not_found!('Wiki Page') page || not_found!('Wiki Page')
end end
......
...@@ -12,6 +12,8 @@ require 'spec_helper' ...@@ -12,6 +12,8 @@ require 'spec_helper'
describe API::Wikis do describe API::Wikis do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:group) { create(:group).tap { |g| g.add_owner(user) } }
let(:project_wiki) { create(:project_wiki, project: project, user: user) }
let(:payload) { { content: 'content', format: 'rdoc', title: 'title' } } let(:payload) { { content: 'content', format: 'rdoc', title: 'title' } }
let(:expected_keys_with_content) { %w(content format slug title) } let(:expected_keys_with_content) { %w(content format slug title) }
let(:expected_keys_without_content) { %w(format slug title) } let(:expected_keys_without_content) { %w(format slug title) }
...@@ -19,8 +21,8 @@ describe API::Wikis do ...@@ -19,8 +21,8 @@ describe API::Wikis do
shared_examples_for 'returns list of wiki pages' do shared_examples_for 'returns list of wiki pages' do
context 'when wiki has pages' do context 'when wiki has pages' do
let!(:pages) do let!(:pages) do
[create(:wiki_page, wiki: project.wiki, attrs: { title: 'page1', content: 'content of page1' }), [create(:wiki_page, wiki: project_wiki, attrs: { title: 'page1', content: 'content of page1' }),
create(:wiki_page, wiki: project.wiki, attrs: { title: 'page2', content: 'content of page2' })] create(:wiki_page, wiki: project_wiki, attrs: { title: 'page2', content: 'content of page2' })]
end end
it 'returns the list of wiki pages without content' do it 'returns the list of wiki pages without content' do
...@@ -445,7 +447,7 @@ describe API::Wikis do ...@@ -445,7 +447,7 @@ describe API::Wikis do
end end
describe 'PUT /projects/:id/wikis/:slug' do describe 'PUT /projects/:id/wikis/:slug' do
let(:page) { create(:wiki_page, wiki: project.wiki) } let(:page) { create(:wiki_page, wiki: project_wiki) }
let(:payload) { { title: 'new title', content: 'new content' } } let(:payload) { { title: 'new title', content: 'new content' } }
let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" } let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" }
...@@ -568,10 +570,20 @@ describe API::Wikis do ...@@ -568,10 +570,20 @@ describe API::Wikis do
end end
end end
end end
context 'when wiki belongs to a group project' do
let(:project) { create(:project, namespace: group) }
before do
put(api(url, user), payload)
end
include_examples 'updates wiki page'
end
end end
describe 'DELETE /projects/:id/wikis/:slug' do describe 'DELETE /projects/:id/wikis/:slug' do
let(:page) { create(:wiki_page, wiki: project.wiki) } let(:page) { create(:wiki_page, wiki: project_wiki) }
let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" } let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" }
context 'when wiki is disabled' do context 'when wiki is disabled' do
...@@ -675,5 +687,15 @@ describe API::Wikis do ...@@ -675,5 +687,15 @@ describe API::Wikis do
end end
end end
end end
context 'when wiki belongs to a group project' do
let(:project) { create(:project, namespace: group) }
before do
delete(api(url, user))
end
include_examples '204 No Content'
end
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