From 03e925fb3ce307ed87b0e5c96c9ca0bf39e9e972 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 29 Sep 2022 08:36:59 +0200 Subject: [PATCH] use ban_reason column as a reason for shadowbanning too --- files/routes/admin.py | 23 ++++--- files/templates/comments.html | 2 +- files/templates/shadowbanned.html | 2 + files/templates/submission.html | 2 +- files/templates/submission_listing.html | 2 +- files/templates/userpage.html | 79 ++++++++++++++++++------- 6 files changed, 79 insertions(+), 31 deletions(-) diff --git a/files/routes/admin.py b/files/routes/admin.py index e13582386..4c63363b6 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -910,23 +910,28 @@ def shadowban(user_id, v): user = get_account(user_id) if user.admin_level != 0: abort(403) user.shadowbanned = v.username + reason = request.values.get("reason").strip()[:256] + user.ban_reason = reason g.db.add(user) - for alt in user.alts: - if alt.admin_level: continue - alt.shadowbanned = v.username - g.db.add(alt) + if request.values.get("alts"): + for alt in user.alts: + if alt.admin_level: continue + alt.shadowbanned = v.username + alt.ban_reason = reason + g.db.add(alt) ma = ModAction( kind="shadowban", user_id=v.id, target_user_id=user.id, + _note=f'reason: "{reason}"' ) g.db.add(ma) cache.delete_memoized(frontlist) - return {"message": f"@{user.username} has been shadowbanned!"} + return redirect(user.url) @app.post("/unshadowban/") @limiter.limit("1/second;30/minute;200/hour;1000/day") @@ -934,9 +939,11 @@ 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 g.db.add(user) for alt in user.alts: alt.shadowbanned = None + if not alt.is_banned: alt.ban_reason = None g.db.add(alt) ma = ModAction( @@ -948,7 +955,7 @@ def unshadowban(user_id, v): cache.delete_memoized(frontlist) - return {"message": f"@{user.username} has been unshadowbanned!"} + return redirect(user.url) @app.post("/admin/title_change/") @@ -996,7 +1003,7 @@ def ban_user(user_id, v): days = float(request.values.get("days")) if request.values.get('days') else 0 - reason = request.values.get("reason", "").strip()[:256] + reason = request.values.get("reason").strip()[:256] reason = filter_emojis_only(reason) if reason.startswith("/") and '\\' not in reason: @@ -1429,7 +1436,7 @@ def admin_toggle_ban_domain(v): domain=request.values.get("domain", "").strip() if not domain: abort(400) - reason=request.values.get("reason", "").strip() + reason=request.values.get("reason").strip() d = g.db.query(BannedDomain).filter_by(domain=domain).one_or_none() if d: diff --git a/files/templates/comments.html b/files/templates/comments.html index dfd050576..1f9352415 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -140,7 +140,7 @@ {% endif %} {% if c.active_flags(v) %}{{c.active_flags(v)}} Report{{ help.plural(c.active_flags(v)) }}{% endif %} {% if c.over_18 %}+18{% endif %} - {% if v and v.admin_level > 1 and c.author.shadowbanned %}{% endif %} + {% if v and v.admin_level > 1 and c.author.shadowbanned %}{% endif %} {% if c.stickied %} {% endif %} diff --git a/files/templates/shadowbanned.html b/files/templates/shadowbanned.html index 8ad0eebc9..2c80d8e0d 100644 --- a/files/templates/shadowbanned.html +++ b/files/templates/shadowbanned.html @@ -9,6 +9,7 @@ # Name Shadowbanned by + Shadowban reason {% for user in users %} @@ -16,6 +17,7 @@ {{loop.index}} {% include "user_in_table.html" %} {{user.shadowbanned}} + {{user.ban_reason}} {% endfor %} diff --git a/files/templates/submission.html b/files/templates/submission.html index d53ad54c7..4e7f70472 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -640,7 +640,7 @@ {% endfor %} - {% if v and v.admin_level > 1 and p.author.shadowbanned %}{% endif %} + {% if v and v.admin_level > 1 and p.author.shadowbanned %}{% endif %} {% if p.stickied %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index c7488e78c..b802cdcff 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -134,7 +134,7 @@ {% endfor %} {% if v and v.admin_level > 1 and p.author.shadowbanned %} - + {% endif %} {% if p.stickied %} diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 3e4c51035..e5281f4a2 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -58,7 +58,11 @@ {% endif %} {% endif %} {% if v and v.admin_level >= 2 and u.shadowbanned %} -
SHADOWBANNED USER
+
SHADOWBANNED USER + {% if u.ban_reason %}: + {{u.ban_reason | safe}} + {% endif %} +
{% endif %}

{{u.username}}

@@ -289,6 +293,7 @@

+						

 						{% if u.is_suspended %}
 							
@@ -299,9 +304,9 @@ - + -
+
@@ -309,27 +314,43 @@ {% endif %}

+						

+
+						{% if u.shadowbanned %}
+							
+ + +
+ {% else %} +
+ + +
+ + +
+ +
+ {% endif %} +

+						

 
 						
+

+
 						Disable Chud Theme
 
 						

 
-						Shadowban
-
-						Unshadowban
-
 						Mute
 
 						Unmute
 
 
-						

-
 						

 						
@@ -420,6 +441,10 @@ {% if u.unban_utc %}
{{u.unban_string}}
{% endif %} {% endif %} + {% if u.shadowbanned %} +
SHADOWBANNED USER{% if u.ban_reason %}: {{u.ban_reason | safe}}{% endif %}
+ {% endif %} +

{{u.username}}

{% if u.username != u.original_username %} @@ -637,6 +662,7 @@

+						

 						{% if u.is_suspended %}
 							
 								
@@ -647,39 +673,52 @@
 							
 								
 								
-								
+								
 								
-								
-
+
-
{% endif %}

+						

+
+						{% if u.shadowbanned %}
+							
+ + +
+ {% else %} +
+ + +
+ + +
+ +
+ {% endif %} +

+						

 
 						
+

+
 						Disable Chud Theme
 
 						

 
-						Shadowban
-
-						Unshadowban
-
 						Mute
 
 						Unmute
 
-
-						

-