class AttachmentsController < ApplicationController

  skip_filter :check_for_previous_confirmed_sessions,
              :set_default_metatags,
              :check_bank_account,
              :redirect_to_admin_dashboard,
              :find_current_video_sessions
  before_filter :require_login
  # Method used to download the attachment when user clicks download link. It return attachment information with its url and if it is image it will also return its type and style.
  def download
    attachment = Attachment.find(params[:id])
    if attachment.has_access_to? current_user
      if attachment.image?
        send_data File.read(attachment.attachment.path(params[:style] || :original)), type: attachment.attachment_content_type, disposition: 'inline', url_based_filename: true
      else
        send_file attachment.attachment.path, :type => attachment.attachment_content_type
      end
    else
      render_404
    end
  end

end
