Commit b216ed6cb67150b09c982969c49d13f7d1703e46
Committed by
Charles Oliveira
1 parent
87e9e4a6
Exists in
master
and in
28 other branches
Updated to Mailman API v2 usage
Signed-off-by: Carlos Oliveira <carlospecter@gmail.com>
Showing
2 changed files
with
15 additions
and
6 deletions
Show diff stats
colab/accounts/utils/mailman.py
| @@ -91,7 +91,10 @@ def mailing_lists(**kwargs): | @@ -91,7 +91,10 @@ def mailing_lists(**kwargs): | ||
| 91 | 91 | ||
| 92 | def is_private_list(name): | 92 | def is_private_list(name): |
| 93 | try: | 93 | try: |
| 94 | - return dict(all_lists(private=True))[name] | 94 | + privacy = {} |
| 95 | + privacy.update({mlist.get('listname'): mlist.get('archive_private') | ||
| 96 | + for mlist in all_lists()}) | ||
| 97 | + return privacy[name] | ||
| 95 | except KeyError: | 98 | except KeyError: |
| 96 | return [] | 99 | return [] |
| 97 | 100 |
colab/super_archives/views.py
| @@ -33,17 +33,23 @@ class ThreadView(View): | @@ -33,17 +33,23 @@ class ThreadView(View): | ||
| 33 | thread = get_object_or_404(Thread, subject_token=thread_token, | 33 | thread = get_object_or_404(Thread, subject_token=thread_token, |
| 34 | mailinglist__name=mailinglist) | 34 | mailinglist__name=mailinglist) |
| 35 | 35 | ||
| 36 | - # TODO: Refactor this code | ||
| 37 | - # Use local flag is_private instead of always check the API!! | ||
| 38 | - all_privates = dict(mailman.all_lists(private=True)) | ||
| 39 | - if all_privates[thread.mailinglist.name]: | 36 | + all_privates = [] |
| 37 | + all_privates.extend( | ||
| 38 | + [mlist.get('listname') | ||
| 39 | + for mlist in mailman.all_lists() | ||
| 40 | + if mlist.get('archive_private')] | ||
| 41 | + ) | ||
| 42 | + | ||
| 43 | + if all_privates.count(thread.mailinglist.name): | ||
| 40 | if not request.user.is_authenticated(): | 44 | if not request.user.is_authenticated(): |
| 41 | raise PermissionDenied | 45 | raise PermissionDenied |
| 42 | else: | 46 | else: |
| 43 | user = User.objects.get(username=request.user) | 47 | user = User.objects.get(username=request.user) |
| 44 | emails = user.emails.values_list('address', flat=True) | 48 | emails = user.emails.values_list('address', flat=True) |
| 45 | lists_for_user = mailman.get_user_mailinglists(user) | 49 | lists_for_user = mailman.get_user_mailinglists(user) |
| 46 | - if thread.mailinglist.name not in lists_for_user: | 50 | + listnames_for_user = [mlist.get("listname") |
| 51 | + for mlist in lists_for_user] | ||
| 52 | + if thread.mailinglist.name not in listnames_for_user: | ||
| 47 | raise PermissionDenied | 53 | raise PermissionDenied |
| 48 | 54 | ||
| 49 | thread.hit(request) | 55 | thread.hit(request) |