Class: Decidim::PrivateDownloadsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#store_share_token

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

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