You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2026/08/28 15:13:15 UTC

(allura) branch master updated: update discussion thread logic for consistency

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ac3817ca update discussion thread logic for consistency
2ac3817ca is described below

commit 2ac3817ca2b77b813420da6070234c5ba4840dbf
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Thu Aug 27 16:07:25 2026 -0400

    update discussion thread logic for consistency
---
 Allura/allura/controllers/discuss.py                          | 1 +
 ForgeDiscussion/forgediscussion/controllers/root.py           | 7 +++++--
 ForgeDiscussion/forgediscussion/tests/functional/test_rest.py | 9 +++++++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index 79dff39f2..f47ece6e3 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -214,6 +214,7 @@ def index(self, limit=None, page=0, count=0, **kw):
         count = self.thread.query_posts(page=page, limit=int(limit)).count()
         if self.thread.num_replies == 0 or all(p.status != 'ok' for p in self.thread.posts):
             # return status code 404 but still display the page content
+            # necessary so a moderated author can see thread page with "Post awaiting moderation"
             request.environ['tg.status_code_redirect'] = True
             response.status_int = 404
         return dict(discussion=self.thread.discussion,
diff --git a/ForgeDiscussion/forgediscussion/controllers/root.py b/ForgeDiscussion/forgediscussion/controllers/root.py
index 63b1fd8a5..3e0c4f41c 100644
--- a/ForgeDiscussion/forgediscussion/controllers/root.py
+++ b/ForgeDiscussion/forgediscussion/controllers/root.py
@@ -355,7 +355,8 @@ def _check_security(self):
     @expose('json:')
     def index(self, limit=None, page=0, **kw):
         limit, page, start = g.handle_paging(limit, int(page))
-        topics = model.Forum.thread_class().query.find(dict(discussion_id=self.forum._id))
+        topics = model.Forum.thread_class().query.find(dict(discussion_id=self.forum._id,
+                                                            num_replies={'$gt': 0}))
         topics = topics.sort([('flags', pymongo.DESCENDING),
                               ('last_post_date', pymongo.DESCENDING)])
         topics = topics.skip(start).limit(limit)
@@ -377,8 +378,10 @@ def index(self, limit=None, page=0, **kw):
         return json
 
     @expose()
-    def _lookup(self, thread, thread_id, *remainder):
+    def _lookup(self, thread, thread_id=None, *remainder):
         if thread == 'thread':
+            if thread_id is None:
+                raise exc.HTTPNotFound()
             topic = model.Forum.thread_class().query.find(dict(
                 app_config_id=c.app.config._id,
                 discussion_id=self.forum._id,
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py b/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py
index edb3bd088..0a885cd48 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py
@@ -206,6 +206,15 @@ def test_topic_show_ok_only(self):
         posts = resp.json['topic']['posts']
         assert len(posts) == 1
 
+    def test_forum_hides_topics_without_posts(self):
+        self.create_topic('general', 'Doomed', 'secret text here')
+        t = ForumThread.query.find({'subject': 'Doomed'}).first()
+        t.first_post.delete()
+        ThreadLocalODMSession.flush_all()
+        forum = self.app.get('/rest/p/test/discussion/general/',
+                             extra_environ={'username': '*anonymous'})
+        assert 'Doomed' not in [x['subject'] for x in forum.json['forum']['topics']]
+
     def test_security(self):
         p = M.Project.query.get(shortname='test')
         acl = p.app_instance('discussion').config.acl