Class: Caboose::RedirectsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_json, #admin_json_single, #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

#admin_addObject


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/caboose/redirects_controller.rb', line 52

def admin_add
  return unless user_is_allowed('redirects', 'add')

  resp = Caboose::StdClass.new

  pr = PermanentRedirect.new
  pr.site_id = Site.id_for_domain(request.host_with_port)
  pr.is_regex = false
  pr.old_url  = params[:old_url]
  pr.new_url  = params[:new_url]
  pr.priority = 0

  if !pr.valid?        
    resp.error = pr.errors.first[1]
  else
    pr.save
    resp.redirect = "/admin/redirects/#{pr.id}"
  end

  render :json => resp
end

#admin_deleteObject


96
97
98
99
100
101
102
103
104
105
# File 'app/controllers/caboose/redirects_controller.rb', line 96

def admin_delete
  return unless user_is_allowed('redirects', 'delete')
  pr = PermanentRedirect.find(params[:id])
  pr.destroy
  
  resp = StdClass.new({
    'redirect' => '/admin/redirects'
  })
  render :json => resp
end

#admin_editObject


30
31
32
33
34
# File 'app/controllers/caboose/redirects_controller.rb', line 30

def admin_edit
  return unless user_is_allowed('redirects', 'edit')
  @permanent_redirect = PermanentRedirect.find(params[:id])
  render :layout => 'caboose/admin'
end

#admin_indexObject


16
17
18
19
20
21
# File 'app/controllers/caboose/redirects_controller.rb', line 16

def admin_index
  return if !user_is_allowed('redirects', 'view')            
  @domain = Domain.where(:domain => request.host_with_port).first      
  @redirects = @domain ? PermanentRedirect.where(:site_id => @domain.site_id).reorder(:priority).all : []            
  render :layout => 'caboose/admin'      
end

#admin_newObject


24
25
26
27
# File 'app/controllers/caboose/redirects_controller.rb', line 24

def admin_new
  return unless user_is_allowed('redirects', 'add')            
  render :layout => 'caboose/admin'
end

#admin_updateObject


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/caboose/redirects_controller.rb', line 75

def admin_update
  return unless user_is_allowed('redirects', 'edit')
  
  resp = StdClass.new
  pr = PermanentRedirect.find(params[:id])
  
  save = true      
  params.each do |name, value|
    case name
      when 'is_regex'  then pr.is_regex = value
      when 'old_url'   then pr.old_url  = value
      when 'new_url'   then pr.new_url  = value
      when 'priority'  then pr.priority = value        
    end
  end

  resp.success = save && pr.save
  render :json => resp
end

#admin_update_priorityObject


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/caboose/redirects_controller.rb', line 37

def admin_update_priority
  return unless user_is_allowed('redirects', 'edit')      
  @page = Page.find(params[:id])
  ids = params[:ids]
  i = 0
  ids.each do |prid|
    pr = PermanentRedirect.find(prid)
    pr.priority = i
    pr.save
    i = i + 1
  end
  render :json => true
end

#before_actionObject


7
8
9
# File 'app/controllers/caboose/redirects_controller.rb', line 7

def before_action
  @page = Page.page_with_uri(request.host_with_port, '/admin')
end