summaryrefslogtreecommitdiff
path: root/app/controllers/uploads_controller.rb
blob: b096c3913e1150ca2216a49d476ec8a287ab2d63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class UploadsController < ApplicationController
  skip_before_filter :authenticate_user!, :reject_blocked!
  before_filter :authorize_access

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

    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
  end

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