redirect on post delete if target post cant be found

This commit is contained in:
2025-08-15 22:45:19 +03:00
parent 033df03c49
commit 05bd034b23

View File

@ -48,6 +48,9 @@ def update_post(post_id, new_content, markup_language='babycode'):
@login_required
def delete(post_id):
post = Posts.find({'id': post_id})
if not post:
return redirect(url_for('topics.all_topics'))
thread = Threads.find({'id': post.thread_id})
user = get_active_user()
if not user:
@ -76,6 +79,10 @@ def delete(post_id):
@bp.get("/<post_id>/edit")
@login_required
def edit(post_id):
post = Posts.find({'id': post_id})
if not post:
return redirect(url_for('topics.all_topics'))
user = get_active_user()
q = f"{Posts.FULL_POSTS_QUERY} WHERE posts.id = ?"
editing_post = db.fetch_one(q, post_id)
@ -106,6 +113,8 @@ def edit(post_id):
def edit_form(post_id):
user = get_active_user()
post = Posts.find({'id': post_id})
if not post:
return redirect(url_for('topics.all_topics'))
if post.user_id != user.id:
return redirect(url_for('topics.all_topics'))