Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b87e1e11
Commit
b87e1e11
authored
Aug 17, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return snippet binary blob content in GraphQL
Remove the countermeasure that prevented returning the content.
parent
603bce88
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
35 deletions
+92
-35
app/presenters/snippet_blob_presenter.rb
app/presenters/snippet_blob_presenter.rb
+11
-4
changelogs/unreleased/237864-fj-return-snippet-binary-blob-content.yml
...released/237864-fj-return-snippet-binary-blob-content.yml
+5
-0
spec/helpers/gitlab_routing_helper_spec.rb
spec/helpers/gitlab_routing_helper_spec.rb
+1
-12
spec/presenters/snippet_blob_presenter_spec.rb
spec/presenters/snippet_blob_presenter_spec.rb
+54
-19
spec/support/shared_examples/snippet_blob_shared_examples.rb
spec/support/shared_examples/snippet_blob_shared_examples.rb
+21
-0
No files found.
app/presenters/snippet_blob_presenter.rb
View file @
b87e1e11
...
@@ -4,7 +4,6 @@ class SnippetBlobPresenter < BlobPresenter
...
@@ -4,7 +4,6 @@ class SnippetBlobPresenter < BlobPresenter
include
GitlabRoutingHelper
include
GitlabRoutingHelper
def
rich_data
def
rich_data
return
if
blob
.
binary?
return
unless
blob
.
rich_viewer
return
unless
blob
.
rich_viewer
render_rich_partial
render_rich_partial
...
@@ -17,9 +16,11 @@ class SnippetBlobPresenter < BlobPresenter
...
@@ -17,9 +16,11 @@ class SnippetBlobPresenter < BlobPresenter
end
end
def
raw_path
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
end
private
private
...
@@ -38,7 +39,7 @@ class SnippetBlobPresenter < BlobPresenter
...
@@ -38,7 +39,7 @@ class SnippetBlobPresenter < BlobPresenter
def
render_rich_partial
def
render_rich_partial
renderer
.
render
(
"projects/blob/viewers/_
#{
blob
.
rich_viewer
.
partial_name
}
"
,
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
)
layout:
false
)
end
end
...
@@ -49,4 +50,10 @@ class SnippetBlobPresenter < BlobPresenter
...
@@ -49,4 +50,10 @@ class SnippetBlobPresenter < BlobPresenter
ApplicationController
.
renderer
.
new
(
'warden'
=>
proxy
)
ApplicationController
.
renderer
.
new
(
'warden'
=>
proxy
)
end
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
end
changelogs/unreleased/237864-fj-return-snippet-binary-blob-content.yml
0 → 100644
View file @
b87e1e11
---
title
:
Return snippet binary blob content in GraphQL
merge_request
:
39583
author
:
type
:
changed
spec/helpers/gitlab_routing_helper_spec.rb
View file @
b87e1e11
...
@@ -224,21 +224,10 @@ RSpec.describe GitlabRoutingHelper do
...
@@ -224,21 +224,10 @@ RSpec.describe GitlabRoutingHelper do
subject
{
gitlab_raw_snippet_blob_url
(
snippet
,
blob
.
path
,
ref
,
args
)
}
subject
{
gitlab_raw_snippet_blob_url
(
snippet
,
blob
.
path
,
ref
,
args
)
}
context
'for a PersonalSnippet'
do
it_behaves_like
'snippet blob raw url'
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
context
'when an argument is set'
do
context
'when an argument is set'
do
let
(
:args
)
{
{
inline:
true
}
}
let
(
:args
)
{
{
inline:
true
}
}
let
(
:snippet
)
{
personal_snippet
}
let
(
:snippet
)
{
personal_snippet
}
it
{
expect
(
subject
).
to
eq
(
"http://test.host/-/snippets/
#{
snippet
.
id
}
/raw/
#{
ref
}
/
#{
blob
.
path
}
?inline=true"
)
}
it
{
expect
(
subject
).
to
eq
(
"http://test.host/-/snippets/
#{
snippet
.
id
}
/raw/
#{
ref
}
/
#{
blob
.
path
}
?inline=true"
)
}
...
...
spec/presenters/snippet_blob_presenter_spec.rb
View file @
b87e1e11
...
@@ -13,13 +13,14 @@ RSpec.describe SnippetBlobPresenter do
...
@@ -13,13 +13,14 @@ RSpec.describe SnippetBlobPresenter do
subject
{
described_class
.
new
(
snippet
.
blob
).
rich_data
}
subject
{
described_class
.
new
(
snippet
.
blob
).
rich_data
}
context
'with PersonalSnippet'
do
context
'with PersonalSnippet'
do
let
(
:raw_url
)
{
"http://127.0.0.1:3000/-/snippets/
#{
snippet
.
id
}
/raw"
}
let
(
:snippet
)
{
create
(
:personal_snippet
,
:repository
)
}
let
(
:snippet
)
{
build
(
:personal_snippet
)
}
it
'returns nil when the snippet blob is binary'
do
context
'when blob is binary'
do
allow
(
snippet
.
blob
).
to
receive
(
:binary?
).
and_return
(
true
)
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
end
context
'with markdown format'
do
context
'with markdown format'
do
...
@@ -108,7 +109,7 @@ RSpec.describe SnippetBlobPresenter do
...
@@ -108,7 +109,7 @@ RSpec.describe SnippetBlobPresenter do
end
end
end
end
describe
'
#raw_path
'
do
describe
'
route helpers
'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:personal_snippet
)
{
create
(
:personal_snippet
,
:repository
,
author:
user
)
}
let_it_be
(
:personal_snippet
)
{
create
(
:personal_snippet
,
:repository
,
author:
user
)
}
...
@@ -118,6 +119,7 @@ RSpec.describe SnippetBlobPresenter do
...
@@ -118,6 +119,7 @@ RSpec.describe SnippetBlobPresenter do
project
.
add_developer
(
user
)
project
.
add_developer
(
user
)
end
end
describe
'#raw_path'
do
subject
{
described_class
.
new
(
snippet
.
blobs
.
first
,
current_user:
user
).
raw_path
}
subject
{
described_class
.
new
(
snippet
.
blobs
.
first
,
current_user:
user
).
raw_path
}
it_behaves_like
'snippet blob raw path'
it_behaves_like
'snippet blob raw path'
...
@@ -144,4 +146,37 @@ RSpec.describe SnippetBlobPresenter do
...
@@ -144,4 +146,37 @@ RSpec.describe SnippetBlobPresenter do
end
end
end
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
end
spec/support/shared_examples/snippet_blob_shared_examples.rb
View file @
b87e1e11
...
@@ -22,3 +22,24 @@ RSpec.shared_examples 'snippet blob raw path' do
...
@@ -22,3 +22,24 @@ RSpec.shared_examples 'snippet blob raw path' do
end
end
end
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment