Merge branch 'features/attachment_server' of /home/git/repositories/gitlab/gitlabhq
This commit is contained in:
commit
fa3cc1dd24
5 changed files with 28 additions and 2 deletions
13
app/controllers/files_controller.rb
Normal file
13
app/controllers/files_controller.rb
Normal file
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -45,6 +45,11 @@ Gitlab::Application.routes.draw do
|
|||
root to: "projects#index"
|
||||
end
|
||||
|
||||
#
|
||||
# Attachments serving
|
||||
#
|
||||
get 'files/:type/:id/:filename' => 'files#download', constraints: { id: /\d+/, type: /[a-z]+/, filename: /[a-zA-Z.0-9_\-\+]+/ }
|
||||
|
||||
#
|
||||
# Admin Area
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue