Просмотр исходного кода

fix #681: because post read sets last_read_on equal to its posted_on date

Rafał Pitoń 8 лет назад
Родитель
Сommit
bfadc1b08f

+ 1 - 1
misago/threads/api/postingendpoint/emailnotification.py

@@ -18,7 +18,7 @@ class EmailNotificationMiddleware(PostingMiddleware):
     def post_save(self, serializer):
         queryset = self.thread.subscription_set.filter(
             send_email=True,
-            last_read_on__gt=self.previous_last_post_on
+            last_read_on__gte=self.previous_last_post_on
         ).exclude(user=self.user).select_related('user')
 
         notifications = []

+ 30 - 0
misago/threads/tests/test_emailnotification_middleware.py

@@ -170,3 +170,33 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
 
         last_post = self.thread.post_set.order_by('id').last()
         self.assertIn(last_post.get_absolute_url(), message)
+
+    def test_other_notified_after_reading(self):
+        """email is sent to subscriber that had sub updated by read api"""
+        self.other_user.subscription_set.create(
+            thread=self.thread,
+            category=self.category,
+            last_read_on=self.thread.last_post_on,
+            send_email=True
+        )
+        self.override_other_user_acl()
+
+        response = self.client.post(self.api_link, data={
+            'post': 'This is test response!'
+        })
+        self.assertEqual(response.status_code, 200)
+
+        self.assertEqual(len(mail.outbox), 1)
+        last_email = mail.outbox[-1]
+
+        self.assertIn(self.user.username, last_email.subject)
+        self.assertIn(self.thread.title, last_email.subject)
+
+        message = smart_str(last_email.body)
+
+        self.assertIn(self.user.username, message)
+        self.assertIn(self.thread.title, message)
+        self.assertIn(self.thread.get_absolute_url(), message)
+
+        last_post = self.thread.post_set.order_by('id').last()
+        self.assertIn(last_post.get_absolute_url(), message)