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
Boxiang Sun
gitlab-ce
Commits
63e9969c
Commit
63e9969c
authored
Dec 31, 2018
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor upload service to return uploader
Also changes old calls to the service
parent
ccbc4555
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
13 additions
and
15 deletions
+13
-15
app/controllers/concerns/uploads_actions.rb
app/controllers/concerns/uploads_actions.rb
+1
-1
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+5
-5
app/services/upload_service.rb
app/services/upload_service.rb
+3
-5
lib/api/projects.rb
lib/api/projects.rb
+1
-1
lib/gitlab/email/attachment_uploader.rb
lib/gitlab/email/attachment_uploader.rb
+1
-1
lib/gitlab/import_export/uploads_manager.rb
lib/gitlab/import_export/uploads_manager.rb
+1
-1
spec/services/upload_service_spec.rb
spec/services/upload_service_spec.rb
+1
-1
No files found.
app/controllers/concerns/uploads_actions.rb
View file @
63e9969c
...
@@ -7,7 +7,7 @@ module UploadsActions
...
@@ -7,7 +7,7 @@ module UploadsActions
UPLOAD_MOUNTS
=
%w(avatar attachment file logo header_logo favicon)
.
freeze
UPLOAD_MOUNTS
=
%w(avatar attachment file logo header_logo favicon)
.
freeze
def
create
def
create
link_to_file
=
UploadService
.
new
(
model
,
params
[
:file
],
uploader_class
).
execute
link_to_file
=
UploadService
.
new
(
model
,
params
[
:file
],
uploader_class
).
execute
.
to_h
respond_to
do
|
format
|
respond_to
do
|
format
|
if
link_to_file
if
link_to_file
...
...
app/controllers/projects/issues_controller.rb
View file @
63e9969c
...
@@ -37,6 +37,8 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -37,6 +37,8 @@ class Projects::IssuesController < Projects::ApplicationController
# Allow create a new branch and empty WIP merge request from current issue
# Allow create a new branch and empty WIP merge request from current issue
before_action
:authorize_create_merge_request_from!
,
only:
[
:create_merge_request
]
before_action
:authorize_create_merge_request_from!
,
only:
[
:create_merge_request
]
before_action
:authorize_import_issues!
,
only:
[
:import_csv
]
before_action
:set_suggested_issues_feature_flags
,
only:
[
:new
]
before_action
:set_suggested_issues_feature_flags
,
only:
[
:new
]
respond_to
:html
respond_to
:html
...
@@ -176,12 +178,10 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -176,12 +178,10 @@ class Projects::IssuesController < Projects::ApplicationController
end
end
def
import_csv
def
import_csv
return
render_404
unless
Feature
.
enabled?
(
:issues_import_csv
)
&&
can?
(
current_user
,
:import_issues
,
project
)
return
render_404
unless
Feature
.
enabled?
(
:issues_import_csv
)
service
=
UploadService
.
new
(
project
,
params
[
:file
])
if
service
.
execute
if
uploader
=
UploadService
.
new
(
project
,
params
[
:file
])
.
execute
ImportIssuesCsvWorker
.
perform_async
(
current_user
.
id
,
project
.
id
,
service
.
uploader
.
upload
.
id
)
ImportIssuesCsvWorker
.
perform_async
(
current_user
.
id
,
project
.
id
,
uploader
.
upload
.
id
)
flash
[
:notice
]
=
_
(
"Your issues are being imported. Once finished, you'll get a confirmation email."
)
flash
[
:notice
]
=
_
(
"Your issues are being imported. Once finished, you'll get a confirmation email."
)
else
else
...
...
app/services/upload_service.rb
View file @
63e9969c
# frozen_string_literal: true
# frozen_string_literal: true
class
UploadService
class
UploadService
attr_accessor
:uploader
def
initialize
(
model
,
file
,
uploader_class
=
FileUploader
,
**
uploader_context
)
def
initialize
(
model
,
file
,
uploader_class
=
FileUploader
,
**
uploader_context
)
@model
,
@file
,
@uploader_class
,
@uploader_context
=
model
,
file
,
uploader_class
,
uploader_context
@model
,
@file
,
@uploader_class
,
@uploader_context
=
model
,
file
,
uploader_class
,
uploader_context
end
end
...
@@ -10,10 +8,10 @@ class UploadService
...
@@ -10,10 +8,10 @@ class UploadService
def
execute
def
execute
return
nil
unless
@file
&&
@file
.
size
<=
max_attachment_size
return
nil
unless
@file
&&
@file
.
size
<=
max_attachment_size
@
uploader
=
@uploader_class
.
new
(
@model
,
nil
,
@uploader_context
)
uploader
=
@uploader_class
.
new
(
@model
,
nil
,
@uploader_context
)
@
uploader
.
store!
(
@file
)
uploader
.
store!
(
@file
)
@uploader
.
to_h
uploader
end
end
private
private
...
...
lib/api/projects.rb
View file @
63e9969c
...
@@ -475,7 +475,7 @@ module API
...
@@ -475,7 +475,7 @@ module API
requires
:file
,
type:
File
,
desc:
'The file to be uploaded'
requires
:file
,
type:
File
,
desc:
'The file to be uploaded'
end
end
post
":id/uploads"
do
post
":id/uploads"
do
UploadService
.
new
(
user_project
,
params
[
:file
]).
execute
UploadService
.
new
(
user_project
,
params
[
:file
]).
execute
.
to_h
end
end
desc
'Get the users list of a project'
do
desc
'Get the users list of a project'
do
...
...
lib/gitlab/email/attachment_uploader.rb
View file @
63e9969c
...
@@ -23,7 +23,7 @@ module Gitlab
...
@@ -23,7 +23,7 @@ module Gitlab
content_type:
attachment
.
content_type
content_type:
attachment
.
content_type
}
}
link
=
UploadService
.
new
(
project
,
file
).
execute
link
=
UploadService
.
new
(
project
,
file
).
execute
.
to_h
attachments
<<
link
if
link
attachments
<<
link
if
link
ensure
ensure
tmp
.
close!
tmp
.
close!
...
...
lib/gitlab/import_export/uploads_manager.rb
View file @
63e9969c
...
@@ -40,7 +40,7 @@ module Gitlab
...
@@ -40,7 +40,7 @@ module Gitlab
def
add_upload
(
upload
)
def
add_upload
(
upload
)
uploader_context
=
FileUploader
.
extract_dynamic_path
(
upload
).
named_captures
.
symbolize_keys
uploader_context
=
FileUploader
.
extract_dynamic_path
(
upload
).
named_captures
.
symbolize_keys
UploadService
.
new
(
@project
,
File
.
open
(
upload
,
'r'
),
FileUploader
,
uploader_context
).
execute
UploadService
.
new
(
@project
,
File
.
open
(
upload
,
'r'
),
FileUploader
,
uploader_context
).
execute
.
to_h
end
end
def
copy_project_uploads
def
copy_project_uploads
...
...
spec/services/upload_service_spec.rb
View file @
63e9969c
...
@@ -68,6 +68,6 @@ describe UploadService do
...
@@ -68,6 +68,6 @@ describe UploadService do
end
end
def
upload_file
(
project
,
file
)
def
upload_file
(
project
,
file
)
described_class
.
new
(
project
,
file
,
FileUploader
).
execute
described_class
.
new
(
project
,
file
,
FileUploader
).
execute
.
to_h
end
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