summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHeinrich Lee Yu <hleeyu@gmail.com>2018-12-31 11:23:50 +0800
committerHeinrich Lee Yu <hleeyu@gmail.com>2019-01-07 11:16:58 +0800
commit63e9969ca3ac57839b78d9cc44bcf32bc9a45248 (patch)
treecda51e40b5ea915d26425edfce815ca6fae991e9 /app
parentccbc45559b7bedd1d76c1840bbdfba3cce542af7 (diff)
downloadgitlab-ce-63e9969ca3ac57839b78d9cc44bcf32bc9a45248.tar.gz
Refactor upload service to return uploader
Also changes old calls to the service
Diffstat (limited to 'app')
-rw-r--r--app/controllers/concerns/uploads_actions.rb2
-rw-r--r--app/controllers/projects/issues_controller.rb10
-rw-r--r--app/services/upload_service.rb8
3 files changed, 9 insertions, 11 deletions
diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb
index 0eea0cdd50f..5992ad5f1e1 100644
--- a/app/controllers/concerns/uploads_actions.rb
+++ b/app/controllers/concerns/uploads_actions.rb
@@ -7,7 +7,7 @@ module UploadsActions
UPLOAD_MOUNTS = %w(avatar attachment file logo header_logo favicon).freeze
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|
if link_to_file
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb
index f88eb9e0322..21688e54481 100644
--- a/app/controllers/projects/issues_controller.rb
+++ b/app/controllers/projects/issues_controller.rb
@@ -37,6 +37,8 @@ class Projects::IssuesController < Projects::ApplicationController
# 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_import_issues!, only: [:import_csv]
+
before_action :set_suggested_issues_feature_flags, only: [:new]
respond_to :html
@@ -176,12 +178,10 @@ class Projects::IssuesController < Projects::ApplicationController
end
def import_csv
- return render_404 unless Feature.enabled?(:issues_import_csv) && can?(current_user, :import_issues, project)
-
- service = UploadService.new(project, params[:file])
+ return render_404 unless Feature.enabled?(:issues_import_csv)
- if service.execute
- ImportIssuesCsvWorker.perform_async(current_user.id, project.id, service.uploader.upload.id)
+ if uploader = UploadService.new(project, params[:file]).execute
+ 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.")
else
diff --git a/app/services/upload_service.rb b/app/services/upload_service.rb
index 47903eb48c3..41ca95b3b6f 100644
--- a/app/services/upload_service.rb
+++ b/app/services/upload_service.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true
class UploadService
- attr_accessor :uploader
-
def initialize(model, file, uploader_class = FileUploader, **uploader_context)
@model, @file, @uploader_class, @uploader_context = model, file, uploader_class, uploader_context
end
@@ -10,10 +8,10 @@ class UploadService
def execute
return nil unless @file && @file.size <= max_attachment_size
- @uploader = @uploader_class.new(@model, nil, @uploader_context)
- @uploader.store!(@file)
+ uploader = @uploader_class.new(@model, nil, @uploader_context)
+ uploader.store!(@file)
- @uploader.to_h
+ uploader
end
private