Remove ActionDispatch::Flash::NullFlash
After #42167, all apps (except api only ones) have access to the flash module. If the session store is disabled, then an empty flash object is used. This patch also prevents the flash from being committed to the session if this is not enabled.
This commit is contained in:
parent
a34d64d82e
commit
ca7c820c69
@ -199,6 +199,10 @@ def destroy; end
|
||||
def exists?
|
||||
true
|
||||
end
|
||||
|
||||
def enabled?
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
class NullCookieJar < ActionDispatch::Cookies::CookieJar #:nodoc:
|
||||
|
@ -211,6 +211,10 @@ def fetch(key, *args, &block)
|
||||
@data.fetch(key.to_s, *args, &block)
|
||||
end
|
||||
|
||||
def enabled?
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
def load!
|
||||
@id
|
||||
|
@ -45,7 +45,6 @@ module RequestMethods
|
||||
# read a notice you put there or <tt>flash["notice"] = "hello"</tt>
|
||||
# to put a new one.
|
||||
def flash
|
||||
return Flash::NullFlash unless session.respond_to?(:loaded?)
|
||||
flash = flash_hash
|
||||
return flash if flash
|
||||
self.flash = Flash::FlashHash.from_session_value(session["flash"])
|
||||
@ -60,16 +59,14 @@ def flash_hash # :nodoc:
|
||||
end
|
||||
|
||||
def commit_flash # :nodoc:
|
||||
session = self.session || {}
|
||||
flash_hash = self.flash_hash
|
||||
return unless session.enabled?
|
||||
|
||||
if flash_hash && (flash_hash.present? || session.key?("flash"))
|
||||
session["flash"] = flash_hash.to_session_value
|
||||
self.flash = flash_hash.dup
|
||||
end
|
||||
|
||||
if (!session.respond_to?(:loaded?) || session.loaded?) && # reset_session uses {}, which doesn't implement #loaded?
|
||||
session.key?("flash") && session["flash"].nil?
|
||||
if session.loaded? && session.key?("flash") && session["flash"].nil?
|
||||
session.delete("flash")
|
||||
end
|
||||
end
|
||||
@ -80,20 +77,6 @@ def reset_session # :nodoc:
|
||||
end
|
||||
end
|
||||
|
||||
module NullFlash #:nodoc:
|
||||
class << self
|
||||
def []=(k, v); end
|
||||
|
||||
def [](k); end
|
||||
|
||||
def alert=(message); end
|
||||
|
||||
def notice=(message); end
|
||||
|
||||
def empty?; end
|
||||
end
|
||||
end
|
||||
|
||||
class FlashNow #:nodoc:
|
||||
attr_accessor :flash
|
||||
|
||||
|
@ -244,7 +244,7 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest
|
||||
SessionKey = "_myapp_session"
|
||||
Generator = ActiveSupport::CachingKeyGenerator.new(
|
||||
ActiveSupport::KeyGenerator.new("b3c631c314c0bbca50c1b2843150fe33", iterations: 1000)
|
||||
)
|
||||
)
|
||||
Rotations = ActiveSupport::Messages::RotationConfiguration.new
|
||||
SIGNED_COOKIE_SALT = "signed cookie"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user