Commit 06ba4bfa6d2d8505f0eadd919643bca515b2758e

Authored by Gust
Committed by Sergio Oliveira
1 parent 256ed785

Only show mailinglists if public or user in it

Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Signed-off-by: Alexandre Barbosa <alexandreab@live.com>
colab/accounts/utils/mailman.py
... ... @@ -38,7 +38,7 @@ def unsubscribe(listname, address):
38 38  
39 39  
40 40 def update_subscription(address, lists):
41   - current_lists = address_lists(address)
  41 + current_lists = mailing_lists(address=address)
42 42  
43 43 for maillist in current_lists:
44 44 if maillist not in lists:
... ... @@ -48,31 +48,32 @@ def update_subscription(address, lists):
48 48 if maillist not in current_lists:
49 49 subscribe(maillist, address)
50 50  
  51 +def address_lists(address):
  52 + return mailing_lists(address=address)
51 53  
52   -def address_lists(address, description=''):
  54 +def mailing_lists(**kwargs):
53 55 url = get_url()
54 56  
55   - params = {'address': address,
56   - 'description': description}
57   -
58 57 try:
59   - lists = requests.get(url, timeout=TIMEOUT, params=params)
  58 + lists = requests.get(url, timeout=TIMEOUT, params=kwargs)
60 59 except:
61 60 LOGGER.exception('Unable to list mailing lists')
62 61 return []
63 62  
64 63 return lists.json()
65 64  
  65 +def is_private_list(name):
  66 + return dict(all_lists(private=True))[name]
66 67  
67 68 def all_lists(*args, **kwargs):
68   - return address_lists('', *args, **kwargs)
  69 + return mailing_lists(*args, **kwargs)
69 70  
70 71  
71 72 def user_lists(user):
72 73 list_set = set()
73 74  
74 75 for email in user.emails.values_list('address', flat=True):
75   - list_set.update(address_lists(email))
  76 + list_set.update(mailing_lists(address=email))
76 77  
77 78 return tuple(list_set)
78 79  
... ...
colab/super_archives/views.py
... ... @@ -123,20 +123,29 @@ class ThreadDashboardView(View):
123 123 MAX = 6
124 124 context = {}
125 125 all_lists = mailman.all_lists(description=True)
  126 + all_privates = dict(mailman.all_lists(private=True))
  127 +
126 128  
127 129 context['lists'] = []
128 130  
  131 + user = User.objects.get(username=request.user)
  132 + emails = user.emails.values_list('address', flat=True)
  133 + lists_for_user = []
  134 + for email in emails:
  135 + lists_for_user.extend(mailman.address_lists(email))
  136 +
129 137 for list_ in MailingList.objects.order_by('name'):
130   - context['lists'].append((
131   - list_.name,
132   - mailman.get_list_description(list_.name, all_lists),
133   - list_.thread_set.filter(spam=False).order_by(
134   - '-latest_message__received_time'
135   - )[:MAX],
136   - [t.latest_message for t in Thread.highest_score.filter(
137   - mailinglist__name=list_.name)[:MAX]],
138   - len(mailman.list_users(list_.name)),
139   - ))
  138 + if not all_privates[list_.name] or list_.name in lists_for_user:
  139 + context['lists'].append((
  140 + list_.name,
  141 + mailman.get_list_description(list_.name),
  142 + list_.thread_set.filter(spam=False).order_by(
  143 + '-latest_message__received_time'
  144 + )[:MAX],
  145 + [t.latest_message for t in Thread.highest_score.filter(
  146 + mailinglist__name=list_.name)[:MAX]],
  147 + len(mailman.list_users(list_.name)),
  148 + ))
140 149  
141 150 return render(request, 'superarchives/thread-dashboard.html', context)
142 151  
... ...