Class: ErpApp::PublicController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/erp_app/public_controller.rb

Instance Method Summary collapse

Instance Method Details

#downloadObject

Download Inline Example: /download/filename.ext?path=/directory&disposition=inline Download Prompt Example: /download/filename.ext?path=/directory&disposition=attachment



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/erp_app/public_controller.rb', line 11

def download
  filename = "#{params[:filename]}.#{params[:format]}"
  disposition = params[:disposition]

  file = FileAsset.where(:name => filename)
  file = file.where(:directory => params[:path]) unless params[:path].blank?
  file = file.first

  unless file.nil?
    if file.is_secured?
      begin
        unless current_user == false
          current_user.with_capability(:download, file) do
            serve_file(file, disposition)
          end
        else
          raise ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability
        end
      rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
        render :text => ex.message and return
      rescue Exception => ex
        Rails.logger.error ex.message
        Rails.logger.error ex.backtrace.join("\n")
        render :text => ex.message and return
      end
    else
      serve_file(file, disposition)
    end
  else
    render :text => 'File not found.'
  end
end