From cf264bae48e7b0f9f25f75be309278abb2bd922f Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 11 Feb 2024 16:40:22 +0200 Subject: [PATCH] add shadowban_reason column to stop the endless confusion and overwriting --- files/classes/user.py | 1 + files/helpers/actions.py | 2 +- files/helpers/sanitize.py | 2 +- files/routes/admin.py | 14 +++++++------- files/routes/awards.py | 3 +-- files/routes/routehelpers.py | 9 ++------- files/templates/admin/shadowbanned.html | 2 +- files/templates/admin/shadowbanned_tooltip.html | 2 +- files/templates/userpage/admintools.html | 2 +- migrations/20240211-add-shadowban-reason.sql | 3 +++ 10 files changed, 19 insertions(+), 21 deletions(-) create mode 100644 migrations/20240211-add-shadowban-reason.sql diff --git a/files/classes/user.py b/files/classes/user.py index 45d80591a..af7e39582 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -115,6 +115,7 @@ class User(Base): is_banned = Column(Integer, ForeignKey("users.id")) unban_utc = Column(Integer) ban_reason = deferred(Column(String)) + shadowban_reason = deferred(Column(String)) is_muted = Column(Boolean, default=False) login_nonce = Column(Integer, default=0) coins = Column(Integer, default=DEFAULT_COINS) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index e4bf16994..955c7fd6c 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -540,7 +540,7 @@ def execute_under_siege(v, target, body, kind): if v.shadowbanned: return v.shadowbanned = AUTOJANNY_ID - v.ban_reason = "Under Siege" + v.shadowban_reason = "Under Siege" g.db.add(v) if kind == "report": diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 4a11d9af3..62da5df83 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -148,7 +148,7 @@ def execute_blackjack(v, target, body, kind): ) g.db.add(ma) - v.ban_reason = f"Blackjack: {kind}" + v.shadowban_reason = f"Blackjack: {kind}" g.db.add(v) notified_ids = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['BLACKJACK_NOTIFICATIONS'])] diff --git a/files/routes/admin.py b/files/routes/admin.py index 39812c004..d5a279efa 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -256,6 +256,7 @@ def revert_actions(v, username): user.shadowbanned = None user.unban_utc = None user.ban_reason = None + user.shadowban_reason = None if user.is_banned: user.is_banned = None send_repeatable_notification(user.id, f"@{v.username} (a site admin) has unbanned you!") @@ -265,6 +266,7 @@ def revert_actions(v, username): u.shadowbanned = None u.unban_utc = None u.ban_reason = None + u.shadowban_reason = None if u.is_banned: u.is_banned = None send_repeatable_notification(u.id, f"@{v.username} (a site admin) has unbanned you!") @@ -882,7 +884,7 @@ def shadowban(user_id, v): if len(reason) > 256: abort(400, "Ban reason too long!") - user.ban_reason = reason + user.shadowban_reason = reason g.db.add(user) check_for_alts(user) @@ -907,12 +909,12 @@ def shadowban(user_id, v): def unshadowban(user_id, v): user = get_account(user_id) user.shadowbanned = None - if not user.is_banned: user.ban_reason = None + user.shadowban_reason = None g.db.add(user) for alt in get_alt_graph(user.id): alt.shadowbanned = None - if not alt.is_banned: alt.ban_reason = None + alt.shadowban_reason = None g.db.add(alt) ma = ModAction( @@ -1214,8 +1216,7 @@ def unban_user(fullname, v): user.is_banned = None user.unban_utc = None - if not user.shadowbanned: - user.ban_reason = None + user.ban_reason = None send_repeatable_notification(user.id, f"@{v.username} (a site admin) has unbanned you!") g.db.add(user) @@ -1223,8 +1224,7 @@ def unban_user(fullname, v): if x.is_banned: send_repeatable_notification(x.id, f"@{v.username} (a site admin) has unbanned you!") x.is_banned = None x.unban_utc = None - if not x.shadowbanned: - x.ban_reason = None + x.ban_reason = None g.db.add(x) ma = ModAction( diff --git a/files/routes/awards.py b/files/routes/awards.py index 88a7ccea3..77c2bf929 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -292,8 +292,7 @@ def award_thing(v, thing_type, id): else: author.unban_utc = None author.is_banned = None - if not author.shadowbanned: - author.ban_reason = None + author.ban_reason = None send_repeatable_notification(author.id, "You have been unbanned!") elif kind == "grass": link3 = f"/{thing_type}/{obj.id}" diff --git a/files/routes/routehelpers.py b/files/routes/routehelpers.py index bca65652c..654014383 100644 --- a/files/routes/routehelpers.py +++ b/files/routes/routehelpers.py @@ -103,11 +103,11 @@ def check_for_alts(current, include_current_session=False): for u in get_alt_graph(current.id): if u.shadowbanned and not current.shadowbanned: current.shadowbanned = u.shadowbanned - current.ban_reason = u.ban_reason + current.shadowban_reason = u.shadowban_reason g.db.add(current) elif current.shadowbanned and not u.shadowbanned: u.shadowbanned = current.shadowbanned - u.ban_reason = current.ban_reason + u.shadowban_reason = current.shadowban_reason g.db.add(u) elif u.is_permabanned and not current.is_permabanned: current.is_banned = u.is_banned @@ -120,11 +120,6 @@ def check_for_alts(current, include_current_session=False): u.unban_utc = None g.db.add(u) - if current.ban_reason == "Under Siege" and u.ban_reason and u.ban_reason != "Under Siege": - current.ban_reason = u.ban_reason - elif u.ban_reason == "Under Siege" and current.ban_reason and current.ban_reason != "Under Siege": - u.ban_reason = current.ban_reason - if u.is_muted and not current.is_muted: current.is_muted = u.is_muted g.db.add(current) diff --git a/files/templates/admin/shadowbanned.html b/files/templates/admin/shadowbanned.html index 6f53dbac4..20c117a38 100644 --- a/files/templates/admin/shadowbanned.html +++ b/files/templates/admin/shadowbanned.html @@ -27,7 +27,7 @@ {%- include 'user_in_table.html' -%} {{user.truescore}} - {{user.ban_reason | safe}} + {{user.shadowban_reason | safe}} {{user.shadowbanned_by}} diff --git a/files/templates/admin/shadowbanned_tooltip.html b/files/templates/admin/shadowbanned_tooltip.html index 55666fe02..84fb38020 100644 --- a/files/templates/admin/shadowbanned_tooltip.html +++ b/files/templates/admin/shadowbanned_tooltip.html @@ -1,3 +1,3 @@ {% if user.shadowbanned and v and v.admin_level >= PERMS['USER_SHADOWBAN'] %} - + {% endif %} diff --git a/files/templates/userpage/admintools.html b/files/templates/userpage/admintools.html index fcd4999c5..c9c172a51 100644 --- a/files/templates/userpage/admintools.html +++ b/files/templates/userpage/admintools.html @@ -23,7 +23,7 @@ {% endif %} {% if v and v.admin_level >= PERMS['USER_SHADOWBAN'] and u.shadowbanned %}
SHADOWBANNED USER: - {{u.ban_reason | safe}} + {{u.shadowban_reason | safe}} (by {{u.shadowbanned_by}})
diff --git a/migrations/20240211-add-shadowban-reason.sql b/migrations/20240211-add-shadowban-reason.sql new file mode 100644 index 000000000..6268d3d1e --- /dev/null +++ b/migrations/20240211-add-shadowban-reason.sql @@ -0,0 +1,3 @@ +alter table users add column shadowban_reason varchar(256); +update users set shadowban_reason=ban_reason where shadowbanned is not null; +update users set ban_reason=null where is_banned is null and ban_reason is not null;