From 11b7c157585b812149637e24bfb930548a13605d Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 4 Aug 2023 00:17:55 +0300 Subject: [PATCH] move over_18 setting to cookies so ppl can have different settings for different devices --- files/classes/user.py | 6 +++++- files/routes/settings.py | 5 ++++- migrations/20230804-move-over_18-setting-to-cookies.sql | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 migrations/20230804-move-over_18-setting-to-cookies.sql diff --git a/files/classes/user.py b/files/classes/user.py index b420232c3..563b24ad3 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -101,7 +101,6 @@ class User(Base): email_verified = Column(Boolean, default=False) shadowbanned = Column(Integer, ForeignKey("users.id")) chudded_by = Column(Integer, ForeignKey("users.id")) - over_18 = Column(Boolean, default=False) hidevotedon = Column(Boolean, default=False) slurreplacer = Column(Integer, default=1) profanityreplacer = Column(Integer, default=1) @@ -263,6 +262,11 @@ class User(Base): def cursormarsey(self): return session.get('cursormarsey', CURSORMARSEY_DEFAULT) + @property + @lazy + def over_18(self): + return session.get('over_18', False) + @property @lazy def num_of_bought_awards(self): diff --git a/files/routes/settings.py b/files/routes/settings.py index 27023de0e..fd7debf50 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -161,7 +161,6 @@ def settings_personal_post(v): updated = updated or update_flag("imginn", "imginn") updated = updated or update_flag("controversial", "controversial") updated = updated or update_flag("sigs_disabled", "sigs_disabled") - updated = updated or update_flag("over_18", "over_18") updated = updated or update_flag("is_private", "private") updated = updated or update_flag("lifetimedonated_visible", "lifetimedonated_visible") @@ -178,6 +177,10 @@ def settings_personal_post(v): updated = True session["cursormarsey"] = int(request.values.get("cursormarsey") == 'true') + elif not updated and request.values.get("over_18", v.over_18) != v.over_18: + updated = True + session["over_18"] = int(request.values.get("over_18") == 'true') + elif not updated and request.values.get("marsify", v.marsify) != v.marsify and v.marsify <= 1: if not v.patron: abort(403, f"Perma-marsify is only available to {patron}s!") diff --git a/migrations/20230804-move-over_18-setting-to-cookies.sql b/migrations/20230804-move-over_18-setting-to-cookies.sql new file mode 100644 index 000000000..991dc9630 --- /dev/null +++ b/migrations/20230804-move-over_18-setting-to-cookies.sql @@ -0,0 +1 @@ +alter table users drop column over_18;