summaryrefslogtreecommitdiff
path: root/app/controllers/files_controller.rb
blob: 15523cbc2e726de20f90f1f00c56300c1ed657d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class FilesController < ApplicationController
  def download
    note = Note.find(params[:id])
    uploader = note.attachment

    if uploader.file_storage?
      if can?(current_user, :read_project, note.project)
        # Replace old notes location in /public with the new one in / and send the file
        path = uploader.file.path.gsub("#{Rails.root}/public", Rails.root.to_s)

        disposition = uploader.image? ? 'inline' : 'attachment'
        send_file path, disposition: disposition
      else
        not_found!
      end
    else
      redirect_to uploader.url
    end
  end
end