Set preferences before conditional breaks in before_all (#1412)

This commit is contained in:
Matthew McGarvey 2020-10-16 05:23:18 -05:00 committed by GitHub
parent 0f643daac6
commit d571573e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -246,12 +246,13 @@ spawn do
end end
before_all do |env| before_all do |env|
begin preferences = begin
preferences = Preferences.from_json(env.request.cookies["PREFS"]?.try &.value || "{}") Preferences.from_json(env.request.cookies["PREFS"]?.try &.value || "{}")
rescue rescue
preferences = Preferences.from_json("{}") Preferences.from_json("{}")
end end
env.set "preferences", preferences
env.response.headers["X-XSS-Protection"] = "1; mode=block" env.response.headers["X-XSS-Protection"] = "1; mode=block"
env.response.headers["X-Content-Type-Options"] = "nosniff" env.response.headers["X-Content-Type-Options"] = "nosniff"
extra_media_csp = "" extra_media_csp = ""
@ -298,6 +299,7 @@ before_all do |env|
}, HMAC_KEY, PG_DB, 1.week) }, HMAC_KEY, PG_DB, 1.week)
preferences = user.preferences preferences = user.preferences
env.set "preferences", preferences
env.set "sid", sid env.set "sid", sid
env.set "csrf_token", csrf_token env.set "csrf_token", csrf_token
@ -319,6 +321,7 @@ before_all do |env|
}, HMAC_KEY, PG_DB, 1.week) }, HMAC_KEY, PG_DB, 1.week)
preferences = user.preferences preferences = user.preferences
env.set "preferences", preferences
env.set "sid", sid env.set "sid", sid
env.set "csrf_token", csrf_token env.set "csrf_token", csrf_token
@ -336,7 +339,6 @@ before_all do |env|
preferences.dark_mode = dark_mode preferences.dark_mode = dark_mode
preferences.thin_mode = thin_mode preferences.thin_mode = thin_mode
preferences.locale = locale preferences.locale = locale
env.set "preferences", preferences
current_page = env.request.path current_page = env.request.path
if env.request.query if env.request.query