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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
180de2d2
Commit
180de2d2
authored
Aug 07, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure uploads for personal snippets are correctly rendered
parent
b8ae1539
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
22 additions
and
22 deletions
+22
-22
app/uploaders/personal_file_uploader.rb
app/uploaders/personal_file_uploader.rb
+1
-1
config/routes/uploads.rb
config/routes/uploads.rb
+2
-2
spec/controllers/snippets_controller_spec.rb
spec/controllers/snippets_controller_spec.rb
+4
-4
spec/controllers/uploads_controller_spec.rb
spec/controllers/uploads_controller_spec.rb
+2
-2
spec/features/snippets/user_creates_snippet_spec.rb
spec/features/snippets/user_creates_snippet_spec.rb
+3
-3
spec/features/snippets/user_edits_snippet_spec.rb
spec/features/snippets/user_edits_snippet_spec.rb
+1
-1
spec/uploaders/file_mover_spec.rb
spec/uploaders/file_mover_spec.rb
+7
-7
spec/uploaders/personal_file_uploader_spec.rb
spec/uploaders/personal_file_uploader_spec.rb
+2
-2
No files found.
app/uploaders/personal_file_uploader.rb
View file @
180de2d2
...
@@ -4,7 +4,7 @@ class PersonalFileUploader < FileUploader
...
@@ -4,7 +4,7 @@ class PersonalFileUploader < FileUploader
end
end
def
self
.
base_dir
def
self
.
base_dir
File
.
join
(
root_dir
,
'system'
)
File
.
join
(
root_dir
,
'
-'
,
'
system'
)
end
end
private
private
...
...
config/routes/uploads.rb
View file @
180de2d2
...
@@ -5,12 +5,12 @@ scope path: :uploads do
...
@@ -5,12 +5,12 @@ scope path: :uploads do
constraints:
{
model:
/note|user|group|project/
,
mounted_as:
/avatar|attachment/
,
filename:
/[^\/]+/
}
constraints:
{
model:
/note|user|group|project/
,
mounted_as:
/avatar|attachment/
,
filename:
/[^\/]+/
}
# show uploads for models, snippets (notes) available for now
# show uploads for models, snippets (notes) available for now
get
'system/:model/:id/:secret/:filename'
,
get
'
-/
system/:model/:id/:secret/:filename'
,
to:
'uploads#show'
,
to:
'uploads#show'
,
constraints:
{
model:
/personal_snippet/
,
id:
/\d+/
,
filename:
/[^\/]+/
}
constraints:
{
model:
/personal_snippet/
,
id:
/\d+/
,
filename:
/[^\/]+/
}
# show temporary uploads
# show temporary uploads
get
'system/temp/:secret/:filename'
,
get
'
-/
system/temp/:secret/:filename'
,
to:
'uploads#show'
,
to:
'uploads#show'
,
constraints:
{
filename:
/[^\/]+/
}
constraints:
{
filename:
/[^\/]+/
}
...
...
spec/controllers/snippets_controller_spec.rb
View file @
180de2d2
...
@@ -186,8 +186,8 @@ describe SnippetsController do
...
@@ -186,8 +186,8 @@ describe SnippetsController do
end
end
context
'when the snippet description contains a file'
do
context
'when the snippet description contains a file'
do
let
(
:picture_file
)
{
'/system/temp/secret56/picture.jpg'
}
let
(
:picture_file
)
{
'/
-/
system/temp/secret56/picture.jpg'
}
let
(
:text_file
)
{
'/system/temp/secret78/text.txt'
}
let
(
:text_file
)
{
'/
-/
system/temp/secret78/text.txt'
}
let
(
:description
)
do
let
(
:description
)
do
"Description with picture: ![picture](/uploads
#{
picture_file
}
) and "
\
"Description with picture: ![picture](/uploads
#{
picture_file
}
) and "
\
"text: [text.txt](/uploads
#{
text_file
}
)"
"text: [text.txt](/uploads
#{
text_file
}
)"
...
@@ -208,8 +208,8 @@ describe SnippetsController do
...
@@ -208,8 +208,8 @@ describe SnippetsController do
snippet
=
subject
snippet
=
subject
expected_description
=
"Description with picture: "
\
expected_description
=
"Description with picture: "
\
"![picture](/uploads/system/personal_snippet/
#{
snippet
.
id
}
/secret56/picture.jpg) and "
\
"![picture](/uploads/
-/
system/personal_snippet/
#{
snippet
.
id
}
/secret56/picture.jpg) and "
\
"text: [text.txt](/uploads/system/personal_snippet/
#{
snippet
.
id
}
/secret78/text.txt)"
"text: [text.txt](/uploads/
-/
system/personal_snippet/
#{
snippet
.
id
}
/secret78/text.txt)"
expect
(
snippet
.
description
).
to
eq
(
expected_description
)
expect
(
snippet
.
description
).
to
eq
(
expected_description
)
end
end
...
...
spec/controllers/uploads_controller_spec.rb
View file @
180de2d2
...
@@ -102,7 +102,7 @@ describe UploadsController do
...
@@ -102,7 +102,7 @@ describe UploadsController do
subject
subject
expect
(
response
.
body
).
to
match
'\"alt\":\"rails_sample\"'
expect
(
response
.
body
).
to
match
'\"alt\":\"rails_sample\"'
expect
(
response
.
body
).
to
match
"
\"
url
\"
:
\"
/uploads/system/temp"
expect
(
response
.
body
).
to
match
"
\"
url
\"
:
\"
/uploads/
-/
system/temp"
end
end
it
'does not create an Upload record'
do
it
'does not create an Upload record'
do
...
@@ -119,7 +119,7 @@ describe UploadsController do
...
@@ -119,7 +119,7 @@ describe UploadsController do
subject
subject
expect
(
response
.
body
).
to
match
'\"alt\":\"doc_sample.txt\"'
expect
(
response
.
body
).
to
match
'\"alt\":\"doc_sample.txt\"'
expect
(
response
.
body
).
to
match
"
\"
url
\"
:
\"
/uploads/system/temp"
expect
(
response
.
body
).
to
match
"
\"
url
\"
:
\"
/uploads/
-/
system/temp"
end
end
it
'does not create an Upload record'
do
it
'does not create an Upload record'
do
...
...
spec/features/snippets/user_creates_snippet_spec.rb
View file @
180de2d2
...
@@ -41,7 +41,7 @@ feature 'User creates snippet', :js do
...
@@ -41,7 +41,7 @@ feature 'User creates snippet', :js do
expect
(
page
).
to
have_content
(
'My Snippet'
)
expect
(
page
).
to
have_content
(
'My Snippet'
)
link
=
find
(
'a.no-attachment-icon img[alt="banana_sample"]'
)[
'src'
]
link
=
find
(
'a.no-attachment-icon img[alt="banana_sample"]'
)[
'src'
]
expect
(
link
).
to
match
(
%r{/uploads/system/temp/
\h
{32}/banana_sample
\.
gif
\z
}
)
expect
(
link
).
to
match
(
%r{/uploads/
-/
system/temp/
\h
{32}/banana_sample
\.
gif
\z
}
)
visit
(
link
)
visit
(
link
)
expect
(
page
.
status_code
).
to
eq
(
200
)
expect
(
page
.
status_code
).
to
eq
(
200
)
...
@@ -59,7 +59,7 @@ feature 'User creates snippet', :js do
...
@@ -59,7 +59,7 @@ feature 'User creates snippet', :js do
wait_for_requests
wait_for_requests
link
=
find
(
'a.no-attachment-icon img[alt="banana_sample"]'
)[
'src'
]
link
=
find
(
'a.no-attachment-icon img[alt="banana_sample"]'
)[
'src'
]
expect
(
link
).
to
match
(
%r{/uploads/system/personal_snippet/
#{
Snippet
.
last
.
id
}
/
\h
{32}/banana_sample
\.
gif
\z
}
)
expect
(
link
).
to
match
(
%r{/uploads/
-/
system/personal_snippet/
#{
Snippet
.
last
.
id
}
/
\h
{32}/banana_sample
\.
gif
\z
}
)
visit
(
link
)
visit
(
link
)
expect
(
page
.
status_code
).
to
eq
(
200
)
expect
(
page
.
status_code
).
to
eq
(
200
)
...
@@ -84,7 +84,7 @@ feature 'User creates snippet', :js do
...
@@ -84,7 +84,7 @@ feature 'User creates snippet', :js do
end
end
expect
(
page
).
to
have_content
(
'Hello World!'
)
expect
(
page
).
to
have_content
(
'Hello World!'
)
link
=
find
(
'a.no-attachment-icon img[alt="banana_sample"]'
)[
'src'
]
link
=
find
(
'a.no-attachment-icon img[alt="banana_sample"]'
)[
'src'
]
expect
(
link
).
to
match
(
%r{/uploads/system/personal_snippet/
#{
Snippet
.
last
.
id
}
/
\h
{32}/banana_sample
\.
gif
\z
}
)
expect
(
link
).
to
match
(
%r{/uploads/
-/
system/personal_snippet/
#{
Snippet
.
last
.
id
}
/
\h
{32}/banana_sample
\.
gif
\z
}
)
visit
(
link
)
visit
(
link
)
expect
(
page
.
status_code
).
to
eq
(
200
)
expect
(
page
.
status_code
).
to
eq
(
200
)
...
...
spec/features/snippets/user_edits_snippet_spec.rb
View file @
180de2d2
...
@@ -33,7 +33,7 @@ feature 'User edits snippet', :js do
...
@@ -33,7 +33,7 @@ feature 'User edits snippet', :js do
wait_for_requests
wait_for_requests
link
=
find
(
'a.no-attachment-icon img[alt="banana_sample"]'
)[
'src'
]
link
=
find
(
'a.no-attachment-icon img[alt="banana_sample"]'
)[
'src'
]
expect
(
link
).
to
match
(
%r{/uploads/system/personal_snippet/
#{
snippet
.
id
}
/
\h
{32}/banana_sample
\.
gif
\z
}
)
expect
(
link
).
to
match
(
%r{/uploads/
-/
system/personal_snippet/
#{
snippet
.
id
}
/
\h
{32}/banana_sample
\.
gif
\z
}
)
end
end
it
'updates the snippet to make it internal'
do
it
'updates the snippet to make it internal'
do
...
...
spec/uploaders/file_mover_spec.rb
View file @
180de2d2
...
@@ -4,11 +4,11 @@ describe FileMover do
...
@@ -4,11 +4,11 @@ describe FileMover do
let
(
:filename
)
{
'banana_sample.gif'
}
let
(
:filename
)
{
'banana_sample.gif'
}
let
(
:file
)
{
fixture_file_upload
(
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
filename
))
}
let
(
:file
)
{
fixture_file_upload
(
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
filename
))
}
let
(
:temp_description
)
do
let
(
:temp_description
)
do
'test ![banana_sample](/uploads/system/temp/secret55/banana_sample.gif) same ![banana_sample]'
\
'test ![banana_sample](/uploads/
-/
system/temp/secret55/banana_sample.gif) same ![banana_sample]'
\
'(/uploads/system/temp/secret55/banana_sample.gif)'
'(/uploads/
-/
system/temp/secret55/banana_sample.gif)'
end
end
let
(
:temp_file_path
)
{
File
.
join
(
'secret55'
,
filename
).
to_s
}
let
(
:temp_file_path
)
{
File
.
join
(
'secret55'
,
filename
).
to_s
}
let
(
:file_path
)
{
File
.
join
(
'uploads'
,
'system'
,
'personal_snippet'
,
snippet
.
id
.
to_s
,
'secret55'
,
filename
).
to_s
}
let
(
:file_path
)
{
File
.
join
(
'uploads'
,
'
-'
,
'
system'
,
'personal_snippet'
,
snippet
.
id
.
to_s
,
'secret55'
,
filename
).
to_s
}
let
(
:snippet
)
{
create
(
:personal_snippet
,
description:
temp_description
)
}
let
(
:snippet
)
{
create
(
:personal_snippet
,
description:
temp_description
)
}
...
@@ -28,8 +28,8 @@ describe FileMover do
...
@@ -28,8 +28,8 @@ describe FileMover do
expect
(
snippet
.
reload
.
description
)
expect
(
snippet
.
reload
.
description
)
.
to
eq
(
.
to
eq
(
"test ![banana_sample](/uploads/system/personal_snippet/
#{
snippet
.
id
}
/secret55/banana_sample.gif)"
\
"test ![banana_sample](/uploads/
-/
system/personal_snippet/
#{
snippet
.
id
}
/secret55/banana_sample.gif)"
\
" same ![banana_sample](/uploads/system/personal_snippet/
#{
snippet
.
id
}
/secret55/banana_sample.gif)"
" same ![banana_sample](/uploads/
-/
system/personal_snippet/
#{
snippet
.
id
}
/secret55/banana_sample.gif)"
)
)
end
end
...
@@ -50,8 +50,8 @@ describe FileMover do
...
@@ -50,8 +50,8 @@ describe FileMover do
expect
(
snippet
.
reload
.
description
)
expect
(
snippet
.
reload
.
description
)
.
to
eq
(
.
to
eq
(
"test ![banana_sample](/uploads/system/temp/secret55/banana_sample.gif)"
\
"test ![banana_sample](/uploads/
-/
system/temp/secret55/banana_sample.gif)"
\
" same ![banana_sample](/uploads/system/temp/secret55/banana_sample.gif)"
" same ![banana_sample](/uploads/
-/
system/temp/secret55/banana_sample.gif)"
)
)
end
end
...
...
spec/uploaders/personal_file_uploader_spec.rb
View file @
180de2d2
...
@@ -10,7 +10,7 @@ describe PersonalFileUploader do
...
@@ -10,7 +10,7 @@ describe PersonalFileUploader do
dynamic_segment
=
"personal_snippet/
#{
snippet
.
id
}
"
dynamic_segment
=
"personal_snippet/
#{
snippet
.
id
}
"
expect
(
described_class
.
absolute_path
(
upload
)).
to
end_with
(
"/system/
#{
dynamic_segment
}
/secret/foo.jpg"
)
expect
(
described_class
.
absolute_path
(
upload
)).
to
end_with
(
"/
-/
system/
#{
dynamic_segment
}
/secret/foo.jpg"
)
end
end
end
end
...
@@ -19,7 +19,7 @@ describe PersonalFileUploader do
...
@@ -19,7 +19,7 @@ describe PersonalFileUploader do
uploader
=
described_class
.
new
(
snippet
,
'secret'
)
uploader
=
described_class
.
new
(
snippet
,
'secret'
)
allow
(
uploader
).
to
receive
(
:file
).
and_return
(
double
(
extension:
'txt'
,
filename:
'file_name'
))
allow
(
uploader
).
to
receive
(
:file
).
and_return
(
double
(
extension:
'txt'
,
filename:
'file_name'
))
expected_url
=
"/uploads/system/personal_snippet/
#{
snippet
.
id
}
/secret/file_name"
expected_url
=
"/uploads/
-/
system/personal_snippet/
#{
snippet
.
id
}
/secret/file_name"
expect
(
uploader
.
to_h
).
to
eq
(
expect
(
uploader
.
to_h
).
to
eq
(
alt:
'file_name'
,
alt:
'file_name'
,
...
...
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