app/controllers/alchemy/base_controller.rb in alchemy_cms-2.5.3.1 vs app/controllers/alchemy/base_controller.rb in alchemy_cms-2.6.0.rc5
- old
+ new
@@ -8,22 +8,17 @@
before_filter :set_current_site
before_filter :set_language
before_filter :mailer_set_url_options
before_filter :store_user_request_time
+ before_filter :set_authorization_user
helper_method :current_server, :current_site, :multi_site?
# Returns a host string with the domain the app is running on.
def current_server
- # For local development server
- if request.port != 80
- "#{request.protocol}#{request.host}:#{request.port}"
- # For remote production server
- else
- "#{request.protocol}#{request.host}"
- end
+ "#{request.protocol}#{request.host_with_port}"
end
# Returns the configuratin value of given key.
#
# Config file is in +config/alchemy/config.yml+
@@ -62,10 +57,16 @@
#
def set_current_site
Site.current = current_site
end
+ # Stores the current_user for declarative_authorization
+ #
+ def set_authorization_user
+ Authorization.current_user = current_user
+ end
+
# Sets Alchemy's GUI translation to users preffered language and stores it in the session.
#
# Guesses the language from browser locale. If not successful it takes the default.
#
# You can set the default translation in your +config/application.rb+ file, via Rails +default_locale+ config option.
@@ -201,13 +202,11 @@
protected
def permission_denied
if current_user
- if current_user.role == 'registered'
- redirect_to alchemy.root_path
- else
+ if permitted_to? :index_alchemy_admin_dashboard
if request.referer == alchemy.login_url
render :file => Rails.root.join('public/422'), :status => 422
elsif request.xhr?
respond_to do |format|
format.js {
@@ -219,19 +218,27 @@
end
else
flash[:error] = _t('You are not authorized')
redirect_to alchemy.admin_dashboard_path
end
+ else
+ redirect_to alchemy.root_path
end
else
flash[:info] = _t('Please log in')
if request.xhr?
render :action => :permission_denied
else
store_location
redirect_to alchemy.login_path
end
end
+ end
+
+ # Logs the current exception to the error log.
+ def exception_logger(e)
+ Rails.logger.error("\n#{e.class} #{e.message} in #{e.backtrace.first}")
+ Rails.logger.error(e.backtrace[1..50].each { |l| l.gsub(/#{Rails.root.to_s}/, '') }.join("\n"))
end
end
end