Skip to content

Commit

Permalink
fix #911: don't account events in subscribe on reply check
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Oct 6, 2017
1 parent 8c918c2 commit 82cd7bc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
11 changes: 9 additions & 2 deletions misago/threads/api/postingendpoint/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 23 additions & 0 deletions misago/threads/tests/test_subscription_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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={
Expand Down

0 comments on commit 82cd7bc

Please sign in to comment.