Commit 9729cc58 authored by Hannes Rosenögger's avatar Hannes Rosenögger Committed by Douwe Maan

implement Project::UploadsController

parent ca504a77
class FilesController < ApplicationController
def download_notes
def download
note = Note.find(params[:id])
uploader = note.attachment
......@@ -14,32 +14,7 @@ class FilesController < ApplicationController
not_found!
end
else
not_found!
redirect_to uploader.url
end
end
def download_files
namespace_id = params[:namespace]
project_id = params[:project]
folder_id = params[:folder_id]
filename = params[:filename]
project_with_namespace="#{namespace_id}/#{project_id}"
filename_with_id="#{folder_id}/#{filename}"
project = Project.find_with_namespace(project_with_namespace)
uploader = FileUploader.new("#{Rails.root}/uploads","#{project_with_namespace}/#{folder_id}")
uploader.retrieve_from_store!(filename)
if can?(current_user, :read_project, project)
download(uploader)
else
not_found!
end
end
def download(uploader)
disposition = uploader.image? ? 'inline' : 'attachment'
send_file uploader.file.path, disposition: disposition
end
end
class Projects::UploadsController < Projects::ApplicationController
layout 'project'
before_filter :project
def show
folder_id = params[:folder_id]
filename = params[:filename]
uploader = FileUploader.new("#{Rails.root}/uploads","#{@project.path_with_namespace}/#{folder_id}")
uploader.retrieve_from_store!(filename)
disposition = uploader.image? ? 'inline' : 'attachment'
send_file uploader.file.path, disposition: disposition
end
end
......@@ -40,7 +40,9 @@ class FileUploader < CarrierWave::Uploader::Base
end
def secure_url
Gitlab.config.gitlab.relative_url_root + "/files/#{@path}/#{@filename}"
path_array = @path.split('/')
path = File.join(path_array[0],path_array[1],'uploads',path_array[2])
Gitlab.config.gitlab.relative_url_root + "/#{path}/#{@filename}"
end
def image?
......
......@@ -93,8 +93,7 @@ Gitlab::Application.routes.draw do
#
# Attachments serving
#
get 'files/:type/:id/:filename' => 'files#download_notes', constraints: { id: /\d+/, type: /[a-z]+/, filename: /.+/ }
get 'files/:namespace/:project/:folder_id/:filename' => 'files#download_files', constraints: { namespace: /[^\/]+/, project: /[a-zA-Z.\/0-9_\-]+/, filename: /.+/ }
get 'files/:type/:id/:filename' => 'files#download', constraints: { id: /\d+/, type: /[a-z]+/, filename: /.+/ }
#
# Admin Area
......@@ -257,6 +256,8 @@ Gitlab::Application.routes.draw do
end
end
get '/uploads/:folder_id/:filename' => 'uploads#show', constraints: { filename: /.+/ }
get '/compare/:from...:to' => 'compare#show', :as => 'compare',
:constraints => { from: /.+/, to: /.+/ }
......
......@@ -20,7 +20,7 @@ describe Projects::FileService do
it { expect(@link_to_file).to have_key('is_image') }
it { expect(@link_to_file).to have_value('banana_sample') }
it { expect(@link_to_file['is_image']).to equal(true) }
it { expect(@link_to_file['url']).to match("/files/#{@project.path_with_namespace}") }
it { expect(@link_to_file['url']).to match("/#{@project.path_with_namespace}") }
it { expect(@link_to_file['url']).to match('banana_sample.gif') }
end
......@@ -38,7 +38,7 @@ describe Projects::FileService do
it { expect(@link_to_file).to have_value('dk') }
it { expect(@link_to_file).to have_key('is_image') }
it { expect(@link_to_file['is_image']).to equal(true) }
it { expect(@link_to_file['url']).to match("/files/#{@project.path_with_namespace}") }
it { expect(@link_to_file['url']).to match("/#{@project.path_with_namespace}") }
it { expect(@link_to_file['url']).to match('dk.png') }
end
......@@ -53,7 +53,7 @@ describe Projects::FileService do
it { expect(@link_to_file).to have_key('is_image') }
it { expect(@link_to_file).to have_value('rails_sample') }
it { expect(@link_to_file['is_image']).to equal(true) }
it { expect(@link_to_file['url']).to match("/files/#{@project.path_with_namespace}") }
it { expect(@link_to_file['url']).to match("/#{@project.path_with_namespace}") }
it { expect(@link_to_file['url']).to match('rails_sample.jpg') }
end
......@@ -70,7 +70,7 @@ describe Projects::FileService do
it { expect(@link_to_file).to have_key('is_image') }
it { expect(@link_to_file).to have_value('doc_sample.txt') }
it { expect(@link_to_file['is_image']).to equal(false) }
it { expect(@link_to_file['url']).to match("/files/#{@project.path_with_namespace}") }
it { expect(@link_to_file['url']).to match("/#{@project.path_with_namespace}") }
it { expect(@link_to_file['url']).to match('doc_sample.txt') }
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment