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.
master
Snakes 2022-12-09 23:46:19 -05:00
parent 47923ffebe
commit 39a0832223
Signed by: Snakes
GPG Key ID: E745A82778055C7E
6 changed files with 39 additions and 12 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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()

View File

@ -8,6 +8,7 @@
<tr>
<th>#</th>
<th>Name</th>
<th>Last Active</th>
<th>Shadowbanned by</th>
<th>Shadowban reason</th>
</tr>
@ -16,6 +17,7 @@
<tr>
<td>{{loop.index}}</td>
<td>{% include "user_in_table.html" %}</td>
<td data-time="{{user.last_active}}"></td>
<td>{{user.shadowbanned}}</td>
<td>{{user.ban_reason}}</td>
</tr>

View File

@ -8,6 +8,9 @@
<tr>
<th>#</th>
<th>Name</th>
{% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%}
<th>Last Active</th>
{%- endif %}
<th>Ban reason</th>
<th>Banned by</th>
<th>Unban in</th>
@ -17,6 +20,9 @@
<tr>
<td>{{loop.index}}</td>
<td>{% include "user_in_table.html" %}</td>
{% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%}
<td data-time="{{user.last_active}}"></td>
{%- endif %}
<td>{% if user.ban_reason %}{{user.ban_reason}}{% endif %}</td>
<td>
{% with user=user.banned_by %}

View File

@ -8,6 +8,9 @@
<tr>
<th>#</th>
<th>Name</th>
{% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%}
<th>Last Active</th>
{%- endif %}
<th>Unchud in</th>
</tr>
</thead>
@ -15,6 +18,9 @@
<tr>
<td>{{loop.index}}</td>
<td>{% include "user_in_table.html" %}</td>
{% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%}
<td data-time="{{user.last_active}}"></td>
{%- endif %}
<td>{{user.unchud_in}}</td>
</tr>
{% endfor %}