app/controllers/alchemy/base_controller.rb in alchemy_cms-3.2.0.beta vs app/controllers/alchemy/base_controller.rb in alchemy_cms-3.2.0.rc1

- old
+ new

@@ -1,19 +1,19 @@ # This is the main Alchemy controller all other controllers inherit from. # module Alchemy class BaseController < ApplicationController + include Alchemy::ConfigurationMethods include Alchemy::ControllerActions include Alchemy::Modules + include Alchemy::SSLProtection protect_from_forgery before_action :mailer_set_url_options before_action :set_locale - helper_method :multi_site? - helper 'alchemy/admin/form' rescue_from CanCan::AccessDenied do |exception| permission_denied(exception) end @@ -24,30 +24,14 @@ # def set_locale ::I18n.locale = Language.current.code end - # Returns the configuration value of given key. - # - # Config file is in +config/alchemy/config.yml+ - # - def configuration(name) - Alchemy::Config.get(name) + def not_found_error!(msg = "Not found \"#{request.fullpath}\"") + raise ActionController::RoutingError.new(msg) end - def multi_language? - Language.published.count > 1 - end - - def multi_site? - Site.count > 1 - end - - def raise_not_found_error - raise ActionController::RoutingError.new('Not Found') - end - # Shortcut for Alchemy::I18n.translate method def _t(key, *args) I18n.t(key, *args) end @@ -59,42 +43,10 @@ def mailer_set_url_options ActionMailer::Base.default_url_options[:host] = request.host_with_port end - def render_404(exception = nil) - if exception - logger.info "Rendering 404: #{exception.message}" - end - render :file => Rails.root.join("public/404.html"), :status => 404, :layout => false - end - - # Enforce ssl for login and all admin modules. - # - # Default is +false+ - # - # === Usage - # - # # config/alchemy/config.yml - # ... - # require_ssl: true - # ... - # - # === Note - # - # You have to create a ssl certificate - # if you want to use the ssl protection. - # - def ssl_required? - !Rails.env.test? && configuration(:require_ssl) - end - - # Redirects current request to https. - def enforce_ssl - redirect_to url_for(request.params.merge(protocol: 'https')) - end - protected def permission_denied(exception = nil) if exception Rails.logger.debug <<-WARN @@ -148,12 +100,7 @@ # 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 - - def raise_authorization_exception(exception) - raise("Not permitted to #{exception.action} #{exception.subject}") - end - end end