Skip to content

Commit

Permalink
Merge pull request #2194 from SpaceFox/fix_2160
Browse files Browse the repository at this point in the history
Fixes #2160: Un MP peut ne pas avoir de participants
  • Loading branch information
Laville Augustin committed Jan 31, 2015
2 parents d592c36 + 6eeb2c7 commit a466f71
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 3 additions & 2 deletions zds/utils/templatetags/interventions.py
Expand Up @@ -137,15 +137,16 @@ def interventions_privatetopics(user):
'''
select distinct t.*
from mp_privatetopic t
inner join mp_privatetopic_participants p on p.privatetopic_id = t.id
left outer join mp_privatetopic_participants p on p.privatetopic_id = t.id
left outer join mp_privatetopicread r on r.user_id = %s and r.privatepost_id = t.last_message_id
where (t.author_id = %s or p.user_id = %s)
and r.id is null
order by t.pubdate desc''',
[user.id, user.id, user.id])

# "total" re-do the query, but there is no other way to get the length as __len__ is not available on raw queries.
return {'unread': privatetopics_unread, 'total': len(list(privatetopics_unread))}
topics = list(privatetopics_unread)
return {'unread': topics, 'total': len(topics)}


@register.filter(name='alerts_list')
Expand Down
38 changes: 38 additions & 0 deletions zds/utils/templatetags/tests/tests_interventions.py
@@ -0,0 +1,38 @@
# coding: utf-8

from django.test import TestCase

from zds.member.factories import ProfileFactory
from zds.mp.factories import PrivateTopicFactory, PrivatePostFactory
from zds.utils.templatetags.interventions import interventions_privatetopics


class InterventionsTest(TestCase):

def setUp(self):
self.author = ProfileFactory()
self.user = ProfileFactory()
self.topic = PrivateTopicFactory(author=self.author.user)
self.topic.participants.add(self.user.user)
self.post = PrivatePostFactory(
privatetopic=self.topic,
author=self.author.user,
position_in_topic=1)

def test_interventions_privatetopics(self):
result = interventions_privatetopics(self.author)
self.assertEqual(result['total'], 1)

result = interventions_privatetopics(self.user)
self.assertEqual(result['total'], 1)

def test_interventions_privatetopics_author_leave(self):

# profile1 (author) leave topic
move = self.topic.participants.first()
self.topic.author = move
self.topic.participants.remove(move)
self.topic.save()

result = interventions_privatetopics(self.user)
self.assertEqual(result['total'], 1)

0 comments on commit a466f71

Please sign in to comment.