Class: Decidim::PrivateDownloadsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/decidim/private_downloads_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/decidim/private_downloads_controller.rb', line 7

def show
  return head :not_found unless private_download.attached?
  return head :not_found unless private_download.authorized_for?(current_user)

  disposition = private_download.attachment.content_type.start_with?("image/") ? :inline : :attachment

  send_data(
    private_download.attachment.download,
    filename: private_download.attachment.filename.to_s,
    type: private_download.attachment.content_type,
    disposition:
  )
rescue Decidim::PrivateDownload::InvalidTokenError
  head :not_found
end