Class: Caboose::SitesController
Instance Method Summary
collapse
#add_ga_event, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #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_add ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'app/controllers/caboose/sites_controller.rb', line 156
def admin_add
return if !user_is_allowed('sites', 'add')
render :json => { :error => "You are not allowed to manage sites." } and return if !@site.is_master
resp = StdClass.new
site_name = params[:name].strip
if site_name.blank?
resp.error = "Please enter a valid site name."
elsif Site.where(:name => site_name.downcase.gsub(" ","").gsub("'","").gsub("-","")).exists?
resp.error = "That site name is taken."
else
site = Caboose::Site.new
site.name = site_name.downcase.gsub(" ","").gsub("'","").gsub("-","")
site.description = site_name
site.use_fonts = true
site.use_dragdrop = true
site.use_caching = true
site.theme_color = '#141414'
site.allow_self_registration = false
site.use_store = false
site.save
resp.redirect = "/admin/sites/#{site.id}"
if Rails.env.development?
site.build_new_site
elsif Rails.env.production?
site.delay(:queue => 'general', :priority => 11).build_new_site
end
end
render :json => resp
end
|
#admin_add_member ⇒ Object
283
284
285
286
287
288
289
290
291
|
# File 'app/controllers/caboose/sites_controller.rb', line 283
def admin_add_member
return if !user_is_allowed('sites', 'edit')
render :json => { :error => "You are not allowed to manage sites." } and return if !@site.is_master
sm = SiteMembership.where(:site_id => params[:id], :user_id => params[:user_id]).first
sm = SiteMembership.create(:site_id => params[:id], :user_id => params[:user_id]) if sm.nil?
sm.role = params[:role]
sm.save
render :json => true
end
|
#admin_delete ⇒ Object
271
272
273
274
275
276
277
278
279
280
|
# File 'app/controllers/caboose/sites_controller.rb', line 271
def admin_delete
return if !user_is_allowed('sites', 'delete')
render :json => { :error => "You are not allowed to manage sites." } and return if !@site.is_master
site = Site.find(params[:id])
site.destroy
resp = StdClass.new({
'redirect' => '/admin/sites'
})
render :json => resp
end
|
131
132
133
134
135
136
137
138
|
# File 'app/controllers/caboose/sites_controller.rb', line 131
def admin_delete_form
return if !user_is_allowed('sites', 'delete')
if (!logged_in_user.is_super_admin?)
@error = "You are not allowed to edit this site."
render :file => 'caboose/extras/error' and return
end
@site = Site.find(params[:id])
end
|
#admin_edit ⇒ Object
141
142
143
144
145
146
147
148
|
# File 'app/controllers/caboose/sites_controller.rb', line 141
def admin_edit
return unless user_is_allowed('site_settings', 'edit') || user_is_allowed('sites', 'edit')
if (@site.id.to_s != params[:id] && !@site.is_master)
@error = "You are not allowed to edit this site."
render :file => 'caboose/extras/error' and return
end
@site = Site.find(params[:id])
end
|
#admin_edit_block_types ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'app/controllers/caboose/sites_controller.rb', line 91
def admin_edit_block_types
return unless user_is_allowed('site_settings', 'edit') || user_is_allowed('sites', 'edit')
if (@site.id.to_s != params[:id] && !@site.is_master)
@error = "You are not allowed to edit this site."
render :file => 'caboose/extras/error' and return
end
@site = Site.find(params[:id])
end
|
#admin_edit_code ⇒ Object
151
152
153
|
# File 'app/controllers/caboose/sites_controller.rb', line 151
def admin_edit_code
return if !user_is_allowed('code', 'edit')
end
|
111
112
113
114
115
116
117
118
|
# File 'app/controllers/caboose/sites_controller.rb', line 111
def admin_edit_contact
return if !user_is_allowed('contactinfo', 'edit')
if (@site.id.to_s != params[:id] && !@site.is_master)
@error = "You are not allowed to edit this site."
render :file => 'caboose/extras/error' and return
end
@site = Site.find(params[:id])
end
|
#admin_edit_css ⇒ Object
101
102
103
|
# File 'app/controllers/caboose/sites_controller.rb', line 101
def admin_edit_css
return if !user_is_allowed('code', 'edit')
end
|
#admin_edit_js ⇒ Object
106
107
108
|
# File 'app/controllers/caboose/sites_controller.rb', line 106
def admin_edit_js
return if !user_is_allowed('code', 'edit')
end
|
#admin_index ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/caboose/sites_controller.rb', line 28
def admin_index
return if !user_is_allowed('sites', 'view')
if !@site.is_master
@error = "You are not allowed to manage sites."
render :file => 'caboose/extras/error' and return
end
@pager = PageBarGenerator.new(params, {
'name_like' => '',
},{
'model' => 'Caboose::Site',
'sort' => 'name',
'desc' => false,
'base_url' => '/admin/sites',
'use_url_params' => false,
'items_per_page' => 100
})
@sites = @pager.items
end
|
#admin_json ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/caboose/sites_controller.rb', line 48
def admin_json
return if !user_is_allowed('sites', 'view')
if !@site.is_master
@error = "You are not allowed to view sites."
render :file => 'caboose/extras/error' and return
end
h = {
'name' => '',
'description' => '',
'name_like' => '',
'description_like' => '',
}
= Caboose::Pager.new(params, h, {
'model' => 'Caboose::Site',
'sort' => 'name',
'desc' => 'false',
'base_url' => "/admin/sites",
'items_per_page' => 1000
})
render :json => {
:pager => ,
:models => .items.as_json(:include => :domains)
}
end
|
#admin_json_single ⇒ Object
74
75
76
77
78
|
# File 'app/controllers/caboose/sites_controller.rb', line 74
def admin_json_single
return if !user_is_allowed('sites', 'view')
site = get_edit_site(params[:id], @site.id)
render :json => site.as_json(:include => :domains)
end
|
#admin_new ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'app/controllers/caboose/sites_controller.rb', line 81
def admin_new
return if !user_is_allowed('sites', 'add')
if !@site.is_master
@error = "You are not allowed to edit this site."
render :file => 'caboose/extras/error' and return
end
@site = Site.new
end
|
#admin_refresh_cache ⇒ Object
323
324
325
326
327
|
# File 'app/controllers/caboose/sites_controller.rb', line 323
def admin_refresh_cache
return if !user_is_allowed('sites', 'edit')
@site.delay(:queue => 'caching', :priority => 5).refresh_all_page_caches
render :json => true
end
|
#admin_remove_member ⇒ Object
294
295
296
297
298
299
|
# File 'app/controllers/caboose/sites_controller.rb', line 294
def admin_remove_member
return if !user_is_allowed('sites', 'edit')
render :json => { :error => "You are not allowed to manage sites." } and return if !@site.is_master
SiteMembership.where(:site_id => params[:id], :user_id => params[:user_id]).destroy_all
render :json => true
end
|
#admin_update ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'app/controllers/caboose/sites_controller.rb', line 187
def admin_update
return if !user_is_allowed('sites', 'edit')
if (@site.id.to_s != params[:id] && !@site.is_master)
render :json => { :error => "You are not allowed to manage sites." } and return
end
resp = StdClass.new
site = Site.find(params[:id])
save = true
params.each do |name,value|
case name
when 'name' then site.name = value
when 'description' then site.description = value
when 'under_construction_html' then site.under_construction_html = value
when 'use_store' then site.use_store = value
when 'use_fonts' then site.use_fonts = value
when 'use_dragdrop' then site.use_dragdrop = value
when 'use_retargeting' then site.use_retargeting = value
when 'custom_css' then site.custom_css = value
when 'custom_js' then site.custom_js = value
when 'default_layout_id' then site.default_layout_id = value
when 'allow_self_registration' then site.allow_self_registration = value
when 'theme_color' then site.theme_color = value
when 'assets_url' then site.assets_url = value
when 'main_phone' then site.main_phone = value
when 'alt_phone' then site.alt_phone = value
when 'address1' then site.address1 = value
when 'address2' then site.address2 = value
when 'city' then site.city = value
when 'state' then site.state = value
when 'zip' then site.zip = value
when 'fax' then site.fax = value
when 'use_change_logs' then site.use_change_logs = value
when 'google_api_key' then site.google_api_key = value
when 'contact_email' then site.contact_email = value
when 'recaptcha_threshold' then site.recaptcha_threshold = value
when 'use_caching' then site.use_caching = value
when 'head_code' then site.head_code = (value.blank? ? nil : value.gsub('<end/script>','</script>'))
when 'body_open_code' then site.body_open_code = (value.blank? ? nil : value.gsub('<end/script>','</script>'))
when 'body_close_code' then site.body_close_code = (value.blank? ? nil : value.gsub('<end/script>','</script>'))
end
end
resp.success = save && site.save
render :json => resp
end
|
#admin_update_favicon ⇒ Object
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
# File 'app/controllers/caboose/sites_controller.rb', line 252
def admin_update_favicon
return if !user_is_allowed('sites', 'edit')
if (@site.id.to_s != params[:id] && !@site.is_master)
render :json => { :error => "You are not allowed to manage sites." } and return
end
site = Site.find(params[:id])
site.favicon = params[:favicon]
site.save
resp = StdClass.new
resp.success = true
resp.attributes = { :favicon => { :value => site.favicon.url(:tiny) }}
if Caboose::use_cloudinary
site.update_cloudinary_favicon if Rails.env.development?
site.delay(:queue => 'general', :priority => 12).update_cloudinary_favicon if Rails.env.production?
end
render :json => resp
end
|
#admin_update_logo ⇒ Object
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
# File 'app/controllers/caboose/sites_controller.rb', line 233
def admin_update_logo
return if !user_is_allowed('sites', 'edit')
if (@site.id.to_s != params[:id] && !@site.is_master)
render :json => { :error => "You are not allowed to manage sites." } and return
end
site = Site.find(params[:id])
site.logo = params[:logo]
site.save
resp = StdClass.new
resp.success = true
resp.attributes = { :logo => { :value => site.logo.url(:thumb) }}
if Caboose::use_cloudinary
site.update_cloudinary_logo if Rails.env.development?
site.delay(:queue => 'general', :priority => 12).update_cloudinary_logo if Rails.env.production?
end
render :json => resp
end
|
#before_action ⇒ Object
7
8
9
|
# File 'app/controllers/caboose/sites_controller.rb', line 7
def before_action
@page = Page.page_with_uri(request.host_with_port, '/admin')
end
|
#compiled_asset ⇒ Object
330
331
332
333
334
335
|
# File 'app/controllers/caboose/sites_controller.rb', line 330
def compiled_asset
respond_to do |format|
format.css { render :layout => 'caboose/footer_css', :content_type => "text/css" }
format.js { render :layout => 'caboose/footer_js', :content_type => "text/javascript" }
end
end
|
#options ⇒ Object
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
# File 'app/controllers/caboose/sites_controller.rb', line 305
def options
return if !user_is_allowed('sites', 'edit')
render :json => { :error => "You are not allowed to manage sites." } and return if !logged_in_user.is_super_admin?
case params[:field]
when nil
options = logged_in_user.is_super_admin? ? Site.reorder('name').all.collect { |s| { 'value' => s.id, 'text' => s.name }} : []
when 'default-layout'
cat_ids = Caboose::BlockTypeCategory.layouts.collect{ |cat| cat.id }
block_types = Caboose::BlockType.includes(:block_type_site_memberships).where("block_type_category_id in (?) and block_type_site_memberships.site_id = ?", cat_ids, params[:id]).reorder(:description).all
options = block_types.collect do |bt|
{ 'value' => bt.id, 'text' => bt.description }
end
end
render :json => options
end
|
#robots ⇒ Object
23
24
25
|
# File 'app/controllers/caboose/sites_controller.rb', line 23
def robots
respond_to :text
end
|
#sitemap ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
|
# File 'app/controllers/caboose/sites_controller.rb', line 11
def sitemap
@protocol = request && request.protocol ? request.protocol : 'http://'
@protocol = 'https://' if request && request.env['HTTP_CF_VISITOR'] && request.env['HTTP_CF_VISITOR'].to_s.include?('https')
begin
view = ActionView::Base.new(ActionController::Base.view_paths)
str = view.render(:partial => "../../app/views/caboose/blocks/#{@site.name}/sitemap", :locals => {:site => @site, :protocol => @protocol})
render :inline => str
rescue ActionView::MissingTemplate => ex
respond_to :xml
end
end
|