From 39a0832223513643b24f0463202fde4adc3abddf Mon Sep 17 00:00:00 2001 From: Snakes Date: Fri, 9 Dec 2022 23:46:19 -0500 Subject: [PATCH] Sort banned, chudded, etc listings by activity. The listings of users affected by jannied states are long. To make them more useful, sort by recent user activity (when v is allowed to view last_active) to know which accounts are still in use. --- files/routes/admin.py | 6 +++++- files/routes/static.py | 10 ---------- files/routes/users.py | 21 ++++++++++++++++++++- files/templates/admin/shadowbanned.html | 2 ++ files/templates/banned.html | 6 ++++++ files/templates/chuds.html | 6 ++++++ 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/files/routes/admin.py b/files/routes/admin.py index 2c5f020b8..bcf5cd11b 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1,6 +1,8 @@ import time from urllib.parse import quote, urlencode +from sqlalchemy import nullslast + from files.__main__ import app, cache, limiter from files.classes import * from files.helpers.actions import * @@ -335,7 +337,9 @@ def revert_actions(v, username): @app.get("/admin/shadowbanned") @admin_level_required(PERMS['USER_SHADOWBAN']) def shadowbanned(v): - users = g.db.query(User).filter(User.shadowbanned != None).order_by(User.shadowbanned).all() + users = g.db.query(User) \ + .filter(User.shadowbanned != None) \ + .order_by(nullslast(User.last_active.desc())).all() return render_template("admin/shadowbanned.html", v=v, users=users) diff --git a/files/routes/static.py b/files/routes/static.py index 067be1280..aec23c6a2 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -353,16 +353,6 @@ def blocks(v): return render_template("blocks.html", v=v, users=users, targets=targets) -@app.get("/banned") -@auth_required -def banned(v:User): - after_30_days = int(time.time()) + 86400 * 30 - users = g.db.query(User).filter(User.is_banned > 0, or_(User.unban_utc == 0, User.unban_utc > after_30_days)) - if not v.can_see_shadowbanned: - users = users.filter(User.shadowbanned == None) - users = users.all() - return render_template("banned.html", v=v, users=users) - @app.get("/formatting") @auth_required def formatting(v:User): diff --git a/files/routes/users.py b/files/routes/users.py index 27dfa657f..14e8265f2 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -7,6 +7,7 @@ from typing import Literal import gevent import qrcode +from sqlalchemy import nullslast from sqlalchemy.orm import aliased from files.classes import * @@ -167,6 +168,20 @@ def user_voted_posts(v:User, username): def user_voted_comments(v:User, username): return user_voted(v, username, Comment, CommentVote, "userpage/voted_comments.html", True) +@app.get("/banned") +@auth_required +def banned(v:User): + after_30_days = int(time.time()) + 86400 * 30 + users = g.db.query(User).filter( + User.is_banned > 0, + or_(User.unban_utc == 0, User.unban_utc > after_30_days), + ) + if v.admin_level >= PERMS['VIEW_LAST_ACTIVE']: + users = users.order_by(nullslast(User.last_active.desc())) + if not v.can_see_shadowbanned: + users = users.filter(User.shadowbanned == None) + users = users.all() + return render_template("banned.html", v=v, users=users) @app.get("/grassed") @auth_required @@ -181,7 +196,11 @@ def grassed(v:User): @auth_required def chuds(v:User): after_30_days = int(time.time()) + 86400 * 30 - users = g.db.query(User).filter(or_(User.agendaposter == 1, User.agendaposter > after_30_days)) + users = g.db.query(User).filter( + or_(User.agendaposter == 1, User.agendaposter > after_30_days), + ) + if v.admin_level >= PERMS['VIEW_LAST_ACTIVE']: + users = users.order_by(nullslast(User.last_active.desc())) if not v.can_see_shadowbanned: users = users.filter(User.shadowbanned == None) users = users.order_by(User.username).all() diff --git a/files/templates/admin/shadowbanned.html b/files/templates/admin/shadowbanned.html index dd0f2cf02..8e6d8ae64 100644 --- a/files/templates/admin/shadowbanned.html +++ b/files/templates/admin/shadowbanned.html @@ -8,6 +8,7 @@ # Name + Last Active Shadowbanned by Shadowban reason @@ -16,6 +17,7 @@ {{loop.index}} {% include "user_in_table.html" %} + {{user.shadowbanned}} {{user.ban_reason}} diff --git a/files/templates/banned.html b/files/templates/banned.html index 555e2c1ed..7f5f78f6d 100644 --- a/files/templates/banned.html +++ b/files/templates/banned.html @@ -8,6 +8,9 @@ # Name + {% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} + Last Active + {%- endif %} Ban reason Banned by Unban in @@ -17,6 +20,9 @@ {{loop.index}} {% include "user_in_table.html" %} + {% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} + + {%- endif %} {% if user.ban_reason %}{{user.ban_reason}}{% endif %} {% with user=user.banned_by %} diff --git a/files/templates/chuds.html b/files/templates/chuds.html index 523d96183..0eab6fab9 100644 --- a/files/templates/chuds.html +++ b/files/templates/chuds.html @@ -8,6 +8,9 @@ # Name + {% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} + Last Active + {%- endif %} Unchud in @@ -15,6 +18,9 @@ {{loop.index}} {% include "user_in_table.html" %} + {% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} + + {%- endif %} {{user.unchud_in}} {% endfor %}