2011-10-30 23:02:41 +00:00
|
|
|
module Locomotive
|
2011-11-09 01:35:59 +00:00
|
|
|
class BaseController < ApplicationController
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
include Locomotive::Routing::SiteDispatcher
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-01-09 14:49:59 +00:00
|
|
|
include Locomotive::ActionController::Helpers
|
|
|
|
|
2011-10-30 23:02:41 +00:00
|
|
|
layout '/locomotive/layouts/application'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-10-30 23:02:41 +00:00
|
|
|
before_filter :require_account
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
before_filter :require_site
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
before_filter :validate_site_membership
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-08-27 17:14:02 +00:00
|
|
|
load_and_authorize_resource
|
|
|
|
|
2012-01-14 00:38:09 +00:00
|
|
|
before_filter :set_back_office_locale
|
|
|
|
|
|
|
|
before_filter :set_current_content_locale
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-09-17 14:23:43 +00:00
|
|
|
before_filter :set_current_thread_variables
|
|
|
|
|
2012-01-09 14:49:59 +00:00
|
|
|
helper_method :sections, :current_ability
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-01-09 14:49:59 +00:00
|
|
|
helper Locomotive::BaseHelper, Locomotive::ContentTypesHelper
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-01-09 14:49:59 +00:00
|
|
|
self.responder = Locomotive::ActionController::Responder # custom responder
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
respond_to :html
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-06-25 16:25:31 +00:00
|
|
|
rescue_from CanCan::AccessDenied do |exception|
|
2011-07-26 19:20:03 +00:00
|
|
|
::Locomotive.log "[CanCan::AccessDenied] #{exception.inspect}"
|
2011-06-25 16:25:31 +00:00
|
|
|
|
|
|
|
if request.xhr?
|
|
|
|
render :json => { :error => exception.message }
|
|
|
|
else
|
|
|
|
flash[:alert] = exception.message
|
|
|
|
|
2011-10-31 23:44:23 +00:00
|
|
|
redirect_to pages_url
|
2011-06-25 16:25:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
protected
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-09-17 14:23:43 +00:00
|
|
|
def set_current_thread_variables
|
2012-01-09 14:49:59 +00:00
|
|
|
Thread.current[:account] = current_locomotive_account
|
|
|
|
Thread.current[:site] = current_site
|
2011-09-17 14:23:43 +00:00
|
|
|
end
|
|
|
|
|
2011-06-25 16:25:31 +00:00
|
|
|
def current_ability
|
2011-11-04 15:55:51 +00:00
|
|
|
@current_ability ||= Ability.new(current_locomotive_account, current_site)
|
2011-06-25 16:25:31 +00:00
|
|
|
end
|
|
|
|
|
2011-10-30 23:02:41 +00:00
|
|
|
def require_account
|
2011-11-04 15:55:51 +00:00
|
|
|
authenticate_locomotive_account!
|
2011-05-28 17:52:36 +00:00
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|