From 057bc360bf44397a6b1b45d59981bea7ec42aa06 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Fri, 30 Sep 2022 15:40:02 -0700 Subject: [PATCH] don't duplicate get checks for posts --- files/helpers/jinja2.py | 4 ---- files/routes/admin.py | 15 ++------------- files/routes/awards.py | 4 +--- files/routes/posts.py | 2 -- 4 files changed, 3 insertions(+), 22 deletions(-) diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index b4fcc7ed8..92251befe 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -8,10 +8,6 @@ from files.helpers.assetcache import assetcache_path @app.template_filter("post_embed") def post_embed(id, v): - - try: id = int(id) - except: return None - p = get_post(id, v, graceful=True) if p: return render_template("submission_listing.html", listing=[p], v=v) diff --git a/files/routes/admin.py b/files/routes/admin.py index c15df9715..634e054a7 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1121,12 +1121,7 @@ def mute_user(v, user_id, mute_status): @limiter.limit("1/second;30/minute;200/hour;1000/day") @admin_level_required(2) def remove_post(post_id, v): - post = get_post(post_id) - - if not post: - abort(400) - post.is_banned = True post.is_approved = None post.stickied = None @@ -1164,9 +1159,6 @@ def approve_post(post_id, v): if post.author.id == v.id and post.author.agendaposter and AGENDAPOSTER_PHRASE not in post.body.lower() and post.sub != 'chudrama': return {"error": "You can't bypass the chud award!"}, 400 - if not post: - abort(400) - if post.is_banned: ma=ModAction( kind="unban_post", @@ -1192,11 +1184,8 @@ def approve_post(post_id, v): @app.post("/distinguish/") @admin_level_required(1) def distinguish_post(post_id, v): - post = get_post(post_id) - if not post: abort(404) - if post.author_id != v.id and v.admin_level < 2 : abort(403) if post.distinguish_level: @@ -1227,7 +1216,7 @@ def sticky_post(post_id, v): abort(403) post = get_post(post_id) - if post and not post.stickied: + if not post.stickied: pins = g.db.query(Submission).filter(Submission.stickied != None, Submission.is_banned == False).count() if pins >= PIN_LIMIT: if v.admin_level > 2: @@ -1255,7 +1244,7 @@ def sticky_post(post_id, v): def unsticky_post(post_id, v): post = get_post(post_id) - if post and post.stickied: + if post.stickied: if post.stickied.endswith('(pin award)'): return {"error": "Can't unpin award pins!"}, 403 post.stickied = None diff --git a/files/routes/awards.py b/files/routes/awards.py index 1d51b0ee9..093bb9afd 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -133,8 +133,6 @@ def award_thing(v, thing_type, id): if thing_type == 'post': thing = get_post(id) else: thing = get_comment(id) - if not thing: return {"error": f"This {thing_type} doesn't exist."}, 404 - if v.shadowbanned: return render_template('errors/500.html', err=True, v=v), 500 kind = request.values.get("kind", "").strip() @@ -165,7 +163,7 @@ def award_thing(v, thing_type, id): note = request.values.get("note", "").strip() author = thing.author - if author.shadowbanned: return {"error": f"This {thing_type} doesn't exist."}, 404 + if author.shadowbanned: abort(404) if SITE == 'rdrama.net' and author.id in (PIZZASHILL_ID, CARP_ID): return {"error": "This user is immune to awards."}, 403 diff --git a/files/routes/posts.py b/files/routes/posts.py index 29dee0f55..062b1dd14 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -234,8 +234,6 @@ def post_id(pid, anything=None, v=None, sub=None): @limiter.limit("1/second;30/minute;200/hour;1000/day") @auth_desired_with_logingate def viewmore(v, pid, sort, offset): - try: pid = int(pid) - except: abort(400) post = get_post(pid, v=v) if post.club and not (v and (v.paid_dues or v.id == post.author_id)): abort(403)