2011-10-18 19:31:59 +01:00
|
|
|
# coding: UTF-8
|
2011-03-09 13:13:36 +00:00
|
|
|
class ApplicationController < ActionController::Base
|
|
|
|
protect_from_forgery
|
2012-01-17 11:48:40 +00:00
|
|
|
|
2011-03-31 00:10:23 +01:00
|
|
|
layout :layout_by_resource
|
2011-10-21 15:57:29 +01:00
|
|
|
|
2012-01-17 11:48:40 +00:00
|
|
|
before_filter :set_locale
|
2011-10-28 23:31:47 +01:00
|
|
|
before_filter lambda { EventLog.current_controller = self },
|
2011-12-21 14:01:50 +00:00
|
|
|
:only => [:create, :destroy, :open_id, :auto_build, :cancel, :publish, :change_visibility] # :update
|
2011-10-14 21:45:58 +01:00
|
|
|
after_filter lambda { EventLog.current_controller = nil }
|
|
|
|
|
2011-10-27 13:49:21 +01:00
|
|
|
helper_method :get_owner
|
2011-11-15 20:05:08 +00:00
|
|
|
|
|
|
|
rescue_from CanCan::AccessDenied do |exception|
|
2011-11-19 11:49:14 +00:00
|
|
|
redirect_to forbidden_url, :alert => t('flash.exception_message')#:alert => exception.message
|
2011-11-15 20:05:08 +00:00
|
|
|
end
|
|
|
|
|
2011-03-31 00:10:23 +01:00
|
|
|
protected
|
2012-01-17 11:48:40 +00:00
|
|
|
|
|
|
|
def set_locale
|
|
|
|
I18n.locale = extract_locale_from_request
|
|
|
|
end
|
|
|
|
|
|
|
|
def extract_locale_from_request
|
|
|
|
get_user_locale || request.env['HTTP_ACCEPT_LANGUAGE'].to_sym || :en
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_user_locale
|
|
|
|
user_signed_in? ? current_user.language : nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_owner
|
2011-11-30 12:58:14 +00:00
|
|
|
# params['user_id'] && User.find_by_id(params['user_id']) ||
|
|
|
|
# params['group_id'] && Group.find_by_id(params['group_id']) || current_user
|
2012-01-17 11:48:40 +00:00
|
|
|
if self.class.method_defined? :parent
|
|
|
|
if parent and (parent.is_a? User or parent.is_a? Group)
|
|
|
|
return parent
|
2011-11-30 12:58:14 +00:00
|
|
|
else
|
2012-01-17 11:48:40 +00:00
|
|
|
return current_user
|
2011-11-30 12:58:14 +00:00
|
|
|
end
|
2012-01-17 11:48:40 +00:00
|
|
|
else
|
|
|
|
params['user_id'] && User.find_by_id(params['user_id']) ||
|
|
|
|
params['group_id'] && Group.find_by_id(params['group_id']) || current_user
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
2012-01-17 11:48:40 +00:00
|
|
|
end
|
2011-10-26 21:57:51 +01:00
|
|
|
|
2012-01-17 11:48:40 +00:00
|
|
|
def layout_by_resource
|
|
|
|
if devise_controller?
|
|
|
|
"sessions"
|
|
|
|
else
|
|
|
|
"application"
|
2011-03-31 00:10:23 +01:00
|
|
|
end
|
2012-01-17 11:48:40 +00:00
|
|
|
end
|
2011-03-09 13:13:36 +00:00
|
|
|
end
|