replace stub returns with redirects

This commit is contained in:
2025-07-04 17:24:17 +03:00
parent 13c89cbde2
commit 7ab1c8745f
3 changed files with 40 additions and 30 deletions

View File

@ -18,7 +18,7 @@ def thread(slug):
POSTS_PER_PAGE = 10
thread = Threads.find({"slug": slug})
if not thread:
return "no"
return redirect(url_for('topics.all_topics'))
post_count = Posts.count({"thread_id": thread.id})
page_count = max(math.ceil(post_count / POSTS_PER_PAGE), 1)
@ -69,12 +69,12 @@ def thread(slug):
def reply(slug):
thread = Threads.find({"slug": slug})
if not thread:
return "no"
return redirect(url_for('topics.all_topics'))
user = get_active_user()
if user.is_guest():
return "no"
return redirect(url_for('.thread', slug=slug))
if thread.locked() and not user.is_mod():
return "no"
return redirect(url_for('.thread', slug=slug))
post_content = request.form['post_content']
post = create_post(thread.id, user.id, post_content)
@ -102,10 +102,12 @@ def create_form():
topic = Topics.find({"id": request.form['topic_id']})
user = get_active_user()
if not topic:
return "no"
flash('Invalid topic', InfoboxKind.ERROR)
return redirect(url_for('.create'))
if topic.is_locked and not get_active_user().is_mod():
return "no"
flash(f'Topic "{topic.name}" is locked', InfoboxKind.ERROR)
return redirect(url_for('.create'))
title = request.form['title'].strip()
now = int(time.time())
@ -128,8 +130,10 @@ def create_form():
def lock(slug):
user = get_active_user()
thread = Threads.find({'slug': slug})
if not thread:
return redirect(url_for('topics.all_topics'))
if not ((thread.user_id == user.id) or user.is_mod()):
return 'no'
return redirect(url_for('.thread', slug=slug))
target_op = request.form.get('target_op')
thread.update({
'is_locked': target_op
@ -143,8 +147,10 @@ def lock(slug):
def sticky(slug):
user = get_active_user()
thread = Threads.find({'slug': slug})
if not thread:
return redirect(url_for('topics.all_topics'))
if not ((thread.user_id == user.id) or user.is_mod()):
return 'no'
return redirect(url_for('.thread', slug=slug))
target_op = request.form.get('target_op')
thread.update({
'is_stickied': target_op
@ -167,12 +173,12 @@ def move(slug):
'id': new_topic_id
})
if not new_topic:
return 'no'
return redirect(url_for('topics.all_topics'))
thread = Threads.find({
'slug': slug
})
if not thread:
return 'no'
return redirect(url_for('topics.all_topics'))
if new_topic.id == thread.topic_id:
flash('Thread is already in this topic.', InfoboxKind.ERROR)
return redirect(url_for('.thread', slug=slug))
@ -189,7 +195,7 @@ def subscribe(slug):
user = get_active_user()
thread = Threads.find({'slug': slug})
if not thread:
return 'no'
return redirect(url_for('topics.all_topics'))
subscription = Subscriptions.find({
'user_id': user.id,
'thread_id': thread.id,
@ -204,11 +210,11 @@ def subscribe(slug):
})
elif request.form['subscribe'] == 'unsubscribe':
if not subscription:
return 'no'
return redirect(url_for('.thread', slug=slug))
subscription.delete()
elif request.form['subscribe'] == 'read':
if not subscription:
return 'no'
return redirect(url_for('.thread', slug=slug))
subscription.update({
'last_seen': int(time.time())
})