From 0fbb102929dfcc97a3c365b4dc2c915c0f83c25f Mon Sep 17 00:00:00 2001 From: TLSM Date: Sat, 9 Jul 2022 05:25:15 -0400 Subject: [PATCH] Propagate shadows to new alts on signup. --- files/classes/user.py | 15 +++++++++++++++ files/routes/admin.py | 2 +- files/routes/login.py | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/files/classes/user.py b/files/classes/user.py index 398aa51c0..974c16bd0 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -690,6 +690,21 @@ class User(Base): def is_suspended(self): return (self.is_banned and (self.unban_utc == 0 or self.unban_utc > time.time())) + @property + @lazy + def has_shadowbanned_alts(self): + qty = g.db.execute( + """SELECT COUNT(*) FROM ( + SELECT (CASE + WHEN user1 = :u THEN user2 + WHEN user2 = :u THEN user1 + END) AS id FROM alts + WHERE user1 = :u OR user2 = :u + ) AS a + JOIN users ON a.id = users.id + WHERE users.shadowbanned IS NOT NULL""", + {"u": self.id}).scalar() + return qty > 0 @property @lazy diff --git a/files/routes/admin.py b/files/routes/admin.py index 1d8fe36ca..a3389fd13 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -930,7 +930,7 @@ def shadowban(user_id, v): g.db.add(user) for alt in user.alts: - if alt.admin_level: break + if alt.admin_level: continue alt.shadowbanned = v.username g.db.add(alt) diff --git a/files/routes/login.py b/files/routes/login.py index 66b891d83..0d4e65df6 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -345,6 +345,10 @@ def sign_up_post(v): check_for_alts(new_user.id) + if new_user.has_shadowbanned_alts: + new_user.shadowbanned = "AutoJanny" + g.db.add(new_user) + g.db.commit() send_notification(new_user.id, WELCOME_MSG)