diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-16 12:45:20 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-16 12:45:20 +0000 |
commit | fa3cc1dd24fed0cd3b041e469cada054fda479ab (patch) | |
tree | 8b1b96f38209f9a81fca0f287f5192382a9d65dc | |
parent | b7297285369171c95b006e49d6da7bc84b969fc8 (diff) | |
parent | f6cc71bc36283223a10f3004121be34f06547d94 (diff) | |
download | gitlab-ce-fa3cc1dd24fed0cd3b041e469cada054fda479ab.tar.gz |
Merge branch 'features/attachment_server' of /home/git/repositories/gitlab/gitlabhq
-rw-r--r-- | app/controllers/files_controller.rb | 13 | ||||
-rw-r--r-- | app/uploaders/attachment_uploader.rb | 8 | ||||
-rw-r--r-- | app/views/events/event/_note.html.haml | 2 | ||||
-rw-r--r-- | app/views/notes/_note.html.haml | 2 | ||||
-rw-r--r-- | config/routes.rb | 5 |
5 files changed, 28 insertions, 2 deletions
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb new file mode 100644 index 00000000000..3cd2e77322c --- /dev/null +++ b/app/controllers/files_controller.rb @@ -0,0 +1,13 @@ +class FilesController < ApplicationController + def download + note = Note.find(params[:id]) + + if can?(current_user, :read_project, note.project) + uploader = note.attachment + send_file uploader.file.path, disposition: 'attachment' + else + not_found! + end + end +end + diff --git a/app/uploaders/attachment_uploader.rb b/app/uploaders/attachment_uploader.rb index 3dbf2860bd4..200700b8810 100644 --- a/app/uploaders/attachment_uploader.rb +++ b/app/uploaders/attachment_uploader.rb @@ -19,4 +19,12 @@ class AttachmentUploader < CarrierWave::Uploader::Base rescue false end + + def secure_url + if self.class.storage == CarrierWave::Storage::File + "/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}" + else + url + end + end end diff --git a/app/views/events/event/_note.html.haml b/app/views/events/event/_note.html.haml index 20c3b927067..19665ce0aea 100644 --- a/app/views/events/event/_note.html.haml +++ b/app/views/events/event/_note.html.haml @@ -26,7 +26,7 @@ = markdown truncate(event.target.note, length: 70) - note = event.target - if note.attachment.url - = link_to note.attachment.url, target: "_blank", class: 'note-file-attach' do + = link_to note.attachment.secure_url, target: "_blank", class: 'note-file-attach' do - if note.attachment.image? = image_tag note.attachment.url, class: 'note-image-attach' - else diff --git a/app/views/notes/_note.html.haml b/app/views/notes/_note.html.haml index 4d3007a0ed1..b355e2a0bd4 100644 --- a/app/views/notes/_note.html.haml +++ b/app/views/notes/_note.html.haml @@ -31,7 +31,7 @@ - if note.attachment.image? = image_tag note.attachment.url, class: 'note-image-attach' .attachment.pull-right - = link_to note.attachment.url, target: "_blank" do + = link_to note.attachment.secure_url, target: "_blank" do %i.icon-paper-clip = note.attachment_identifier .clear diff --git a/config/routes.rb b/config/routes.rb index 88667db130e..7537a11de96 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,6 +46,11 @@ Gitlab::Application.routes.draw do end # + # Attachments serving + # + get 'files/:type/:id/:filename' => 'files#download', constraints: { id: /\d+/, type: /[a-z]+/, filename: /[a-zA-Z.0-9_\-\+]+/ } + + # # Admin Area # namespace :admin do |