From 82cd7bcbc210f5248775e7c14a884499a8dddc09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Pito=C5=84?= Date: Sat, 7 Oct 2017 01:02:41 +0200 Subject: [PATCH] fix #911: don't account events in subscribe on reply check --- .../threads/api/postingendpoint/subscribe.py | 11 +++++++-- .../tests/test_subscription_middleware.py | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/misago/threads/api/postingendpoint/subscribe.py b/misago/threads/api/postingendpoint/subscribe.py index 3a2cf58bde..8935ec47f5 100644 --- a/misago/threads/api/postingendpoint/subscribe.py +++ b/misago/threads/api/postingendpoint/subscribe.py @@ -41,8 +41,15 @@ def subscribe_replied_thread(self): except Subscription.DoesNotExist: pass - # we are replying to thread again? - if self.user.post_set.filter(thread=self.thread).count() > 1: + # posts user's posts in this thread, minus events and current post + posts_queryset = self.user.post_set.filter( + thread=self.thread, + is_event=False, + ).exclude( + pk=self.post.pk, + ) + + if posts_queryset.exists(): return self.user.subscription_set.create( diff --git a/misago/threads/tests/test_subscription_middleware.py b/misago/threads/tests/test_subscription_middleware.py index 9dea96ccc5..87e6b0cbc4 100644 --- a/misago/threads/tests/test_subscription_middleware.py +++ b/misago/threads/tests/test_subscription_middleware.py @@ -163,6 +163,28 @@ def test_email_subscribe(self): self.assertEqual(subscription.category_id, self.category.id) self.assertTrue(subscription.send_email) + def test_subscribe_with_events(self): + """middleware omits events when testing for replied thread""" + self.user.subscribe_to_replied_threads = UserModel.SUBSCRIBE_ALL + self.user.save() + + # set event in thread + testutils.reply_thread(self.thread, self.user, is_event=True) + + # reply thread + response = self.client.post( + self.api_link, data={ + 'post': "This is test response!", + } + ) + self.assertEqual(response.status_code, 200) + + # user has subscribed to thread + subscription = self.user.subscription_set.get(thread=self.thread) + + self.assertEqual(subscription.category_id, self.category.id) + self.assertTrue(subscription.send_email) + def test_dont_subscribe_replied(self): """middleware omits threads user already replied""" self.user.subscribe_to_replied_threads = UserModel.SUBSCRIBE_ALL @@ -177,6 +199,7 @@ def test_dont_subscribe_replied(self): # clear subscription self.user.subscription_set.all().delete() + # reply again response = self.client.post( self.api_link, data={