Class: Caboose::DomainsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_edit, #admin_index, #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


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/caboose/domains_controller.rb', line 12

def admin_add
  return if !user_is_allowed('domains', 'edit')
  return if params[:site_id] != @site.id.to_s && !@site.is_master
  resp = Caboose::StdClass.new
  d = Domain.where(:domain => params[:domain]).first
  if d && d.site_id != params[:site_id]
    resp.error = "That domain is already associated with another site."
  elsif d && d.site_id == params[:site_id]
    resp.refresh = true
  elsif d.nil?
    primary = Domain.where(:site_id => params[:site_id]).count == 0
    d = Domain.create(:site_id => params[:site_id], :domain => params[:domain], :primary => primary)
    resp.refresh = true
  end
  render :json => resp
end

#admin_deleteObject


57
58
59
60
61
62
63
# File 'app/controllers/caboose/domains_controller.rb', line 57

def admin_delete
  return if !user_is_allowed('sites', 'delete')
  return if params[:site_id] != @site.id.to_s && !@site.is_master
  domain = get_edit_domain(params[:id], @site.id)
  domain.destroy if domain
  render :json => { 'refresh' => "/admin/sites/#{params[:site_id]}" }
end

#admin_set_primaryObject


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/caboose/domains_controller.rb', line 66

def admin_set_primary
  return if !user_is_allowed('domains', 'edit')
  return if params[:site_id] != @site.id.to_s && !@site.is_master
  resp = StdClass.new     
  d = get_edit_domain(params[:id], @site.id)
  save = true
  Domain.where(:site_id => params[:site_id]).all.each do |d2|
    d2.primary = d2.id == d.id ? true : false
    d2.save
  end      
  resp.success = save && d.save
  render :json => resp
end

#admin_updateObject


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
# File 'app/controllers/caboose/domains_controller.rb', line 30

def admin_update
  return if !user_is_allowed('domains', 'edit')
  return if params[:site_id] != @site.id.to_s && !@site.is_master
  resp = StdClass.new     
  d = get_edit_domain(params[:id], @site.id)
  save = true
  params.each do |name,value|
    case name
      when 'site_id'            then d.site_id            = value
      when 'domain'             then d.domain             = value
      when 'under_construction' then d.under_construction = value
      when 'forward_to_primary' then d.forward_to_primary = value
      when 'forward_to_uri'     then d.forward_to_uri     = value
      when 'force_ssl'          then d.force_ssl     = value
      when 'primary'            then
        d.primary = value
        Domain.where(:site_id => params[:site_id]).all.each do |d2|
          d2.primary = d2.id == d.id ? true : false
          d2.save
        end
	  end
	end
	resp.success = save && d.save
	render :json => resp
end

#before_actionObject


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

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