From d686b53c4e0d9caa5128f2f7866f5cee34a818de Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 23 Nov 2021 01:25:33 +0200 Subject: [PATCH] dfsfds --- files/helpers/get.py | 25 +++++++++++++++++++++++++ files/routes/static.py | 17 +++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/files/helpers/get.py b/files/helpers/get.py index a9f778f1b..055902ea3 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -1,6 +1,31 @@ from files.classes import * from flask import g + +def get_id(username, v=None, graceful=False): + + username = username.replace('\\', '') + username = username.replace('_', '\_') + username = username.replace('%', '') + + user = g.db.query( + User.id + ).filter( + or_( + User.username.ilike(username), + User.original_username.ilike(username) + ) + ).first() + + if not user: + if not graceful: + abort(404) + else: + return None + + return user[0] + + def get_user(username, v=None, graceful=False): username = username.replace('\\', '') diff --git a/files/routes/static.py b/files/routes/static.py index 681bfdb1d..3ee79c3f1 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -175,15 +175,20 @@ def admins(v): @auth_desired def log(v): - page=int(request.args.get("page",1)) - admin=int(request.args.get("admin",0)) + page = int(request.args.get("page",1)) + admin = request.args.get("admin") + if admin: admin = get_id(admin) - if v and v.admin_level > 1: actions = g.db.query(ModAction).order_by(ModAction.id.desc()).offset(25 * (page - 1)).limit(26) - else: actions=g.db.query(ModAction).filter(ModAction.kind!="shadowban", ModAction.kind!="unshadowban", ModAction.kind!="club", ModAction.kind!="unclub", ModAction.kind!="check").order_by(ModAction.id.desc()).offset(25*(page-1)).limit(26) + kind = request.args.get("kind") - if admin: actions = actions.filter_by(user_id=admin) + actions = g.db.query(ModAction) + if not (v and v.admin_level > 1): + actions = actions.filter(ModAction.kind!="shadowban", ModAction.kind!="unshadowban", ModAction.kind!="club", ModAction.kind!="unclub", ModAction.kind!="check") - actions = actions.all() + if admin: actions = actions.filter_by(user_id=admin) + if kind: actions = actions.filter_by(kind=kind) + + actions = actions.order_by(ModAction.id.desc()).offset(25*(page-1)).limit(26).all() next_exists=len(actions)>25 actions=actions[:25]