Commit 3ada432a authored by Deimos's avatar Deimos

Stop fixing old Solarized theme cookies

This was done for over 10 months now, there shouldn't really be any old
ones left to fix at this point.
parent a1e30527
......@@ -31,9 +31,6 @@ _COUNTERS = {
"login_failures": Counter("tildes_login_failures_total", "Login Failures"),
"messages": Counter("tildes_messages_total", "Messages", labelnames=["type"]),
"registrations": Counter("tildes_registrations_total", "User Registrations"),
"theme_cookie_tween_sets": Counter(
"tildes_theme_cookie_tween_sets_total", "Theme Cookies Set by Tween"
),
"topics": Counter("tildes_topics_total", "Topics", labelnames=["type"]),
"subscriptions": Counter("tildes_subscriptions_total", "Subscriptions"),
"unsubscriptions": Counter("tildes_unsubscriptions_total", "Unsubscriptions"),
......
......@@ -12,8 +12,6 @@ from pyramid.registry import Registry
from pyramid.request import Request
from pyramid.response import Response
from tildes.metrics import incr_counter
def http_method_tween_factory(handler: Callable, registry: Registry) -> Callable:
# pylint: disable=unused-argument
......@@ -79,9 +77,6 @@ def theme_cookie_tween_factory(handler: Callable, registry: Registry) -> Callabl
but doesn't already have a theme cookie. This is necessary so that their default
theme will apply to the Blog and Docs sites as well, since those sites are
static and can't look up the user's default theme in the database.
Temporarily, this tween is also being used to convert old theme cookies with
"light" or "dark" values to the new "solarized-light" and "solarized-dark" ones.
"""
response = handler(request)
......@@ -89,30 +84,22 @@ def theme_cookie_tween_factory(handler: Callable, registry: Registry) -> Callabl
if request.method.upper() != "GET":
return response
current_theme = request.cookies.get("theme", "")
# if they already have a valid theme cookie, we don't need to do anything
if current_theme and current_theme not in ("light", "dark"):
# if they already have a theme cookie, we don't need to do anything
if request.cookies.get("theme", ""):
return response
if current_theme in ("light", "dark"):
# add the "solarized-" prefix to "light" / "dark" values
new_theme = "solarized-" + current_theme
elif request.user and request.user.theme_default:
# otherwise (no theme cookie), set as the user's default
new_theme = request.user.theme_default
else:
# if the user isn't logged in or doesn't have a default, do nothing
# if the user doesn't have a default theme, we don't need to do anything
if not request.user or not request.user.theme_default:
return response
# set a cookie with the user's default theme
response.set_cookie(
"theme",
new_theme,
request.user.theme_default,
max_age=315360000,
secure=True,
domain="." + request.domain,
)
incr_counter("theme_cookie_tween_sets")
return response
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment