Commit b086563abd5092e4e01019dc53bed74d1b184f3c
Committed by
Charles Oliveira
1 parent
b216ed6c
Exists in
master
and in
28 other branches
Fixed Mailman API v2 usage
Fixed test calls in order to adapt it to mailman-api v2 Signed-off-by: Carlos Oliveira <carlospecter@gmail.com>
Showing
6 changed files
with
39 additions
and
20 deletions
Show diff stats
colab/accounts/utils/mailman.py
| ... | ... | @@ -117,8 +117,9 @@ def get_list_description(listname, lists=None): |
| 117 | 117 | if not lists: |
| 118 | 118 | lists = all_lists() |
| 119 | 119 | |
| 120 | - desc = "".join(mlist.get('description') for mlist in lists\ | |
| 121 | - if isinstance(mlist, dict) and mlist.get('listname') == listname) | |
| 120 | + desc = "".join(mlist.get('description') for mlist in lists | |
| 121 | + if isinstance(mlist, dict) and | |
| 122 | + mlist.get('listname') == listname) | |
| 122 | 123 | |
| 123 | 124 | return desc |
| 124 | 125 | |
| ... | ... | @@ -147,3 +148,10 @@ def get_user_mailinglists(user): |
| 147 | 148 | lists_for_user.extend(mailing_lists(address=email)) |
| 148 | 149 | |
| 149 | 150 | return lists_for_user |
| 151 | + | |
| 152 | + | |
| 153 | +def extract_listname_from_list(lists): | |
| 154 | + try: | |
| 155 | + return [mlist.get('listname') for mlist in lists] | |
| 156 | + except ValueError: | |
| 157 | + return [] | ... | ... |
colab/home/views.py
| ... | ... | @@ -10,9 +10,10 @@ from colab.accounts.models import User |
| 10 | 10 | |
| 11 | 11 | def get_user_threads(threads, lists_for_user, key): |
| 12 | 12 | visible_threads = [] |
| 13 | + listnames_for_user = mailman.extract_listname_from_list(lists_for_user) | |
| 13 | 14 | for t in threads: |
| 14 | 15 | if not t.mailinglist.is_private or \ |
| 15 | - t.mailinglist.name in lists_for_user: | |
| 16 | + t.mailinglist.name in listnames_for_user: | |
| 16 | 17 | visible_threads.append(key(t)) |
| 17 | 18 | |
| 18 | 19 | return visible_threads | ... | ... |
colab/search/utils.py
| ... | ... | @@ -15,11 +15,12 @@ from colab.accounts.utils import mailman |
| 15 | 15 | |
| 16 | 16 | def get_visible_threads_queryset(logged_user): |
| 17 | 17 | queryset = Thread.objects |
| 18 | - lists_for_user = [] | |
| 18 | + listnames_for_user = [] | |
| 19 | 19 | if logged_user: |
| 20 | 20 | lists_for_user = mailman.get_user_mailinglists(logged_user) |
| 21 | + listnames_for_user = mailman.extract_listname_from_list(lists_for_user) | |
| 21 | 22 | |
| 22 | - user_lists = Condition(mailinglist__name__in=lists_for_user) | |
| 23 | + user_lists = Condition(mailinglist__name__in=listnames_for_user) | |
| 23 | 24 | public_lists = Condition(mailinglist__is_private=False) |
| 24 | 25 | queryset = Thread.objects.filter(user_lists | public_lists) |
| 25 | 26 | |
| ... | ... | @@ -28,6 +29,7 @@ def get_visible_threads_queryset(logged_user): |
| 28 | 29 | |
| 29 | 30 | def get_visible_threads(logged_user, filter_by_user=None): |
| 30 | 31 | thread_qs = get_visible_threads_queryset(logged_user) |
| 32 | + | |
| 31 | 33 | if filter_by_user: |
| 32 | 34 | message_qs = Message.objects.filter(thread__in=thread_qs) |
| 33 | 35 | messages = message_qs.filter( | ... | ... |
colab/super_archives/fixtures/mailinglistdata.json
| ... | ... | @@ -6,23 +6,23 @@ |
| 6 | 6 | "twitter": null, |
| 7 | 7 | "is_staff": false, |
| 8 | 8 | "user_permissions": [ |
| 9 | - | |
| 9 | + | |
| 10 | 10 | ], |
| 11 | 11 | "date_joined": "2015-02-24T21:10:35.004Z", |
| 12 | 12 | "google_talk": null, |
| 13 | - "first_name": "Gust", | |
| 13 | + "first_name": "John", | |
| 14 | 14 | "is_superuser": false, |
| 15 | 15 | "last_login": "2015-02-26T17:56:13.378Z", |
| 16 | 16 | "verification_hash": null, |
| 17 | 17 | "role": null, |
| 18 | - "email": "gustmax@hotmail.com", | |
| 19 | - "username": "gustmax", | |
| 18 | + "email": "johndoe@example.com", | |
| 19 | + "username": "johndoe", | |
| 20 | 20 | "bio": null, |
| 21 | 21 | "needs_update": false, |
| 22 | 22 | "is_active": true, |
| 23 | 23 | "facebook": null, |
| 24 | 24 | "groups": [ |
| 25 | - | |
| 25 | + | |
| 26 | 26 | ], |
| 27 | 27 | "password": "pbkdf2_sha256$12000$ez83ccNOUQZk$vYT/QcYMukXZ7D7L1qQPyYlzCUEEEF20J7/Xjef0Rqg=", |
| 28 | 28 | "institution": null, |
| ... | ... | @@ -37,7 +37,7 @@ |
| 37 | 37 | "real_name": "", |
| 38 | 38 | "user": 1, |
| 39 | 39 | "md5": "ed8f47ae6048f8d4456c0554578f53ff", |
| 40 | - "address": "gustmax@hotmail.com" | |
| 40 | + "address": "johndoe@example.com" | |
| 41 | 41 | }, |
| 42 | 42 | "model": "super_archives.emailaddress", |
| 43 | 43 | "pk": 1 | ... | ... |
colab/super_archives/tests/test_privatelist.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | import mock |
| 3 | 3 | |
| 4 | 4 | from colab.accounts.utils import mailman |
| 5 | -from django.test import TestCase, Client | |
| 5 | +from django.test import TestCase, Client | |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | class ArchivesViewTest(TestCase): |
| ... | ... | @@ -13,11 +13,14 @@ class ArchivesViewTest(TestCase): |
| 13 | 13 | self.client = Client() |
| 14 | 14 | |
| 15 | 15 | def authenticate_user(self): |
| 16 | - self.client.login(username='gustmax', password='1234') | |
| 16 | + self.client.login(username='johndoe', password='1234') | |
| 17 | 17 | |
| 18 | 18 | def test_see_only_private_list_if_member(self): |
| 19 | 19 | mailman.get_user_mailinglists = mock.Mock( |
| 20 | + return_value="[{'listname': 'privatelist'}]") | |
| 21 | + mailman.extract_listname_from_list = mock.Mock( | |
| 20 | 22 | return_value="['privatelist']") |
| 23 | + mailman.list_users = mock.Mock(return_value="['johndoe@example.com']") | |
| 21 | 24 | |
| 22 | 25 | self.authenticate_user() |
| 23 | 26 | request = self.client.get('/archives/thread/') |
| ... | ... | @@ -26,7 +29,7 @@ class ArchivesViewTest(TestCase): |
| 26 | 29 | |
| 27 | 30 | self.assertEqual('lista', list_data[0][0]) |
| 28 | 31 | self.assertEqual('privatelist', list_data[1][0]) |
| 29 | - self.assertEqual(2, len(list_data)) | |
| 32 | + self.assertEqual(2, len(list_data)) | |
| 30 | 33 | |
| 31 | 34 | def test_see_only_public_if_not_logged_in(self): |
| 32 | 35 | request = self.client.get('/archives/thread/') |
| ... | ... | @@ -34,10 +37,12 @@ class ArchivesViewTest(TestCase): |
| 34 | 37 | list_data = request.context['lists'] |
| 35 | 38 | |
| 36 | 39 | self.assertEqual('lista', list_data[0][0]) |
| 37 | - self.assertEqual(1, len(list_data)) | |
| 40 | + self.assertEqual(1, len(list_data)) | |
| 38 | 41 | |
| 39 | 42 | def test_see_private_thread_in_dashboard_if_member(self): |
| 40 | 43 | mailman.get_user_mailinglists = mock.Mock( |
| 44 | + return_value="[{'listname': 'privatelist'}]") | |
| 45 | + mailman.extract_listname_from_list = mock.Mock( | |
| 41 | 46 | return_value="['privatelist']") |
| 42 | 47 | |
| 43 | 48 | self.authenticate_user() |
| ... | ... | @@ -59,7 +64,7 @@ class ArchivesViewTest(TestCase): |
| 59 | 64 | self.assertEqual(1, len(hottest_threads)) |
| 60 | 65 | |
| 61 | 66 | def test_dont_see_private_threads_in_profile_if_logged_out(self): |
| 62 | - request = self.client.get('/account/gustmax') | |
| 67 | + request = self.client.get('/account/johndoe') | |
| 63 | 68 | |
| 64 | 69 | emails = request.context['emails'] |
| 65 | 70 | ... | ... |
colab/super_archives/views.py
| ... | ... | @@ -47,8 +47,8 @@ class ThreadView(View): |
| 47 | 47 | user = User.objects.get(username=request.user) |
| 48 | 48 | emails = user.emails.values_list('address', flat=True) |
| 49 | 49 | lists_for_user = mailman.get_user_mailinglists(user) |
| 50 | - listnames_for_user = [mlist.get("listname") | |
| 51 | - for mlist in lists_for_user] | |
| 50 | + listnames_for_user = mailman.extract_listname_from_list( | |
| 51 | + lists_for_user) | |
| 52 | 52 | if thread.mailinglist.name not in listnames_for_user: |
| 53 | 53 | raise PermissionDenied |
| 54 | 54 | |
| ... | ... | @@ -151,13 +151,16 @@ class ThreadDashboardView(View): |
| 151 | 151 | |
| 152 | 152 | context['lists'] = [] |
| 153 | 153 | |
| 154 | - lists_for_user = [] | |
| 154 | + listnames_for_user = [] | |
| 155 | 155 | if request.user.is_authenticated(): |
| 156 | 156 | user = User.objects.get(username=request.user) |
| 157 | 157 | lists_for_user = mailman.get_user_mailinglists(user) |
| 158 | + listnames_for_user = mailman.extract_listname_from_list( | |
| 159 | + lists_for_user) | |
| 158 | 160 | |
| 159 | 161 | for list_ in MailingList.objects.order_by('name'): |
| 160 | - if list_.name not in all_privates or list_.name in lists_for_user: | |
| 162 | + if list_.name not in all_privates\ | |
| 163 | + or list_.name in listnames_for_user: | |
| 161 | 164 | context['lists'].append(( |
| 162 | 165 | list_.name, |
| 163 | 166 | mailman.get_list_description(list_.name), | ... | ... |