mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Delegator now checks the mapping for the proper failure app.
This commit is contained in:
parent
4629beecd7
commit
24b26026ef
3 changed files with 83 additions and 45 deletions
|
@ -1,7 +1,16 @@
|
||||||
module Devise
|
module Devise
|
||||||
|
# Checks the scope in the given environment and returns the associated failure app.
|
||||||
class Delegator
|
class Delegator
|
||||||
def call(env)
|
def call(env)
|
||||||
Devise::FailureApp.call(env)
|
failure_app(env).call(env)
|
||||||
|
end
|
||||||
|
|
||||||
|
def failure_app(env)
|
||||||
|
app = env["warden.options"] &&
|
||||||
|
(scope = env["warden.options"][:scope]) &&
|
||||||
|
Devise.mappings[scope].failure_app
|
||||||
|
|
||||||
|
app || Devise::FailureApp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -23,7 +23,9 @@ module Devise
|
||||||
#
|
#
|
||||||
class Mapping #:nodoc:
|
class Mapping #:nodoc:
|
||||||
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
|
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
|
||||||
:class_name, :sign_out_via, :format, :used_routes, :used_helpers
|
:class_name, :sign_out_via, :format, :used_routes, :used_helpers,
|
||||||
|
:constraints, :defaults, :failure_app
|
||||||
|
|
||||||
alias :name :singular
|
alias :name :singular
|
||||||
|
|
||||||
# Receives an object and find a scope for it. If a scope cannot be found,
|
# Receives an object and find a scope for it. If a scope cannot be found,
|
||||||
|
@ -51,46 +53,21 @@ module Devise
|
||||||
@singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym
|
@singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym
|
||||||
|
|
||||||
@class_name = (options[:class_name] || name.to_s.classify).to_s
|
@class_name = (options[:class_name] || name.to_s.classify).to_s
|
||||||
@ref = Devise.ref(@class_name)
|
@klass = Devise.ref(@class_name)
|
||||||
|
|
||||||
@path = (options[:path] || name).to_s
|
@path = (options[:path] || name).to_s
|
||||||
@path_prefix = options[:path_prefix]
|
@path_prefix = options[:path_prefix]
|
||||||
|
|
||||||
mod = options[:module] || "devise"
|
|
||||||
@controllers = Hash.new { |h,k| h[k] = "#{mod}/#{k}" }
|
|
||||||
@controllers.merge!(options[:controllers] || {})
|
|
||||||
@controllers.each { |k,v| @controllers[k] = v.to_s }
|
|
||||||
|
|
||||||
@path_names = Hash.new { |h,k| h[k] = k.to_s }
|
|
||||||
@path_names.merge!(:registration => "")
|
|
||||||
@path_names.merge!(options[:path_names] || {})
|
|
||||||
|
|
||||||
@constraints = Hash.new { |h,k| h[k] = k.to_s }
|
|
||||||
@constraints.merge!(options[:constraints] || {})
|
|
||||||
|
|
||||||
@defaults = Hash.new { |h,k| h[k] = k.to_s }
|
|
||||||
@defaults.merge!(options[:defaults] || {})
|
|
||||||
|
|
||||||
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
|
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
|
||||||
@format = options[:format]
|
@format = options[:format]
|
||||||
|
|
||||||
singularizer = lambda { |s| s.to_s.singularize.to_sym }
|
default_failure_app(options)
|
||||||
|
default_controllers(options)
|
||||||
if options.has_key?(:only)
|
default_path_names(options)
|
||||||
@used_routes = self.routes & Array(options[:only]).map(&singularizer)
|
default_constraints(options)
|
||||||
elsif options[:skip] == :all
|
default_defaults(options)
|
||||||
@used_routes = []
|
default_used_route(options)
|
||||||
else
|
default_used_helpers(options)
|
||||||
@used_routes = self.routes - Array(options[:skip]).map(&singularizer)
|
|
||||||
end
|
|
||||||
|
|
||||||
if options[:skip_helpers] == true
|
|
||||||
@used_helpers = @used_routes
|
|
||||||
elsif skip = options[:skip_helpers]
|
|
||||||
@used_helpers = self.routes - Array(skip).map(&singularizer)
|
|
||||||
else
|
|
||||||
@used_helpers = self.routes
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return modules for the mapping.
|
# Return modules for the mapping.
|
||||||
|
@ -100,7 +77,7 @@ module Devise
|
||||||
|
|
||||||
# Gives the class the mapping points to.
|
# Gives the class the mapping points to.
|
||||||
def to
|
def to
|
||||||
@ref.get
|
@klass.get
|
||||||
end
|
end
|
||||||
|
|
||||||
def strategies
|
def strategies
|
||||||
|
@ -123,12 +100,8 @@ module Devise
|
||||||
"/#{@path_prefix}/#{@path}".squeeze("/")
|
"/#{@path_prefix}/#{@path}".squeeze("/")
|
||||||
end
|
end
|
||||||
|
|
||||||
def constraints
|
def failure_app
|
||||||
@constraints
|
Devise::FailureApp
|
||||||
end
|
|
||||||
|
|
||||||
def defaults
|
|
||||||
@defaults
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create magic predicates for verifying what module is activated by this map.
|
# Create magic predicates for verifying what module is activated by this map.
|
||||||
|
@ -145,5 +118,62 @@ module Devise
|
||||||
end
|
end
|
||||||
METHOD
|
METHOD
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def default_failure_app(options)
|
||||||
|
@failure_app = options[:failure_app] || Devise::FailureApp
|
||||||
|
if @failure_app.is_a?(String)
|
||||||
|
ref = Devise.ref(@failure_app)
|
||||||
|
@failure_app = lambda { |env| ref.get.call(env) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_controllers(options)
|
||||||
|
mod = options[:module] || "devise"
|
||||||
|
@controllers = Hash.new { |h,k| h[k] = "#{mod}/#{k}" }
|
||||||
|
@controllers.merge!(options[:controllers]) if options[:controllers]
|
||||||
|
@controllers.each { |k,v| @controllers[k] = v.to_s }
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_path_names(options)
|
||||||
|
@path_names = Hash.new { |h,k| h[k] = k.to_s }
|
||||||
|
@path_names[:registration] = ""
|
||||||
|
@path_names.merge!(options[:path_names]) if options[:path_names]
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_constraints(options)
|
||||||
|
@constraints = Hash.new
|
||||||
|
@constraints.merge!(options[:constraints]) if options[:constraints]
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_defaults(options)
|
||||||
|
@defaults = Hash.new
|
||||||
|
@defaults.merge!(options[:defaults]) if options[:defaults]
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_used_route(options)
|
||||||
|
singularizer = lambda { |s| s.to_s.singularize.to_sym }
|
||||||
|
|
||||||
|
if options.has_key?(:only)
|
||||||
|
@used_routes = self.routes & Array(options[:only]).map(&singularizer)
|
||||||
|
elsif options[:skip] == :all
|
||||||
|
@used_routes = []
|
||||||
|
else
|
||||||
|
@used_routes = self.routes - Array(options[:skip]).map(&singularizer)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_used_helpers(options)
|
||||||
|
singularizer = lambda { |s| s.to_s.singularize.to_sym }
|
||||||
|
|
||||||
|
if options[:skip_helpers] == true
|
||||||
|
@used_helpers = @used_routes
|
||||||
|
elsif skip = options[:skip_helpers]
|
||||||
|
@used_helpers = self.routes - Array(skip).map(&singularizer)
|
||||||
|
else
|
||||||
|
@used_helpers = self.routes
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -203,7 +203,6 @@ Devise.setup do |config|
|
||||||
# change the failure app, you can configure them inside the config.warden block.
|
# change the failure app, you can configure them inside the config.warden block.
|
||||||
#
|
#
|
||||||
# config.warden do |manager|
|
# config.warden do |manager|
|
||||||
# manager.failure_app = AnotherApp
|
|
||||||
# manager.intercept_401 = false
|
# manager.intercept_401 = false
|
||||||
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
||||||
# end
|
# end
|
||||||
|
|
Loading…
Reference in a new issue