BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
3e1ac95b
Commit
3e1ac95b
authored
Jan 03, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'project-avatar-fork' into 'master'
Copy, don't move uploaded avatar files Closes #26158 See merge request !8396
parents
37ef8d72
0406a357
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
7 deletions
+35
-7
avatar_uploader.rb
app/uploaders/avatar_uploader.rb
+11
-0
project-avatar-fork.yml
changelogs/unreleased/project-avatar-fork.yml
+4
-0
fork_service_spec.rb
spec/services/projects/fork_service_spec.rb
+13
-0
avatar_uploader_spec.rb
spec/uploaders/avatar_uploader_spec.rb
+4
-4
file_uploader_spec.rb
spec/uploaders/file_uploader_spec.rb
+3
-3
No files found.
app/uploaders/avatar_uploader.rb
View file @
3e1ac95b
...
...
@@ -10,4 +10,15 @@ class AvatarUploader < GitlabUploader
def
exists?
model
.
avatar
.
file
&&
model
.
avatar
.
file
.
exists?
end
# We set move_to_store and move_to_cache to 'false' to prevent stealing
# the avatar file from a project when forking it.
# https://gitlab.com/gitlab-org/gitlab-ce/issues/26158
def
move_to_store
false
end
def
move_to_cache
false
end
end
changelogs/unreleased/project-avatar-fork.yml
0 → 100644
View file @
3e1ac95b
---
title
:
Copy, don't move uploaded avatar files
merge_request
:
8396
author
:
spec/services/projects/fork_service_spec.rb
View file @
3e1ac95b
...
...
@@ -5,10 +5,12 @@ describe Projects::ForkService, services: true do
before
do
@from_namespace
=
create
(
:namespace
)
@from_user
=
create
(
:user
,
namespace:
@from_namespace
)
avatar
=
fixture_file_upload
(
Rails
.
root
+
"spec/fixtures/dk.png"
,
"image/png"
)
@from_project
=
create
(
:project
,
creator_id:
@from_user
.
id
,
namespace:
@from_namespace
,
star_count:
107
,
avatar:
avatar
,
description:
'wow such project'
)
@to_namespace
=
create
(
:namespace
)
@to_user
=
create
(
:user
,
namespace:
@to_namespace
)
...
...
@@ -36,6 +38,17 @@ describe Projects::ForkService, services: true do
it
{
expect
(
to_project
.
namespace
).
to
eq
(
@to_user
.
namespace
)
}
it
{
expect
(
to_project
.
star_count
).
to
be_zero
}
it
{
expect
(
to_project
.
description
).
to
eq
(
@from_project
.
description
)
}
it
{
expect
(
to_project
.
avatar
.
file
).
to
be_exists
}
# This test is here because we had a bug where the from-project lost its
# avatar after being forked.
# https://gitlab.com/gitlab-org/gitlab-ce/issues/26158
it
"after forking the from-project still has its avatar"
do
# If we do not fork the project first we cannot detect the bug.
expect
(
to_project
).
to
be_persisted
expect
(
@from_project
.
avatar
.
file
).
to
be_exists
end
end
end
...
...
spec/uploaders/avatar_uploader_spec.rb
View file @
3e1ac95b
...
...
@@ -5,14 +5,14 @@ describe AvatarUploader do
subject
{
described_class
.
new
(
user
)
}
describe
'#move_to_cache'
do
it
'is
tru
e'
do
expect
(
subject
.
move_to_cache
).
to
eq
(
tru
e
)
it
'is
fals
e'
do
expect
(
subject
.
move_to_cache
).
to
eq
(
fals
e
)
end
end
describe
'#move_to_store'
do
it
'is
tru
e'
do
expect
(
subject
.
move_to_store
).
to
eq
(
tru
e
)
it
'is
fals
e'
do
expect
(
subject
.
move_to_store
).
to
eq
(
fals
e
)
end
end
end
spec/uploaders/file_uploader_spec.rb
View file @
3e1ac95b
...
...
@@ -17,7 +17,7 @@ describe FileUploader do
describe
'#image_or_video?'
do
context
'given an image file'
do
before
do
@uploader
.
store!
(
File
.
new
(
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'rails_sample.jpg'
)))
@uploader
.
store!
(
fixture_file_upload
(
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'rails_sample.jpg'
)))
end
it
'detects an image based on file extension'
do
...
...
@@ -27,7 +27,7 @@ describe FileUploader do
context
'given an video file'
do
before
do
video_file
=
File
.
new
(
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'video_sample.mp4'
))
video_file
=
fixture_file_upload
(
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'video_sample.mp4'
))
@uploader
.
store!
(
video_file
)
end
...
...
@@ -37,7 +37,7 @@ describe FileUploader do
end
it
'does not return image_or_video? for other types'
do
@uploader
.
store!
(
File
.
new
(
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'doc_sample.txt'
)))
@uploader
.
store!
(
fixture_file_upload
(
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'doc_sample.txt'
)))
expect
(
@uploader
.
image_or_video?
).
to
be
false
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