Clarify permabanned forbidden messages.

Fixes #221. Provides custom message behavior for the user DM route
and slightly refactors the `@is_not_permabanned` wrapper to not be
deliberately misleading to users.
This commit is contained in:
TLSM 2022-08-30 13:35:02 -04:00
parent e1244e9496
commit b2773cbb40
No known key found for this signature in database
GPG key ID: E745A82778055C7E
3 changed files with 9 additions and 3 deletions

View file

@ -617,6 +617,9 @@ class User(Base):
def is_suspended(self): def is_suspended(self):
return (self.is_banned and (self.unban_utc == 0 or self.unban_utc > time.time())) return (self.is_banned and (self.unban_utc == 0 or self.unban_utc > time.time()))
@property
def is_suspended_permanently(self):
return (self.is_banned and self.unban_utc == 0)
@property @property
@lazy @lazy

View file

@ -91,8 +91,8 @@ def is_not_permabanned(f):
check_ban_evade(v) check_ban_evade(v)
if v.is_banned and v.unban_utc == 0: if v.is_suspended_permanently:
return {"error": "Interal server error"}, 500 return {"error": "Forbidden: you are permabanned."}, 403
g.v = v g.v = v
return make_response(f(*args, v=v, **kwargs)) return make_response(f(*args, v=v, **kwargs))

View file

@ -562,8 +562,11 @@ def reportbugs(v):
@app.post("/@<username>/message") @app.post("/@<username>/message")
@limiter.limit("1/second;10/minute;20/hour;50/day") @limiter.limit("1/second;10/minute;20/hour;50/day")
@is_not_permabanned @auth_required
def message2(v, username): def message2(v, username):
if v.is_suspended_permanently:
return {"error": "You have been permabanned and cannot send messages; " + \
"contact modmail if you think this decision was incorrect."}, 403
user = get_user(username, v=v) user = get_user(username, v=v)
if hasattr(user, 'is_blocking') and user.is_blocking: return {"error": "You're blocking this user."}, 403 if hasattr(user, 'is_blocking') and user.is_blocking: return {"error": "You're blocking this user."}, 403