From 78b668a870a7835f8d9104a3f6471e940ddb6951 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Fri, 30 Sep 2022 15:48:34 -0700 Subject: [PATCH] don't duplicate checks for users --- files/routes/admin.py | 6 ------ files/routes/awards.py | 2 +- files/routes/search.py | 2 -- files/routes/users.py | 9 ++------- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/files/routes/admin.py b/files/routes/admin.py index 10ea73895..722a0fe79 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -300,11 +300,8 @@ def revert_actions(v, username): @limiter.limit("1/second;30/minute;200/hour;1000/day") @admin_level_required(2) def club_allow(v, username): - u = get_user(username, v=v) - if not u: abort(404) - if u.admin_level >= v.admin_level: return {"error": "noob"}, 400 u.club_allowed = True @@ -327,11 +324,8 @@ def club_allow(v, username): @limiter.limit("1/second;30/minute;200/hour;1000/day") @admin_level_required(2) def club_ban(v, username): - u = get_user(username, v=v) - if not u: abort(404) - if u.admin_level >= v.admin_level: return {"error": "noob"}, 400 u.club_allowed = False diff --git a/files/routes/awards.py b/files/routes/awards.py index 093bb9afd..ff6486982 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -467,7 +467,7 @@ def admin_userawards_post(v): whitelist = ("shit", "fireflies", "train", "scooter", "wholesome", "tilt", "glowie") - u = get_user(u, graceful=False, v=v) + u = get_user(u, v=v) notify_awards = {} diff --git a/files/routes/search.py b/files/routes/search.py index ae9ac3494..92d4af1da 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -72,7 +72,6 @@ def searchposts(v): if 'author' in criteria: posts = posts.filter(Submission.ghost == False) author = get_user(criteria['author'], v=v, include_shadowbanned=False) - if not author: return {"error": "User not found"}, 400 if author.is_private and author.id != v.id and v.admin_level < 2 and not v.eye: if request.headers.get("Authorization"): return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}, 400 @@ -209,7 +208,6 @@ def searchcomments(v): if 'author' in criteria: comments = comments.filter(Comment.ghost == False) author = get_user(criteria['author'], v=v, include_shadowbanned=False) - if not author: return {"error": "User not found"}, 400 if author.is_private and author.id != v.id and v.admin_level < 2 and not v.eye: if request.headers.get("Authorization"): return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}, 400 diff --git a/files/routes/users.py b/files/routes/users.py index d7fe29e19..fd2cbb29f 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -458,8 +458,7 @@ def suicide(v, username): @auth_required def get_coins(v, username): user = get_user(username, v=v, include_shadowbanned=False) - if user != None: return {"coins": user.coins}, 200 - else: return {"error": "invalid_user"}, 404 + return {"coins": user.coins} @app.post("/@/transfer_coins") @limiter.limit("1/second;30/minute;200/hour;1000/day") @@ -468,8 +467,6 @@ def get_coins(v, username): def transfer_coins(v, username): receiver = get_user(username, v=v, include_shadowbanned=False) - if receiver is None: return {"error": "This user doesn't exist."}, 404 - if receiver.id != v.id: amount = request.values.get("amount", "").strip() amount = int(amount) if amount.isdigit() else None @@ -512,9 +509,7 @@ def transfer_coins(v, username): @is_not_permabanned def transfer_bux(v, username): receiver = get_user(username, v=v, include_shadowbanned=False) - - if not receiver: return {"error": "This user doesn't exist."}, 404 - + if receiver.id != v.id: amount = request.values.get("amount", "").strip() amount = int(amount) if amount.isdigit() else None