2015-02-20 12:13:48 +00:00
|
|
|
class UploadsController < ApplicationController
|
2015-02-24 13:54:32 +00:00
|
|
|
skip_before_filter :authenticate_user!, :reject_blocked!
|
2015-02-24 03:35:42 +00:00
|
|
|
before_filter :authorize_access
|
|
|
|
|
2015-02-20 12:13:48 +00:00
|
|
|
def show
|
|
|
|
model = params[:model].camelize.constantize.find(params[:id])
|
|
|
|
uploader = model.send(params[:mounted_as])
|
|
|
|
|
2015-02-20 14:37:37 +00:00
|
|
|
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
|
2015-02-20 12:13:48 +00:00
|
|
|
end
|
2015-02-24 03:35:42 +00:00
|
|
|
|
|
|
|
def authorize_access
|
|
|
|
unless params[:mounted_as] == 'avatar'
|
2015-02-24 13:54:32 +00:00
|
|
|
authenticate_user! && reject_blocked!
|
2015-02-24 03:35:42 +00:00
|
|
|
end
|
|
|
|
end
|
2015-02-20 12:13:48 +00:00
|
|
|
end
|