1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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:
Ricardo Díaz 2021-05-18 21:26:24 -05:00
parent a34d64d82e
commit ca7c820c69
4 changed files with 11 additions and 20 deletions

View file

@ -199,6 +199,10 @@ module ActionController #:nodoc:
def exists?
true
end
def enabled?
false
end
end
class NullCookieJar < ActionDispatch::Cookies::CookieJar #:nodoc:

View file

@ -211,6 +211,10 @@ module ActionController
@data.fetch(key.to_s, *args, &block)
end
def enabled?
true
end
private
def load!
@id

View file

@ -45,7 +45,6 @@ module ActionDispatch
# 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 @@ module ActionDispatch
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 @@ module ActionDispatch
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