Skip to content

Commit a466f71

Browse files
committed
Merge pull request #2194 from SpaceFox/fix_2160
Fixes #2160: Un MP peut ne pas avoir de participants
2 parents d592c36 + 6eeb2c7 commit a466f71

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

zds/utils/templatetags/interventions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,16 @@ def interventions_privatetopics(user):
137137
'''
138138
select distinct t.*
139139
from mp_privatetopic t
140-
inner join mp_privatetopic_participants p on p.privatetopic_id = t.id
140+
left outer join mp_privatetopic_participants p on p.privatetopic_id = t.id
141141
left outer join mp_privatetopicread r on r.user_id = %s and r.privatepost_id = t.last_message_id
142142
where (t.author_id = %s or p.user_id = %s)
143143
and r.id is null
144144
order by t.pubdate desc''',
145145
[user.id, user.id, user.id])
146146

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

150151

151152
@register.filter(name='alerts_list')
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# coding: utf-8
2+
3+
from django.test import TestCase
4+
5+
from zds.member.factories import ProfileFactory
6+
from zds.mp.factories import PrivateTopicFactory, PrivatePostFactory
7+
from zds.utils.templatetags.interventions import interventions_privatetopics
8+
9+
10+
class InterventionsTest(TestCase):
11+
12+
def setUp(self):
13+
self.author = ProfileFactory()
14+
self.user = ProfileFactory()
15+
self.topic = PrivateTopicFactory(author=self.author.user)
16+
self.topic.participants.add(self.user.user)
17+
self.post = PrivatePostFactory(
18+
privatetopic=self.topic,
19+
author=self.author.user,
20+
position_in_topic=1)
21+
22+
def test_interventions_privatetopics(self):
23+
result = interventions_privatetopics(self.author)
24+
self.assertEqual(result['total'], 1)
25+
26+
result = interventions_privatetopics(self.user)
27+
self.assertEqual(result['total'], 1)
28+
29+
def test_interventions_privatetopics_author_leave(self):
30+
31+
# profile1 (author) leave topic
32+
move = self.topic.participants.first()
33+
self.topic.author = move
34+
self.topic.participants.remove(move)
35+
self.topic.save()
36+
37+
result = interventions_privatetopics(self.user)
38+
self.assertEqual(result['total'], 1)

0 commit comments

Comments
 (0)