Commit 7d53dcbf authored by Markus Koller's avatar Markus Koller

Use correct upload endpoint for group wikis

This URL is passed on to the JS frontend which uses it to generate
upload requests.
parent 48a15e58
...@@ -69,7 +69,12 @@ module WikiHelper ...@@ -69,7 +69,12 @@ module WikiHelper
end end
def wiki_attachment_upload_url def wiki_attachment_upload_url
expose_url(api_v4_projects_wikis_attachments_path(id: @wiki.container.id)) case @wiki.container
when Project
expose_url(api_v4_projects_wikis_attachments_path(id: @wiki.container.id))
else
raise TypeError, "Unsupported wiki container #{@wiki.container.class}"
end
end end
def wiki_sort_controls(wiki, sort, direction) def wiki_sort_controls(wiki, sort, direction)
...@@ -147,3 +152,5 @@ module WikiHelper ...@@ -147,3 +152,5 @@ module WikiHelper
!container.has_confluence? !container.has_confluence?
end end
end end
WikiHelper.prepend_if_ee('EE::WikiHelper')
# frozen_string_literal: true
module EE
module WikiHelper
extend ::Gitlab::Utils::Override
override :wiki_attachment_upload_url
def wiki_attachment_upload_url
case @wiki.container
when Group
expose_url(api_v4_groups_wikis_attachments_path(id: @wiki.container.id))
else
super
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe WikiHelper do
describe '#wiki_attachment_upload_url' do
it 'returns the upload endpoint for group wikis' do
@wiki = build_stubbed(:group_wiki)
expect(helper.wiki_attachment_upload_url).to end_with("/api/v4/groups/#{@wiki.group.id}/wikis/attachments")
end
end
end
...@@ -53,6 +53,22 @@ RSpec.describe WikiHelper do ...@@ -53,6 +53,22 @@ RSpec.describe WikiHelper do
end end
end end
describe '#wiki_attachment_upload_url' do
it 'returns the upload endpoint for project wikis' do
@wiki = build_stubbed(:project_wiki)
expect(helper.wiki_attachment_upload_url).to end_with("/api/v4/projects/#{@wiki.project.id}/wikis/attachments")
end
it 'raises an exception for unsupported wiki containers' do
@wiki = Wiki.new(User.new)
expect do
helper.wiki_attachment_upload_url
end.to raise_error(TypeError)
end
end
describe '#wiki_sort_controls' do describe '#wiki_sort_controls' do
let(:wiki) { create(:project_wiki) } let(:wiki) { create(:project_wiki) }
let(:wiki_link) { helper.wiki_sort_controls(wiki, sort, direction) } let(:wiki_link) { helper.wiki_sort_controls(wiki, sort, direction) }
......
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