Welcome to mirror list, hosted at ThFree Co, Russian Federation.

files_controller.rb « controllers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 267239b7b84a978f02b7bfc0fbab3037c80dc3fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class FilesController < ApplicationController
  def download
    note = Note.find(params[:id])
    uploader = note.attachment

    if can?(current_user, :read_project, note.project)
      if uploader.file_storage?
        path = uploader.file.path.gsub("#{Rails.root}/public", Rails.root.to_s)

        if File.exist?(path)
          disposition = uploader.image? ? 'inline' : 'attachment'
          send_file path, disposition: disposition
        else
          not_found!
        end
      else
        redirect_to uploader.url
      end
    else
      not_found!
    end
  end
end