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
1683f020
Commit
1683f020
authored
Apr 04, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Gitlab::Geo::AvatarUploader
parent
916c9e7b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
41 deletions
+32
-41
app/services/geo/file_upload_service.rb
app/services/geo/file_upload_service.rb
+4
-11
lib/gitlab/geo/avatar_uploader.rb
lib/gitlab/geo/avatar_uploader.rb
+0
-25
lib/gitlab/geo/file_uploader.rb
lib/gitlab/geo/file_uploader.rb
+24
-1
spec/services/geo/file_upload_service_spec.rb
spec/services/geo/file_upload_service_spec.rb
+4
-4
No files found.
app/services/geo/file_upload_service.rb
View file @
1683f020
...
...
@@ -15,22 +15,15 @@ module Geo
data
=
::
Gitlab
::
Geo
::
JwtRequestDecoder
.
new
(
auth_header
).
decode
return
unless
data
.
present?
begin
uploader_class
.
new
(
object_db_id
,
data
).
execute
rescue
NameError
log
(
"Unknown file type:
#{
object_type
}
"
)
{}
end
uploader_class
.
new
(
object_db_id
,
data
).
execute
end
private
def
uploader_class
"Gitlab::Geo::
#{
object_type
.
camelize
}
Uploader"
.
constantize
end
def
log
(
message
)
Rails
.
logger
.
info
"
#{
self
.
class
.
name
}
:
#{
message
}
"
"Gitlab::Geo::
#{
object_type
.
to_s
.
camelize
}
Uploader"
.
constantize
rescue
NameError
Gitlab
::
Geo
::
FileUploader
end
end
end
lib/gitlab/geo/avatar_uploader.rb
deleted
100644 → 0
View file @
916c9e7b
module
Gitlab
module
Geo
class
AvatarUploader
<
FileUploader
def
execute
upload
=
Upload
.
find_by_id
(
object_db_id
)
return
error
unless
upload
.
present?
return
error
unless
valid?
(
upload
)
unless
upload
.
model
.
avatar
&
.
exists?
return
error
(
"
#{
upload
.
model_type
}
does not have a avatar"
)
end
success
(
upload
.
model
.
avatar
)
end
private
def
valid?
(
upload
)
message
[
:id
]
==
upload
.
model_id
&&
message
[
:type
]
==
upload
.
model_type
&&
message
[
:checksum
]
==
upload
.
checksum
end
end
end
end
lib/gitlab/geo/file_uploader.rb
View file @
1683f020
...
...
@@ -9,11 +9,34 @@ module Gitlab
end
def
execute
raise
NotImplementedError
recorded_file
=
Upload
.
find_by_id
(
object_db_id
)
return
error
unless
recorded_file
&
.
exist?
return
error
unless
valid?
(
recorded_file
)
success
(
CarrierWave
::
SanitizedFile
.
new
(
recorded_file
.
absolute_path
))
end
private
def
valid?
(
recorded_file
)
matches_requested_model?
(
recorded_file
)
&&
matches_checksum?
(
recorded_file
)
end
def
matches_requested_model?
(
recorded_file
)
message
[
:id
]
==
recorded_file
.
model_id
&&
message
[
:type
]
==
recorded_file
.
model_type
end
def
matches_checksum?
(
recorded_file
)
message
[
:checksum
]
==
calculate_checksum
(
recorded_file
.
absolute_path
)
end
def
calculate_checksum
(
absolute_path
)
Digest
::
SHA256
.
file
(
absolute_path
).
hexdigest
end
def
success
(
file
)
{
code: :ok
,
message:
'Success'
,
file:
file
}
end
...
...
spec/services/geo/file_upload_service_spec.rb
View file @
1683f020
...
...
@@ -18,7 +18,7 @@ describe Geo::FileUploadService, services: true do
response
=
service
.
execute
expect
(
response
[
:code
]).
to
eq
(
:ok
)
expect
(
response
[
:file
].
file
.
path
).
to
eq
(
user
.
avatar
.
path
)
expect
(
response
[
:file
].
path
).
to
eq
(
user
.
avatar
.
path
)
end
it
'returns nil if no authorization'
do
...
...
@@ -42,7 +42,7 @@ describe Geo::FileUploadService, services: true do
response
=
service
.
execute
expect
(
response
[
:code
]).
to
eq
(
:ok
)
expect
(
response
[
:file
].
file
.
path
).
to
eq
(
group
.
avatar
.
path
)
expect
(
response
[
:file
].
path
).
to
eq
(
group
.
avatar
.
path
)
end
it
'returns nil if no authorization'
do
...
...
@@ -66,7 +66,7 @@ describe Geo::FileUploadService, services: true do
response
=
service
.
execute
expect
(
response
[
:code
]).
to
eq
(
:ok
)
expect
(
response
[
:file
].
file
.
path
).
to
eq
(
project
.
avatar
.
path
)
expect
(
response
[
:file
].
path
).
to
eq
(
project
.
avatar
.
path
)
end
it
'returns nil if no authorization'
do
...
...
@@ -89,7 +89,7 @@ describe Geo::FileUploadService, services: true do
response
=
service
.
execute
expect
(
response
[
:code
]).
to
eq
(
:ok
)
expect
(
response
[
:file
].
file
.
path
).
to
eq
(
lfs_object
.
file
.
path
)
expect
(
response
[
:file
].
path
).
to
eq
(
lfs_object
.
file
.
path
)
end
it
'returns nil if no authorization'
do
...
...
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