Browse Source

fix #911: don't account events in subscribe on reply check

Rafał Pitoń 7 years ago
parent
commit
82cd7bcbc2

+ 9 - 2
misago/threads/api/postingendpoint/subscribe.py

@@ -41,8 +41,15 @@ class SubscribeMiddleware(PostingMiddleware):
         except Subscription.DoesNotExist:
         except Subscription.DoesNotExist:
             pass
             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
             return
 
 
         self.user.subscription_set.create(
         self.user.subscription_set.create(

+ 23 - 0
misago/threads/tests/test_subscription_middleware.py

@@ -163,6 +163,28 @@ class SubscribeRepliedThreadTests(SubscriptionMiddlewareTestCase):
         self.assertEqual(subscription.category_id, self.category.id)
         self.assertEqual(subscription.category_id, self.category.id)
         self.assertTrue(subscription.send_email)
         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):
     def test_dont_subscribe_replied(self):
         """middleware omits threads user already replied"""
         """middleware omits threads user already replied"""
         self.user.subscribe_to_replied_threads = UserModel.SUBSCRIBE_ALL
         self.user.subscribe_to_replied_threads = UserModel.SUBSCRIBE_ALL
@@ -177,6 +199,7 @@ class SubscribeRepliedThreadTests(SubscriptionMiddlewareTestCase):
 
 
         # clear subscription
         # clear subscription
         self.user.subscription_set.all().delete()
         self.user.subscription_set.all().delete()
+
         # reply again
         # reply again
         response = self.client.post(
         response = self.client.post(
             self.api_link, data={
             self.api_link, data={