From 612d69c1573f697a18eb8a95d219df03d7fdd6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sat, 25 Apr 2026 23:56:46 +0300 Subject: [PATCH] only show reply form if the user can reply --- app/models.py | 4 ++-- app/routes/threads.py | 7 +++---- app/templates/threads/new_thread.html | 2 +- app/templates/threads/thread.html | 2 +- app/templates/topics/topic.html | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/models.py b/app/models.py index 41f98e5..67fa5f8 100644 --- a/app/models.py +++ b/app/models.py @@ -61,14 +61,14 @@ class Users(Model): subscriptions.user_id = ?""" return db.query(q, self.id) - def can_post_to_topic(self, topic): + def can_post_to_thread_or_topic(self, thread_or_topic): if self.is_guest(): return False if self.is_mod(): return True - if topic['is_locked']: + if thread_or_topic['is_locked']: return False return True diff --git a/app/routes/threads.py b/app/routes/threads.py index bc73c45..b38b3a5 100644 --- a/app/routes/threads.py +++ b/app/routes/threads.py @@ -58,15 +58,14 @@ def thread(thread_id, slug): abort(404) return render_template('threads/thread.html', thread=thread, posts=thread.get_posts(PER_PAGE, page), page=page, page_count=page_count, topic=topic, started_by=started_by, topics=Topics.get_list(), Reactions=Reactions) -@bp.post('//reply/') +@bp.post('//') @login_required def reply(thread_id): user = get_active_user() thread = Threads.find({'id': thread_id}) if not thread: abort(404) - if thread.locked() and not user.is_mod(): - # TODO: flash + if not user.can_post_to_thread_or_topic(thread): return redirect(url_for('.thread_by_id', thread_id=thread_id)) post = Posts.new(user.id, thread.id, request.form.get('babycode_content')) return redirect(url_for('.thread_by_id', thread_id=thread_id, after=post.id, _anchor=f'post-{post.id}')) @@ -110,7 +109,7 @@ def new_post(): abort(404) user = get_active_user() - if not user.can_post_to_topic(topic): + if not user.can_post_to_thread_or_topic(topic): abort(404) title = request.form.get('title') diff --git a/app/templates/threads/new_thread.html b/app/templates/threads/new_thread.html index e2110f7..80079d0 100644 --- a/app/templates/threads/new_thread.html +++ b/app/templates/threads/new_thread.html @@ -7,7 +7,7 @@ diff --git a/app/templates/threads/thread.html b/app/templates/threads/thread.html index 8d67999..9a5b53a 100644 --- a/app/templates/threads/thread.html +++ b/app/templates/threads/thread.html @@ -70,7 +70,7 @@ {{- pager(page, page_count) -}} -{%- if is_logged_in() -%} +{%- if is_logged_in() and get_active_user().can_post_to_thread_or_topic(thread) -%}

Reply to "{{thread.title}}"

{{- babycode_editor_component() -}} diff --git a/app/templates/topics/topic.html b/app/templates/topics/topic.html index 226d53f..204c02a 100644 --- a/app/templates/topics/topic.html +++ b/app/templates/topics/topic.html @@ -14,7 +14,7 @@ {%- call() subheader(('Threads in "%s"' % topic.name), td) -%}
Actions - {%- if is_logged_in() and get_active_user().can_post_to_topic(topic) -%} + {%- if is_logged_in() and get_active_user().can_post_to_thread_or_topic(topic) -%} New thread {%- endif -%} Subscribe via RSS @@ -44,7 +44,7 @@ {%- endif -%} {%- endcall -%} {%- if threads | length == 0 -%} -

There are no threads in this topic yet.{%- if is_logged_in() and get_active_user().can_post_to_topic(topic) %} Be the first to start a discussion!{%- endif -%}

+

There are no threads in this topic yet.{%- if is_logged_in() and get_active_user().can_post_to_thread_or_topic(topic) %} Be the first to start a discussion!{%- endif -%}

{%- endif -%} {%- for thread in threads -%}