summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/files_controller.rb17
-rw-r--r--app/controllers/projects/uploads_controller.rb34
-rw-r--r--app/controllers/projects_controller.rb21
-rw-r--r--app/controllers/uploads_controller.rb18
4 files changed, 33 insertions, 57 deletions
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
deleted file mode 100644
index 9671245d3f4..00000000000
--- a/app/controllers/files_controller.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-class FilesController < ApplicationController
- def download
- note = Note.find(params[:id])
- uploader = note.attachment
-
- if uploader.file_storage?
- if can?(current_user, :read_project, note.project)
- disposition = uploader.image? ? 'inline' : 'attachment'
- send_file uploader.file.path, disposition: disposition
- else
- not_found!
- end
- else
- redirect_to uploader.url
- end
- end
-end
diff --git a/app/controllers/projects/uploads_controller.rb b/app/controllers/projects/uploads_controller.rb
index 2b4da35bc7f..53b92d8643d 100644
--- a/app/controllers/projects/uploads_controller.rb
+++ b/app/controllers/projects/uploads_controller.rb
@@ -1,19 +1,35 @@
class Projects::UploadsController < Projects::ApplicationController
- layout "project"
+ layout 'project'
before_filter :project
+ def create
+ link_to_file = ::Projects::UploadService.new(repository, params[:file]).
+ execute
+
+ respond_to do |format|
+ if link_to_file
+ format.json do
+ render json: { link: link_to_file }
+ end
+ else
+ format.json do
+ render json: 'Invalid file.', status: :unprocessable_entity
+ end
+ end
+ end
+ end
+
def show
- path = File.join(project.path_with_namespace, params[:secret])
- uploader = FileUploader.new('uploads', path)
+ uploader = FileUploader.new(project, params[:secret])
+
+ return redirect_to uploader.url unless uploader.file_storage?
uploader.retrieve_from_store!(params[:filename])
- if uploader.file.exists?
- # Right now, these are always images, so we can safely render them inline.
- send_file uploader.file.path, disposition: 'inline'
- else
- not_found!
- end
+ return not_found! unless uploader.file.exists?
+
+ disposition = uploader.image? ? 'inline' : 'attachment'
+ send_file uploader.file.path, disposition: disposition
end
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index b0fde88babc..74e188e484d 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -137,18 +137,6 @@ class ProjectsController < ApplicationController
end
end
- def upload_image
- link_to_image = ::Projects::ImageService.new(repository, params, root_url).execute
-
- respond_to do |format|
- if link_to_image
- format.json { render json: { link: link_to_image } }
- else
- format.json { render json: 'Invalid file.', status: :unprocessable_entity }
- end
- end
- end
-
def toggle_star
current_user.toggle_star(@project)
@project.reload
@@ -161,15 +149,6 @@ class ProjectsController < ApplicationController
private
- def upload_path
- base_dir = FileUploader.generate_dir
- File.join(repository.path_with_namespace, base_dir)
- end
-
- def accepted_images
- %w(png jpg jpeg gif)
- end
-
def set_title
@title = 'New Project'
end
diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb
index d5877977258..508c2a6221a 100644
--- a/app/controllers/uploads_controller.rb
+++ b/app/controllers/uploads_controller.rb
@@ -3,15 +3,13 @@ class UploadsController < ApplicationController
model = params[:model].camelize.constantize.find(params[:id])
uploader = model.send(params[:mounted_as])
- if uploader.file_storage?
- if !model.respond_to?(:project) || can?(current_user, :read_project, model.project)
- disposition = uploader.image? ? 'inline' : 'attachment'
- send_file uploader.file.path, disposition: disposition
- else
- not_found!
- end
- else
- redirect_to uploader.url
- end
+ return not_found! if model.respond_to?(:project) && !can?(current_user, :read_project, model.project)
+
+ return redirect_to uploader.url unless uploader.file_storage?
+
+ return not_found! unless uploader.file.exists?
+
+ disposition = uploader.image? ? 'inline' : 'attachment'
+ send_file uploader.file.path, disposition: disposition
end
end