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
39374921
Commit
39374921
authored
Apr 05, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Normalize default object types to file in the file upload service
parent
3910b4f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
4 deletions
+74
-4
app/services/geo/file_upload_service.rb
app/services/geo/file_upload_service.rb
+21
-4
spec/services/geo/file_upload_service_spec.rb
spec/services/geo/file_upload_service_spec.rb
+53
-0
No files found.
app/services/geo/file_upload_service.rb
View file @
39374921
module
Geo
class
FileUploadService
DEFAULT_OBJECT_TYPES
=
[
:attachment
,
:avatar
,
:file
].
freeze
IAT_LEEWAY
=
60
.
seconds
.
to_i
attr_reader
:object_type
,
:object_db_id
,
:auth_header
...
...
@@ -15,15 +16,31 @@ module Geo
data
=
::
Gitlab
::
Geo
::
JwtRequestDecoder
.
new
(
auth_header
).
decode
return
unless
data
.
present?
uploader_
c
lass
.
new
(
object_db_id
,
data
).
execute
uploader_
k
lass
.
new
(
object_db_id
,
data
).
execute
end
private
def
uploader_
c
lass
"Gitlab::Geo::
#{
object_type
.
to_s
.
camelize
}
Uploader"
.
constantize
def
uploader_
k
lass
uploader_klass_name
.
constantize
rescue
NameError
Gitlab
::
Geo
::
FileUploader
log
(
"Unknown file type:
#{
object_type
}
"
)
raise
end
def
uploader_klass_name
klass_name
=
if
DEFAULT_OBJECT_TYPES
.
include?
(
object_type
.
to_sym
)
:file
else
object_type
end
"Gitlab::Geo::
#{
klass_name
.
to_s
.
camelize
}
Uploader"
end
def
log
(
message
)
Rails
.
logger
.
info
"
#{
self
.
class
.
name
}
:
#{
message
}
"
end
end
end
spec/services/geo/file_upload_service_spec.rb
View file @
39374921
...
...
@@ -76,6 +76,59 @@ describe Geo::FileUploadService, services: true do
end
end
context
'attachment'
do
let
(
:note
)
{
create
(
:note
,
:with_attachment
)
}
let
(
:upload
)
{
Upload
.
find_by
(
model:
note
,
uploader:
'AttachmentUploader'
)
}
let
(
:params
)
{
{
id:
upload
.
id
,
type:
'attachment'
}
}
let
(
:file_transfer
)
{
Gitlab
::
Geo
::
FileTransfer
.
new
(
:attachment
,
upload
)
}
let
(
:transfer_request
)
{
Gitlab
::
Geo
::
TransferRequest
.
new
(
file_transfer
.
request_data
)
}
let
(
:req_header
)
{
transfer_request
.
headers
[
'Authorization'
]
}
it
'sends attachment file'
do
service
=
described_class
.
new
(
params
,
req_header
)
response
=
service
.
execute
expect
(
response
[
:code
]).
to
eq
(
:ok
)
expect
(
response
[
:file
].
path
).
to
eq
(
note
.
attachment
.
path
)
end
it
'returns nil if no authorization'
do
service
=
described_class
.
new
(
params
,
nil
)
expect
(
service
.
execute
).
to
be_nil
end
end
context
'file upload'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:upload
)
{
Upload
.
find_by
(
model:
project
,
uploader:
'FileUploader'
)
}
let
(
:params
)
{
{
id:
upload
.
id
,
type:
'file'
}
}
let
(
:file_transfer
)
{
Gitlab
::
Geo
::
FileTransfer
.
new
(
:file
,
upload
)
}
let
(
:transfer_request
)
{
Gitlab
::
Geo
::
TransferRequest
.
new
(
file_transfer
.
request_data
)
}
let
(
:req_header
)
{
transfer_request
.
headers
[
'Authorization'
]
}
let
(
:file
)
{
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/dk.png'
,
'image/png'
)
}
before
do
FileUploader
.
new
(
project
).
store!
(
file
)
end
it
'sends the file'
do
service
=
described_class
.
new
(
params
,
req_header
)
response
=
service
.
execute
expect
(
response
[
:code
]).
to
eq
(
:ok
)
expect
(
response
[
:file
].
path
).
to
end_with
(
'dk.png'
)
end
it
'returns nil if no authorization'
do
service
=
described_class
.
new
(
params
,
nil
)
expect
(
service
.
execute
).
to
be_nil
end
end
context
'LFS Object'
do
let
(
:lfs_object
)
{
create
(
:lfs_object
,
:with_file
)
}
let
(
:params
)
{
{
id:
lfs_object
.
id
,
type:
'lfs'
}
}
...
...
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