diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-11-29 12:13:23 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-11-29 12:13:23 +0100 |
commit | 5bca903d1c75a59a3e415d14812b4ffca769d930 (patch) | |
tree | 289ecf0c5a6fa6d68be0d65399dee7e8d650260f | |
parent | 7cbafa8b495c2a79339df6e68adb6023eb1d83eb (diff) | |
download | hyperkitty-5bca903d1c75a59a3e415d14812b4ffca769d930.tar.gz hyperkitty-5bca903d1c75a59a3e415d14812b4ffca769d930.tar.xz hyperkitty-5bca903d1c75a59a3e415d14812b4ffca769d930.zip |
Fix bug in voting when emails in different lists have the same msgid
-rw-r--r-- | hyperkitty.spec | 2 | ||||
-rw-r--r-- | hyperkitty/api.py | 2 | ||||
-rw-r--r-- | hyperkitty/lib/voting.py | 12 | ||||
-rw-r--r-- | hyperkitty/tests/test_lib.py | 19 |
4 files changed, 27 insertions, 8 deletions
diff --git a/hyperkitty.spec b/hyperkitty.spec index d934f09..31a5257 100644 --- a/hyperkitty.spec +++ b/hyperkitty.spec @@ -108,7 +108,7 @@ rm -f hyperkitty_standalone/__init__.py # SELinux mkdir SELinux -echo '%{_localstatedir}/lib/%{name}/sites(/.*)? system_u:object_r:httpd_sys_content_t:s0' \ +echo '%{_localstatedir}/lib/%{name}/sites(/.*)? gen_context(system_u:object_r:httpd_sys_content_t,s0)' \ > SELinux/%{name}.fc # remember to bump the following version if the policy is updated echo "policy_module(%{name}, 1.0)" > SELinux/%{name}.te diff --git a/hyperkitty/api.py b/hyperkitty/api.py index c53ff15..89bc59d 100644 --- a/hyperkitty/api.py +++ b/hyperkitty/api.py @@ -90,7 +90,7 @@ class EmailResource(APIView): if not email: return Response(status=404) else: - email.likes, email.dislikes, _ignore = get_votes(email.message_id_hash) + email.likes, email.dislikes, _ignore = get_votes(mlist_fqdn, email.message_id_hash) return Response(EmailSerializer(email).data) diff --git a/hyperkitty/lib/voting.py b/hyperkitty/lib/voting.py index da3e2a4..dd01af2 100644 --- a/hyperkitty/lib/voting.py +++ b/hyperkitty/lib/voting.py @@ -24,14 +24,16 @@ from django.core.cache import cache from hyperkitty.models import Rating -def get_votes(msgid, user=None): +def get_votes(mlist_fqdn, msgid, user=None): """Extract all the votes for this message""" likes = dislikes = myvote = 0 try: if isinstance(msgid, basestring): - votes = Rating.objects.filter(messageid=msgid) + votes = Rating.objects.filter( + list_address=mlist_fqdn, messageid=msgid) elif isinstance(msgid, list): - votes = Rating.objects.filter(messageid__in=msgid) + votes = Rating.objects.filter( + list_address=mlist_fqdn, messageid__in=msgid) except Rating.DoesNotExist: votes = {} for vote in votes: @@ -49,7 +51,7 @@ def get_votes(msgid, user=None): def set_message_votes(message, user=None): # Extract all the votes for this message message.likes, message.dislikes, message.myvote = \ - get_votes(message.message_id_hash, user) + get_votes(message.list_name, message.message_id_hash, user) message.likestatus = "neutral" if message.likes - message.dislikes >= 10: message.likestatus = "likealot" @@ -65,7 +67,7 @@ def set_thread_votes(thread): likes, dislikes = cache.get(cache_key, (None, None)) if likes is None or dislikes is None: # XXX: 1 SQL request per thread, possible optimization here - likes, dislikes, _myvote = get_votes(thread.email_id_hashes) + likes, dislikes, _myvote = get_votes(thread.list_name, thread.email_id_hashes) cache.set(cache_key, (likes, dislikes)) # How should thread likes and dislikes be counted? #thread.likes = likes / thread.emails_count diff --git a/hyperkitty/tests/test_lib.py b/hyperkitty/tests/test_lib.py index 6b6a9e1..0f31fe1 100644 --- a/hyperkitty/tests/test_lib.py +++ b/hyperkitty/tests/test_lib.py @@ -26,7 +26,7 @@ from django.core.cache import cache from hyperkitty.models import Rating from hyperkitty.lib.view_helpers import get_display_dates, paginate -from hyperkitty.lib.voting import get_votes, set_thread_votes +from hyperkitty.lib.voting import set_thread_votes from hyperkitty.tests.utils import TestCase @@ -154,3 +154,20 @@ class VotingTestCase(TestCase): self.assertEqual(self.thread.likes, 10) self.assertEqual(self.thread.dislikes, 0) self.assertEqual(self.thread.likestatus, "likealot") + + def test_same_msgid_different_lists(self): + thread_1 = DummyThread() + thread_1.list_name = "test1@example.com" + thread_2 = DummyThread() + thread_2.list_name = "test2@example.com" + thread_1.email_id_hashes = thread_2.email_id_hashes = ["msgid"] + Rating(list_address="test1@example.com", messageid="msgid", + user=self.user, vote=1).save() + Rating(list_address="test2@example.com", messageid="msgid", + user=self.user, vote=1).save() + set_thread_votes(thread_1) + self.assertEqual(thread_1.likes, 1) + self.assertEqual(thread_1.dislikes, 0) + set_thread_votes(thread_2) + self.assertEqual(thread_2.likes, 1) + self.assertEqual(thread_2.dislikes, 0) |