From 27f5823dee07192f9e47164054a2051392e57bd9 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 19 Oct 2024 06:42:32 +0300 Subject: [PATCH] increase ban reason char limit --- files/classes/user.py | 2 +- files/helpers/config/const.py | 3 +++ files/routes/admin.py | 12 ++++++------ files/routes/jinja2.py | 2 +- files/templates/modals/punish.html | 2 +- files/templates/userpage/admintools.html | 4 ++-- ...241019-increase-rendered-ban-reason-charlimit.sql | 2 ++ 7 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 migrations/20241019-increase-rendered-ban-reason-charlimit.sql diff --git a/files/classes/user.py b/files/classes/user.py index 3b879143c..122582a78 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -1149,7 +1149,7 @@ class User(Base): def ban(self, admin=None, reason=None, days=0.0): - if len(reason) > 256: + if len(reason) > BAN_REASON_HTML_LENGTH_LIMIT: stop(400, "Rendered ban reason is too long!") g.db.add(self) diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 49430693e..c20d31f48 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -920,6 +920,9 @@ HOLE_BANNER_LIMIT = 10 BIO_FRIENDS_ENEMIES_LENGTH_LIMIT = 5000 # do not make larger without altering the table BIO_FRIENDS_ENEMIES_HTML_LENGTH_LIMIT = 20000 # do not make larger without altering the table +BAN_REASON_LENGTH_LIMIT = 500 +BAN_REASON_HTML_LENGTH_LIMIT = 5000 # do not make larger without altering the table + COSMETIC_AWARD_COIN_AWARD_PCT = 0.50 TRUESCORE_MINIMUM = 0 diff --git a/files/routes/admin.py b/files/routes/admin.py index b09a57050..13ed30480 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -883,12 +883,12 @@ def shadowban(user_id, v): if not reason: stop(400, "You need to submit a reason for shadowbanning!") - if len(reason) > 256: - stop(400, "Shadowban reason is too long (max 256 characters)") + if len(reason) > BAN_REASON_LENGTH_LIMIT: + stop(400, f"Shadowban reason is too long (max {BAN_REASON_LENGTH_LIMIT} characters)") reason = filter_emojis_only(reason) - if len(reason) > 256: + if len(reason) > BAN_REASON_HTML_LENGTH_LIMIT: stop(400, "Rendered shadowban reason is too long!") user.shadowban_reason = reason @@ -1029,12 +1029,12 @@ def ban_user(fullname, v): if not reason: stop(400, "You need to submit a reason for banning!") - if len(reason) > 256: - stop(400, "Ban reason is too long (max 256 characters)") + if len(reason) > BAN_REASON_LENGTH_LIMIT: + stop(400, f"Ban reason is too long (max {BAN_REASON_LENGTH_LIMIT} characters)") reason = filter_emojis_only(reason) - if len(reason) > 256: + if len(reason) > BAN_REASON_HTML_LENGTH_LIMIT: stop(400, "Rendered ban reason is too long!") reason = reason_regex_post.sub(r'\1', reason) diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index b973e5b24..2dd4f9e74 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -205,5 +205,5 @@ def inject_constants(): "emoji_count":emoji_count, "group_count":group_count, "user_count":user_count, "HOLE_SIDEBAR_COLUMN_LENGTH":HOLE_SIDEBAR_COLUMN_LENGTH, "HOLE_SNAPPY_QUOTES_LENGTH":HOLE_SNAPPY_QUOTES_LENGTH, "USER_SNAPPY_QUOTES_LENGTH":USER_SNAPPY_QUOTES_LENGTH, "top_poster_of_the_day":top_poster_of_the_day, "CATEGORIES_ICONS":CATEGORIES_ICONS, "CATEGORIES_HOLES":CATEGORIES_HOLES, - "HOLE_COST":HOLE_COST, + "HOLE_COST":HOLE_COST, "BAN_REASON_LENGTH_LIMIT":BAN_REASON_LENGTH_LIMIT, } diff --git a/files/templates/modals/punish.html b/files/templates/modals/punish.html index 0a13a66f1..7380d45df 100644 --- a/files/templates/modals/punish.html +++ b/files/templates/modals/punish.html @@ -11,7 +11,7 @@ - + diff --git a/files/templates/userpage/admintools.html b/files/templates/userpage/admintools.html index 3fc878bcc..45bd1efde 100644 --- a/files/templates/userpage/admintools.html +++ b/files/templates/userpage/admintools.html @@ -60,7 +60,7 @@ {% if v.admin_level >= PERMS['USER_BAN'] %}
- +
@@ -74,7 +74,7 @@ {% if v.admin_level >= PERMS['USER_SHADOWBAN'] %} - + diff --git a/migrations/20241019-increase-rendered-ban-reason-charlimit.sql b/migrations/20241019-increase-rendered-ban-reason-charlimit.sql new file mode 100644 index 000000000..fd6b4d17d --- /dev/null +++ b/migrations/20241019-increase-rendered-ban-reason-charlimit.sql @@ -0,0 +1,2 @@ +alter table users alter column ban_reason type varchar(5000); +alter table users alter column shadowban_reason type varchar(5000);