From ba05430a80770955a79c9a0398cafb7229321462 Mon Sep 17 00:00:00 2001 From: TLSM Date: Thu, 1 Sep 2022 16:19:07 -0400 Subject: [PATCH] Prevent permabanned users from replying to DMs. Permabanning already prevents users from initiating new DMs, and we complete this by preventing replying to existing DM chains. New modmails may still be initiated, and existing modmails may still be replied to. --- files/classes/user.py | 5 +++++ files/helpers/wrappers.py | 2 +- files/routes/users.py | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 0399c1bfb..820b34a20 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -720,6 +720,11 @@ 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 is_suspended_permanently(self): + return (self.is_banned and self.unban_utc == 0) + @property @lazy def has_shadowbanned_alts(self): diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index beca91316..7ffaea636 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -138,7 +138,7 @@ def is_not_permabanned(f): check_ban_evade(v) - if v.is_banned and v.unban_utc == 0: + if v.is_suspended_permanently: return {"error": "Internal server error"}, 500 return make_response(f(*args, v=v, **kwargs)) diff --git a/files/routes/users.py b/files/routes/users.py index abc9a9342..1bf374133 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -722,9 +722,7 @@ def message2(v, username): @limiter.limit("1/second;6/minute;50/hour;200/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}') @auth_required def messagereply(v): - body = request.values.get("body", "").strip().replace('‎','') - body = body.replace('\r\n', '\n')[:10000] if not body and not request.files.get("file"): return {"error": "Message is empty!"} @@ -735,6 +733,9 @@ def messagereply(v): parent = get_comment(id, v=v) user_id = parent.author.id + if v.is_suspended_permanently and parent.sentto != 2: + return {"error": "You are permabanned and may not reply to messages."} + if parent.sentto == 2: user_id = None elif v.id == user_id: user_id = parent.sentto