Return snippet binary blob content in GraphQL

Remove the countermeasure that prevented returning
the content.
parent 603bce88
......@@ -4,7 +4,6 @@ class SnippetBlobPresenter < BlobPresenter
include GitlabRoutingHelper
def rich_data
return if blob.binary?
return unless blob.rich_viewer
render_rich_partial
......@@ -17,9 +16,11 @@ class SnippetBlobPresenter < BlobPresenter
end
def raw_path
return gitlab_raw_snippet_blob_path(snippet, blob.path) if snippet_multiple_files?
snippet_blob_raw_route(only_path: true)
end
gitlab_raw_snippet_path(snippet)
def raw_url
snippet_blob_raw_route
end
private
......@@ -38,7 +39,7 @@ class SnippetBlobPresenter < BlobPresenter
def render_rich_partial
renderer.render("projects/blob/viewers/_#{blob.rich_viewer.partial_name}",
locals: { viewer: blob.rich_viewer, blob: blob, blob_raw_path: raw_path },
locals: { viewer: blob.rich_viewer, blob: blob, blob_raw_path: raw_path, blob_raw_url: raw_url },
layout: false)
end
......@@ -49,4 +50,10 @@ class SnippetBlobPresenter < BlobPresenter
ApplicationController.renderer.new('warden' => proxy)
end
def snippet_blob_raw_route(only_path: false)
return gitlab_raw_snippet_blob_url(snippet, blob.path, only_path: only_path) if snippet_multiple_files?
gitlab_raw_snippet_url(snippet, only_path: only_path)
end
end
---
title: Return snippet binary blob content in GraphQL
merge_request: 39583
author:
type: changed
......@@ -224,21 +224,10 @@ RSpec.describe GitlabRoutingHelper do
subject { gitlab_raw_snippet_blob_url(snippet, blob.path, ref, args) }
context 'for a PersonalSnippet' do
let(:snippet) { personal_snippet }
it { expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}") }
end
context 'for a ProjectSnippet' do
let(:snippet) { project_snippet }
it { expect(subject).to eq("http://test.host/#{snippet.project.full_path}/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}") }
end
it_behaves_like 'snippet blob raw url'
context 'when an argument is set' do
let(:args) { { inline: true } }
let(:snippet) { personal_snippet }
it { expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}?inline=true") }
......
......@@ -13,13 +13,14 @@ RSpec.describe SnippetBlobPresenter do
subject { described_class.new(snippet.blob).rich_data }
context 'with PersonalSnippet' do
let(:raw_url) { "http://127.0.0.1:3000/-/snippets/#{snippet.id}/raw" }
let(:snippet) { build(:personal_snippet) }
let(:snippet) { create(:personal_snippet, :repository) }
it 'returns nil when the snippet blob is binary' do
allow(snippet.blob).to receive(:binary?).and_return(true)
context 'when blob is binary' do
it 'returns the HTML associated with the binary' do
allow(snippet).to receive(:blob).and_return(snippet.repository.blob_at('master', 'files/images/logo-black.png'))
expect(subject).to be_nil
expect(subject).to include('file-content image_file')
end
end
context 'with markdown format' do
......@@ -108,7 +109,7 @@ RSpec.describe SnippetBlobPresenter do
end
end
describe '#raw_path' do
describe 'route helpers' do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:personal_snippet) { create(:personal_snippet, :repository, author: user) }
......@@ -118,6 +119,7 @@ RSpec.describe SnippetBlobPresenter do
project.add_developer(user)
end
describe '#raw_path' do
subject { described_class.new(snippet.blobs.first, current_user: user).raw_path }
it_behaves_like 'snippet blob raw path'
......@@ -144,4 +146,37 @@ RSpec.describe SnippetBlobPresenter do
end
end
end
describe '#raw_url' do
subject { described_class.new(snippet.blobs.first, current_user: user).raw_url }
before do
stub_default_url_options(host: 'test.host')
end
it_behaves_like 'snippet blob raw url'
context 'with snippet_multiple_files feature disabled' do
before do
stub_feature_flags(snippet_multiple_files: false)
end
context 'with ProjectSnippet' do
let(:snippet) { project_snippet }
it 'returns the raw project snippet url' do
expect(subject).to eq("http://test.host/#{project_snippet.project.full_path}/-/snippets/#{project_snippet.id}/raw")
end
end
context 'with PersonalSnippet' do
let(:snippet) { personal_snippet }
it 'returns the raw personal snippet url' do
expect(subject).to eq("http://test.host/-/snippets/#{personal_snippet.id}/raw")
end
end
end
end
end
end
......@@ -22,3 +22,24 @@ RSpec.shared_examples 'snippet blob raw path' do
end
end
end
RSpec.shared_examples 'snippet blob raw url' do
let(:blob) { snippet.blobs.first }
let(:ref) { blob.repository.root_ref }
context 'for PersonalSnippets' do
let(:snippet) { personal_snippet }
it 'returns the raw personal snippet blob url' do
expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}")
end
end
context 'for ProjectSnippets' do
let(:snippet) { project_snippet }
it 'returns the raw project snippet blob url' do
expect(subject).to eq("http://test.host/#{snippet.project.full_path}/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}")
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