2011-10-30 23:02:41 +00:00
|
|
|
module Locomotive
|
2011-07-06 18:48:04 +00:00
|
|
|
class CurrentSiteController < BaseController
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
sections 'settings', 'site'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-06-26 23:02:48 +00:00
|
|
|
skip_load_and_authorize_resource
|
|
|
|
|
|
|
|
load_and_authorize_resource :class => 'Site'
|
|
|
|
|
2012-01-10 01:24:34 +00:00
|
|
|
helper 'Locomotive::Sites'
|
|
|
|
|
2011-11-29 01:24:02 +00:00
|
|
|
before_filter :filter_attributes
|
|
|
|
|
2010-07-13 20:01:40 +00:00
|
|
|
respond_to :json, :only => :update
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-11-21 01:27:05 +00:00
|
|
|
def edit
|
|
|
|
@site = current_site
|
|
|
|
respond_with @site
|
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def update
|
2011-11-21 01:27:05 +00:00
|
|
|
@site = current_site
|
|
|
|
@site.update_attributes(params[:site])
|
2011-11-27 16:22:54 +00:00
|
|
|
respond_with @site, :location => edit_current_site_url(new_host_if_subdomain_changed)
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
protected
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-11-29 01:24:02 +00:00
|
|
|
def filter_attributes
|
|
|
|
unless can?(:manage, Locomotive::Membership)
|
|
|
|
params[:site].delete(:memberships_attributes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def new_host_if_subdomain_changed
|
2011-04-24 23:21:38 +00:00
|
|
|
if !Locomotive.config.manage_subdomain? || @site.domains.include?(request.host)
|
2010-05-10 22:39:52 +00:00
|
|
|
{}
|
|
|
|
else
|
2011-04-24 23:21:38 +00:00
|
|
|
{ :host => site_url(@site, { :fullpath => false, :protocol => false }) }
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|