don't duplicate get checks for posts

master
justcool393 2022-09-30 15:40:02 -07:00
parent d0a19d5cc3
commit 057bc360bf
4 changed files with 3 additions and 22 deletions

View File

@ -8,10 +8,6 @@ from files.helpers.assetcache import assetcache_path
@app.template_filter("post_embed") @app.template_filter("post_embed")
def post_embed(id, v): def post_embed(id, v):
try: id = int(id)
except: return None
p = get_post(id, v, graceful=True) p = get_post(id, v, graceful=True)
if p: return render_template("submission_listing.html", listing=[p], v=v) if p: return render_template("submission_listing.html", listing=[p], v=v)

View File

@ -1121,12 +1121,7 @@ def mute_user(v, user_id, mute_status):
@limiter.limit("1/second;30/minute;200/hour;1000/day") @limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(2) @admin_level_required(2)
def remove_post(post_id, v): def remove_post(post_id, v):
post = get_post(post_id) post = get_post(post_id)
if not post:
abort(400)
post.is_banned = True post.is_banned = True
post.is_approved = None post.is_approved = None
post.stickied = 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': 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 return {"error": "You can't bypass the chud award!"}, 400
if not post:
abort(400)
if post.is_banned: if post.is_banned:
ma=ModAction( ma=ModAction(
kind="unban_post", kind="unban_post",
@ -1192,11 +1184,8 @@ def approve_post(post_id, v):
@app.post("/distinguish/<post_id>") @app.post("/distinguish/<post_id>")
@admin_level_required(1) @admin_level_required(1)
def distinguish_post(post_id, v): def distinguish_post(post_id, v):
post = get_post(post_id) 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.author_id != v.id and v.admin_level < 2 : abort(403)
if post.distinguish_level: if post.distinguish_level:
@ -1227,7 +1216,7 @@ def sticky_post(post_id, v):
abort(403) abort(403)
post = get_post(post_id) 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() pins = g.db.query(Submission).filter(Submission.stickied != None, Submission.is_banned == False).count()
if pins >= PIN_LIMIT: if pins >= PIN_LIMIT:
if v.admin_level > 2: if v.admin_level > 2:
@ -1255,7 +1244,7 @@ def sticky_post(post_id, v):
def unsticky_post(post_id, v): def unsticky_post(post_id, v):
post = get_post(post_id) 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 if post.stickied.endswith('(pin award)'): return {"error": "Can't unpin award pins!"}, 403
post.stickied = None post.stickied = None

View File

@ -133,8 +133,6 @@ def award_thing(v, thing_type, id):
if thing_type == 'post': thing = get_post(id) if thing_type == 'post': thing = get_post(id)
else: thing = get_comment(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 if v.shadowbanned: return render_template('errors/500.html', err=True, v=v), 500
kind = request.values.get("kind", "").strip() kind = request.values.get("kind", "").strip()
@ -165,7 +163,7 @@ def award_thing(v, thing_type, id):
note = request.values.get("note", "").strip() note = request.values.get("note", "").strip()
author = thing.author 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): if SITE == 'rdrama.net' and author.id in (PIZZASHILL_ID, CARP_ID):
return {"error": "This user is immune to awards."}, 403 return {"error": "This user is immune to awards."}, 403

View File

@ -234,8 +234,6 @@ def post_id(pid, anything=None, v=None, sub=None):
@limiter.limit("1/second;30/minute;200/hour;1000/day") @limiter.limit("1/second;30/minute;200/hour;1000/day")
@auth_desired_with_logingate @auth_desired_with_logingate
def viewmore(v, pid, sort, offset): def viewmore(v, pid, sort, offset):
try: pid = int(pid)
except: abort(400)
post = get_post(pid, v=v) post = get_post(pid, v=v)
if post.club and not (v and (v.paid_dues or v.id == post.author_id)): abort(403) if post.club and not (v and (v.paid_dues or v.id == post.author_id)): abort(403)