app/controllers/skyline/application_controller.rb in skylinecms-3.1.0 vs app/controllers/skyline/application_controller.rb in skylinecms-3.2.0
- old
+ new
@@ -8,24 +8,26 @@
around_filter Skyline::ArticleVersionObserver.instance
class_inheritable_accessor :default_menu
attr_accessor :current_menu
- hide_action :default_menu, :default_menu=, :current_menu, :current_menu=, :menu
+ hide_action :default_menu, :default_menu=, :current_menu, :current_menu=, :menu, :javascript_redirect_to
# Load all helpers
Dir[Skyline.root + "app/helpers/**/*_helper.rb"].each do |helper|
- helper helper.sub(Skyline.root + "app/helpers/","").sub(/_helper\.rb$/,"")
+ helper helper.sub(/^#{Regexp.escape((Skyline.root + "app/helpers/").to_s)}/,"").sub(/_helper\.rb$/,"")
end
# Load all plugin helpers so they can override stuff.
- Dir[Skyline::PluginsManager.plugin_path + "*/app/helpers/**/*_helper.rb"].each do |helper|
- helper helper.sub(/^#{Regexp.escape(Skyline::PluginsManager.plugin_path.to_s)}\/?.+?\/app\/helpers\//,"").sub(/_helper\.rb$/,"")
+ Dir[Rails.application.config.skyline_plugins_manager.plugin_path + "*/app/helpers/**/*_helper.rb"].each do |helper|
+ helper helper.sub(/^#{Regexp.escape(Rails.application.config.skyline_plugins_manager.plugin_path.to_s)}\/?.+?\/app\/helpers\//,"").sub(/_helper\.rb$/,"")
end
+ define_callbacks :authenticate
+
class << self
# Authorize a list of actions by a certain right
#
# ==== Parameters
@@ -55,57 +57,53 @@
def authorizations
read_inheritable_attribute(:authorizations) || {}
end
- def insert_before_filter_after(identifier,*filters,&block)
- pos = 0
- filter_chain.each_with_index do |f,i|
- if f.identifier == identifier
- pos = i
- break
- end
- end
- self.filter_chain.send(:update_filter_chain,filters, :before,pos+1, &block)
- end
-
end
protected
# Sets locale according to the configuration on every request
def set_locale
I18n.locale = Skyline::Configuration.locale.present? ? Skyline::Configuration.locale : "en-US"
end
- def default_url_options(options=nil)
- return if options.nil?
+ def default_url_options(options={})
+ return {} if options.blank?
if options[:id].andand.kind_of?(Skyline::Article)
{:type => options[:id].class}
elsif options[:article_id].andand.kind_of?(Skyline::Article)
{:article_type => options[:article_id].class}
end
end
# Returns the currently logged in user
# --
def current_user
- @current_user
+ (self.respond_to?(:skyline_current_user) ? self.skyline_current_user : nil) || @current_user
end
helper_method :current_user
+ def current_user=(c)
+ @current_user = c
+ end
+
# Override this in the controller, all actions are protected by default
def protect?; true; end
# Authenticate the user
def authenticate_user
if self.protect?
- unless session[:user_id] && @current_user = Skyline::User.find_by_id(session[:user_id])
- # Store location to go back to in session...
- session[:before_login_url] = request.request_uri
- return redirect_to(new_skyline_authentication_path)
+ run_callbacks :authenticate do
+ self.current_user = Skyline::Configuration.user_class.find_by_identification(session[:skyline_user_identification]) if !self.current_user && session[:skyline_user_identification]
+ unless self.current_user
+ # Store location to go back to in session...
+ session[:before_login_url] = request.fullpath
+ return redirect_to(new_skyline_authentication_path)
+ end
end
end
end
# Handle the user preferences
@@ -169,11 +167,11 @@
# Handle an unauthorized user
# Currently just logs an [AUTH] message and renders an UNAUTHORIZED text on the screen
# --
def handle_unauthorized_user
- logger.warn("[AUTH] Unauthorized access to #{self.controller_name}/#{self.action_name} by #{@current_user.email} (#{@current_user.id})")
+ logger.warn("[AUTH] Unauthorized access to #{self.controller_name}/#{self.action_name} by #{current_user.email} (ID=#{current_user.id})")
render(:text => "UNAUTHORIZED", :status => :unauthorized)
end
# Set the current menu item
#
@@ -193,11 +191,11 @@
# Messages work just like Flashes, so you can do
# messages.now[:error] and messages[:error]
#--
def messages
unless defined? @_messages
- @_messages = session["_messages"] ||= ActionController::Flash::FlashHash.new
+ @_messages = session["_messages"] ||= ActionDispatch::Flash::FlashHash.new
@_messages.sweep
end
@_messages
end
helper_method :messages
@@ -210,11 +208,11 @@
# notifications should be rendered as volatile, they should
# dissapear after some time from the GUI.
#--
def notifications
unless defined? @_notifications
- @_notifications = session["_notifications"] ||= ActionController::Flash::FlashHash.new
+ @_notifications = session["_notifications"] ||= ActionDispatch::Flash::FlashHash.new
@_notifications.sweep
end
@_notifications
end
helper_method :notifications
@@ -241,11 +239,12 @@
end
def stack
return @stack if @stack
- @stack ||= Skyline::Content::Stack.new(@implementation,params[:types] || [])
+ types = params[:types].kind_of?(String) ? params[:types].split("/") : params[:types]
+ @stack ||= Skyline::Content::Stack.new(@implementation, types || [])
@class = @stack.klass
logger.debug "STACK classes: " + @stack.collect{|s| s.class}.inspect
logger.debug "STACK: " + @stack.inspect
@stack
@@ -287,6 +286,11 @@
url_for options.update(:types => types)
end
helper_method :object_url
+
+ def javascript_redirect_to(url)
+ render :js => "window.location = '#{url.to_s.html_safe}';"
+ end
+
end