uploads_controller.rb 747 Bytes
Newer Older
1
class UploadsController < ApplicationController
2
  skip_before_filter :authenticate_user!, :reject_blocked!
3 4
  before_filter :authorize_access

5 6 7 8
  def show
    model = params[:model].camelize.constantize.find(params[:id])
    uploader = model.send(params[:mounted_as])

9 10 11 12 13 14 15 16
    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
17
  end
18 19 20

  def authorize_access
    unless params[:mounted_as] == 'avatar'
21
      authenticate_user! && reject_blocked!
22 23
    end
  end
24
end