Commit abc10771 authored by Abhilash Raj's avatar Abhilash Raj

Merge branch 'filter-vhost' into 'master'

Support mail_host in get_list_page and find_lists

See merge request !97
parents 8efb0c42 539cc3f9
Pipeline #50801035 passed with stage
in 4 minutes and 35 seconds
......@@ -163,15 +163,19 @@ class Client:
return [MailingList(self._connection, entry['self_link'], entry)
for entry in content['entries']]
def get_list_page(self, count=50, page=1, advertised=None):
def get_list_page(self, count=50, page=1, advertised=None, mail_host=None):
"""Get a list of all MailingList with pagination.
:param count: Number of entries per-page (defaults to 50).
:param page: The page number to return (defaults to 1).
:param advertised: If marked True, returns all MailingLists including
the ones that aren't advertised.
:param mail_host: Domain to filter results by.
"""
url = 'lists'
if mail_host:
url = 'domains/{0}/lists'.format(mail_host)
else:
url = 'lists'
if advertised:
url += '?advertised=true'
return Page(self._connection, url, MailingList, count, page)
......@@ -401,7 +405,8 @@ class Client:
data['password'] = password
return self._connection.call('uris', data, 'PATCH')[1]
def find_lists(self, subscriber, role=None, count=50, page=1):
def find_lists(self, subscriber, role=None, count=50, page=1,
mail_host=None):
"""Given a subscriber and a role, return all the list they are subscribed
to with given role.
......@@ -410,7 +415,10 @@ class Client:
memberships of a user in a single mailing list.
:param str subscriber: The address of the subscriber.
:param str role: owner, moderator or subscriber
:param str role: owner, moderator or subscriber.
:param int count: Number of entries per-page (defaults to 50).
:param int page: The page number to return (defaults to 1).
:param str mail_host: Domain to filter results by.
:returns: A filtered list of mailing lists with given filters.
:rtype: List[:class:`MailingList`]
"""
......@@ -422,4 +430,5 @@ class Client:
if 'entries' not in content:
return []
return [MailingList(self._connection, entry['self_link'], entry)
for entry in content['entries']]
for entry in content['entries']
if not mail_host or entry['mail_host'] == mail_host]
......@@ -2,6 +2,13 @@
NEWS for mailmanclient
=======================
3.2.3 (2019-XX-XX)
==================
* Add a ``mail_host`` parameter to ``get_list_page`` and ``find_lists`` to
support filtering the response by a list domain.
3.2.2 (2019-02-09)
==================
......
......@@ -189,8 +189,15 @@ Pages can also use the advertised filter:
[email protected]
[email protected]
If you only want to know all lists for a specific domain, use the domain
object.
Pages can also limit the results by domain:
>>> page = client.get_list_page(mail_host='example.net')
>>> for m_list in page:
... print(m_list.fqdn_listname)
[email protected]
You can also use the domain object if you only want to know all lists for a
specific domain without pagination.
>>> for mlist in example.lists:
... print(mlist.fqdn_listname)
......@@ -791,6 +798,8 @@ list:
... pre_confirmed=True))
Member "[email protected]" on "test-1.example.com"
>>> test_four_net = example_net.create_list('test-4')
>>> test_four_net.add_owner('[email protected]', display_name='Foo')
>>> for member in client.members:
... print('%s: %s' % (member, member.role))
Member "[email protected]" on "test-1.example.com": owner
......@@ -798,6 +807,31 @@ list:
Member "[email protected]" on "test-1.example.com": member
Member "[email protected]" on "test-1.example.com": member
Member "[email protected]" on "test-2.example.com": member
Member "[email protected]" on "test-4.example.net": owner
You can find the lists that a user is a member, moderator, or owner of:
>>> lists = client.find_lists('[email protected]', 'member')
>>> for m_list in lists:
... print(m_list.fqdn_listname)
[email protected]
>>> lists = client.find_lists('[email protected]', 'moderator')
>>> for m_list in lists:
... print(m_list.fqdn_listname)
[email protected]
>>> lists = client.find_lists('[email protected]', 'owner')
>>> for m_list in lists:
... print(m_list.fqdn_listname)
[email protected]
[email protected]
You can also filter those results by domain:
>>> lists = client.find_lists('[email protected]', 'owner',
... mail_host='example.net')
>>> for m_list in lists:
... print(m_list.fqdn_listname)
[email protected]
Both owners and moderators can be removed:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment