Class: Caboose::MyAccountLineItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose/my_account_line_items_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_delete, #admin_edit, #admin_index, #admin_json, #admin_json_single, #admin_update, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#downloadObject

GET /my-account/orders/:order_id/line-items/:id/download



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/caboose/my_account_line_items_controller.rb', line 29

def download
  return if !verify_logged_in
  
  order = Order.find(params[:order_id])      
  if order.customer_id != logged_in_user.id
    @error = "The given order does not belong to you."
    render :file => 'caboose/extras/error'
    return
  end
  
  li = LineItem.find(params[:id])
  if !li.variant.downloadable
    render :text => "Not a downloadable file."
    return
  end
  
  # Generate the download URL and redirect to it
  sc = @site.store_config              
  config = YAML.load_file("#{::Rails.root}/config/aws.yml")
  AWS.config({ 
    :access_key_id => config[Rails.env]['access_key_id'],
    :secret_access_key => config[Rails.env]['secret_access_key']  
  })          
  bucket = AWS::S3::Bucket.new(config[Rails.env]['bucket'])
  s3object = AWS::S3::S3Object.new(bucket, li.variant.download_path)
  url = s3object.url_for(:read, :expires => sc.download_url_expires_in.to_i.minutes).to_s

  redirect_to url
end

#editObject

GET /my-account/orders/:order_id/line-items/:id



16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/caboose/my_account_line_items_controller.rb', line 16

def edit
  return if !verify_logged_in
  
  @order = Order.find(params[:order_id])
  @line_item = LineItem.find(params[:id])
  if @order.customer_id != logged_in_user.id
    @error = "The given order does not belong to you."
    render :file => 'caboose/extras/error'
    return
  end      
end

#indexObject

GET /my-account/orders/:order_id/line-items



5
6
7
8
9
10
11
12
13
# File 'app/controllers/caboose/my_account_line_items_controller.rb', line 5

def index
  return if !verify_logged_in      
  @order = Order.find(params[:order_id])
  if @order.customer_id != logged_in_user.id
    @error = "The given order does not belong to you."
    render :file => 'caboose/extras/error'
    return
  end
end