Commit fa3cc1dd24fed0cd3b041e469cada054fda479ab
Exists in
master
and in
4 other branches
Merge branch 'features/attachment_server' of /home/git/repositories/gitlab/gitlabhq
Showing
5 changed files
with
28 additions
and
2 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +class FilesController < ApplicationController | |
| 2 | + def download | |
| 3 | + note = Note.find(params[:id]) | |
| 4 | + | |
| 5 | + if can?(current_user, :read_project, note.project) | |
| 6 | + uploader = note.attachment | |
| 7 | + send_file uploader.file.path, disposition: 'attachment' | |
| 8 | + else | |
| 9 | + not_found! | |
| 10 | + end | |
| 11 | + end | |
| 12 | +end | |
| 13 | + | ... | ... |
app/uploaders/attachment_uploader.rb
| ... | ... | @@ -19,4 +19,12 @@ class AttachmentUploader < CarrierWave::Uploader::Base |
| 19 | 19 | rescue |
| 20 | 20 | false |
| 21 | 21 | end |
| 22 | + | |
| 23 | + def secure_url | |
| 24 | + if self.class.storage == CarrierWave::Storage::File | |
| 25 | + "/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}" | |
| 26 | + else | |
| 27 | + url | |
| 28 | + end | |
| 29 | + end | |
| 22 | 30 | end | ... | ... |
app/views/events/event/_note.html.haml
| ... | ... | @@ -26,7 +26,7 @@ |
| 26 | 26 | = markdown truncate(event.target.note, length: 70) |
| 27 | 27 | - note = event.target |
| 28 | 28 | - if note.attachment.url |
| 29 | - = link_to note.attachment.url, target: "_blank", class: 'note-file-attach' do | |
| 29 | + = link_to note.attachment.secure_url, target: "_blank", class: 'note-file-attach' do | |
| 30 | 30 | - if note.attachment.image? |
| 31 | 31 | = image_tag note.attachment.url, class: 'note-image-attach' |
| 32 | 32 | - else | ... | ... |
app/views/notes/_note.html.haml
| ... | ... | @@ -31,7 +31,7 @@ |
| 31 | 31 | - if note.attachment.image? |
| 32 | 32 | = image_tag note.attachment.url, class: 'note-image-attach' |
| 33 | 33 | .attachment.pull-right |
| 34 | - = link_to note.attachment.url, target: "_blank" do | |
| 34 | + = link_to note.attachment.secure_url, target: "_blank" do | |
| 35 | 35 | %i.icon-paper-clip |
| 36 | 36 | = note.attachment_identifier |
| 37 | 37 | .clear | ... | ... |
config/routes.rb
| ... | ... | @@ -46,6 +46,11 @@ Gitlab::Application.routes.draw do |
| 46 | 46 | end |
| 47 | 47 | |
| 48 | 48 | # |
| 49 | + # Attachments serving | |
| 50 | + # | |
| 51 | + get 'files/:type/:id/:filename' => 'files#download', constraints: { id: /\d+/, type: /[a-z]+/, filename: /[a-zA-Z.0-9_\-\+]+/ } | |
| 52 | + | |
| 53 | + # | |
| 49 | 54 | # Admin Area |
| 50 | 55 | # |
| 51 | 56 | namespace :admin do | ... | ... |