Commit 6c7221b6 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'patch/geo-display-attachments' into 'master'

GitLab Geo: Display Attachments from Primary node

GitLab Geo (#76) does not store attachments user uploaded files on secondary nodes yet.
This is a workaround to get images/attachments link in a working state, even when the files are not
in that node.

Banzai will build URLs using Geo primary URL for relative URIs expansion.

Fixes #414

See merge request !302
parents 9310e6ea ef79cf7a
......@@ -32,7 +32,11 @@ module Banzai
end
def build_url(uri)
File.join(Gitlab.config.gitlab.url, context[:project].path_with_namespace, uri)
if Gitlab::Geo.secondary?
File.join(Gitlab::Geo.primary_node.url, context[:project].path_with_namespace, uri)
else
File.join(Gitlab.config.gitlab.url, context[:project].path_with_namespace, uri)
end
end
# Ensure that a :project key exists in context
......
......@@ -69,5 +69,31 @@ describe Banzai::Filter::UploadLinkFilter, lib: true do
doc = filter(image(escaped))
expect(doc.at_css('img')['src']).to match "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/%ED%95%9C%EA%B8%80.png"
end
context 'in a geo secondary node' do
let(:geo_url) { 'http://geo.example.com' }
before(:each) do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive_message_chain(:primary_node, :url) { geo_url }
end
it 'rebuilds relative URL for a link' do
doc = filter(link('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))
expect(doc.at_css('a')['href']).
to eq "#{geo_url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
end
it 'rebuilds relative URL for an image' do
doc = filter(link('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))
expect(doc.at_css('a')['href']).
to eq "#{geo_url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
end
it 'does not modify absolute URL' do
doc = filter(link('http://example.com'))
expect(doc.at_css('a')['href']).to eq 'http://example.com'
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