From d1bc2f346858b58c8b4f28b1fa17b32f10369165 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 23 Sep 2022 14:33:58 +0200 Subject: [PATCH] integrate check_ban_evade into check_for_alts --- files/classes/user.py | 17 ----------------- files/helpers/wrappers.py | 4 +--- files/routes/admin.py | 5 +++++ files/routes/login.py | 17 ++++++++++++----- files/routes/users.py | 2 ++ 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index c8db922e0c..cb522df36a 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -832,23 +832,6 @@ class User(Base): def is_suspended_permanently(self): return (self.is_banned and self.unban_utc == 0) - @lazy - def check_ban_evade(self): - for u in self.alts_unique: - if u.shadowbanned: - self.shadowbanned = u.shadowbanned - g.db.add(self) - g.db.commit() - return - ## Disabled pending better solution: permabans haven't propagated for - ## most of Summer 2022. We've gotten somewhat used to this. Think we only - ## want them to propagate on account creation? Or at least needs discussion. - # if u.is_suspended_permanently: - # self.shadowbanned = u.banned_by.username - # g.db.add(self) - # g.db.commit() - # return - @property @lazy def applications(self): diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 0001337a43..e58fd72cba 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -77,9 +77,7 @@ def get_logged_in_user(): g.v = v - if v: - v.poor = session.get('poor') - v.check_ban_evade() + if v: v.poor = session.get('poor') if AEVANN_ID and request.headers.get("Cf-Ipcountry") == 'EG': if v and not v.username.startswith('Aev'): diff --git a/files/routes/admin.py b/files/routes/admin.py index a4c7221d60..e13582386d 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -15,6 +15,7 @@ from files.classes import * from flask import * from files.__main__ import app, cache, limiter from .front import frontlist +from .login import check_for_alts from files.helpers.discord import add_role import datetime import requests @@ -772,6 +773,10 @@ def admin_link_accounts(v): ) g.db.add(new_alt) + g.db.flush() + + check_for_alts(g.db.get(User, u1)) + check_for_alts(g.db.get(User, u2)) ma = ModAction( kind="link_accounts", diff --git a/files/routes/login.py b/files/routes/login.py index 5ca6aff5b2..61e9e2aa39 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -21,7 +21,8 @@ def login_get(v): return render_template("login.html", failed=False, redirect=redir) -def check_for_alts(current_id): +def check_for_alts(current): + current_id = current.id ids = [x[0] for x in g.db.query(User.id).all()] past_accs = set(session.get("history", [])) @@ -78,6 +79,14 @@ def check_for_alts(current_id): past_accs.add(current_id) session["history"] = list(past_accs) + g.db.flush() + for u in current.alts_unique: + if u.shadowbanned: + current.shadowbanned = u.shadowbanned + g.db.add(current) + elif current.shadowbanned: + u.shadowbanned = current.shadowbanned + g.db.add(u) @app.post("/login") @@ -154,8 +163,7 @@ def on_login(account, redir=None): session["lo_user"] = account.id session["login_nonce"] = account.login_nonce if account.id == AEVANN_ID: session["verified"] = time.time() - - check_for_alts(account.id) + check_for_alts(account) @app.get("/me") @app.get("/@me") @@ -355,8 +363,7 @@ def sign_up_post(v): send_verification_email(new_user) - check_for_alts(new_user.id) - new_user.check_ban_evade() + check_for_alts(new_user) send_notification(new_user.id, WELCOME_MSG) diff --git a/files/routes/users.py b/files/routes/users.py index 14020806c5..0645cf010c 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -19,6 +19,7 @@ import gevent from sys import stdout import os import json +from .login import check_for_alts def leaderboard_thread(): db = db_session() @@ -1332,6 +1333,7 @@ def fp(v, fp): g.db.add(new_alt) g.db.flush() print(v.username + ' + ' + u.username, flush=True) + check_for_alts(v) g.db.add(v) return '', 204