Commit 5332878af3032cd6a5ddcf21ed87c4a4030e0db4
1 parent
a2b437aa
Exists in
master
and in
28 other branches
Added support for mailman apiv2
Showing
2 changed files
with
19 additions
and
14 deletions
Show diff stats
colab/accounts/utils/mailman.py
| ... | ... | @@ -27,15 +27,15 @@ MAILMAN_MSGS = { |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
| 30 | -def get_url(listname=None): | |
| 30 | +def get_url(path, listname=None): | |
| 31 | + url = urlparse.urljoin(settings.MAILMAN_API_URL, path) | |
| 31 | 32 | if listname: |
| 32 | - return urlparse.urljoin(settings.MAILMAN_API_URL, listname) | |
| 33 | - | |
| 34 | - return settings.MAILMAN_API_URL | |
| 33 | + return urlparse.urljoin(url, listname) | |
| 34 | + return url | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | def subscribe(listname, address): |
| 38 | - url = get_url(listname) | |
| 38 | + url = get_url('subscribe/', listname=listname) | |
| 39 | 39 | try: |
| 40 | 40 | result = requests.put(url, timeout=TIMEOUT, data={'address': address}) |
| 41 | 41 | msg_type, message = MAILMAN_MSGS[result.json()] |
| ... | ... | @@ -46,7 +46,7 @@ def subscribe(listname, address): |
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | def unsubscribe(listname, address): |
| 49 | - url = get_url(listname) | |
| 49 | + url = get_url('subscribe/', listname) | |
| 50 | 50 | try: |
| 51 | 51 | result = requests.delete(url, timeout=TIMEOUT, data={'address': address}) |
| 52 | 52 | msg_type, message = MAILMAN_MSGS[result.json()] |
| ... | ... | @@ -57,7 +57,7 @@ def unsubscribe(listname, address): |
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | def update_subscription(address, lists): |
| 60 | - current_lists = mailing_lists(address=address) | |
| 60 | + current_lists = mailing_lists(address=address, names_only=True) | |
| 61 | 61 | info_messages = [] |
| 62 | 62 | |
| 63 | 63 | for maillist in current_lists: |
| ... | ... | @@ -72,16 +72,21 @@ def update_subscription(address, lists): |
| 72 | 72 | |
| 73 | 73 | |
| 74 | 74 | def mailing_lists(**kwargs): |
| 75 | - url = get_url() | |
| 76 | - path = 'lists/' | |
| 75 | + url = get_url('lists/') | |
| 77 | 76 | |
| 78 | 77 | try: |
| 79 | - lists = requests.get(url + path, timeout=TIMEOUT, params=kwargs) | |
| 78 | + lists = requests.get(url, timeout=TIMEOUT, params=kwargs) | |
| 80 | 79 | except: |
| 81 | 80 | LOGGER.exception('Unable to list mailing lists') |
| 82 | 81 | return [] |
| 83 | 82 | |
| 84 | - return lists.json() | |
| 83 | + if 'names_only' in kwargs and kwargs['names_only']: | |
| 84 | + names_only = [] | |
| 85 | + for l in lists.json(): | |
| 86 | + names_only.append(l['listname']) | |
| 87 | + return names_only | |
| 88 | + else: | |
| 89 | + return lists.json() | |
| 85 | 90 | |
| 86 | 91 | |
| 87 | 92 | def is_private_list(name): |
| ... | ... | @@ -115,7 +120,7 @@ def get_list_description(listname, lists=None): |
| 115 | 120 | |
| 116 | 121 | |
| 117 | 122 | def list_users(listname): |
| 118 | - url = get_url(listname) | |
| 123 | + url = get_url('members/', listname) | |
| 119 | 124 | |
| 120 | 125 | params = {} |
| 121 | 126 | ... | ... |
colab/accounts/views.py
| ... | ... | @@ -158,11 +158,11 @@ class ManageUserSubscriptionsView(UserProfileBaseMixin, DetailView): |
| 158 | 158 | |
| 159 | 159 | user = self.get_object() |
| 160 | 160 | emails = user.emails.values_list('address', flat=True) |
| 161 | - all_lists = mailman.all_lists(description=True) | |
| 161 | + all_lists = mailman.all_lists() | |
| 162 | 162 | |
| 163 | 163 | for email in emails: |
| 164 | 164 | lists = [] |
| 165 | - lists_for_address = mailman.mailing_lists(address=email) | |
| 165 | + lists_for_address = mailman.mailing_lists(address=email, names_only=True) | |
| 166 | 166 | for mlist in all_lists: |
| 167 | 167 | if mlist.get('listname') in lists_for_address: |
| 168 | 168 | checked = True | ... | ... |