Commit ef62efe7 authored by Stan Hu's avatar Stan Hu

Merge branch '208762-group-wiki-upload-attachments' into 'master'

Use correct upload endpoint for group wikis

See merge request gitlab-org/gitlab!40985
parents 6a734725 7d53dcbf
......@@ -69,7 +69,12 @@ module WikiHelper
end
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
def wiki_sort_controls(wiki, sort, direction)
......@@ -147,3 +152,5 @@ module WikiHelper
!container.has_confluence?
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
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
let(:wiki) { create(:project_wiki) }
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