diff options
| -rw-r--r-- | src/mailman/interfaces/domain.py | 2 | ||||
| -rw-r--r-- | src/mailman/interfaces/listmanager.py | 7 | ||||
| -rw-r--r-- | src/mailman/model/docs/domains.txt | 23 | ||||
| -rw-r--r-- | src/mailman/model/domain.py | 9 | ||||
| -rw-r--r-- | src/mailman/model/listmanager.py | 4 | ||||
| -rw-r--r-- | src/mailman/rest/docs/domains.txt | 43 | ||||
| -rw-r--r-- | src/mailman/rest/docs/lists.rst | 9 | ||||
| -rw-r--r-- | src/mailman/rest/domains.py | 7 | ||||
| -rw-r--r-- | src/mailman/rest/lists.py | 2 |
9 files changed, 88 insertions, 18 deletions
diff --git a/src/mailman/interfaces/domain.py b/src/mailman/interfaces/domain.py index e1e41035a..e36ad03d3 100644 --- a/src/mailman/interfaces/domain.py +++ b/src/mailman/interfaces/domain.py @@ -64,6 +64,8 @@ class IDomain(Interface): The contact address for the human at this domain. E.g. postmaster@example.com""") + mailing_lists = Attribute("""All mailing lists for this domain."""); + def confirm_url(token=''): """The url used for various forms of confirmation. diff --git a/src/mailman/interfaces/listmanager.py b/src/mailman/interfaces/listmanager.py index 88060ce83..c1b7721a9 100644 --- a/src/mailman/interfaces/listmanager.py +++ b/src/mailman/interfaces/listmanager.py @@ -140,10 +140,3 @@ class IListManager(Interface): :return: The list of all known mailing lists. :rtype: list of `IMailingList` """ - - def get_lists_for_domain(): - """The list of all mailing lists for a particular domain. - - :return: The mailing lists for a particular domain. - :rtype: list of `IMailingList` - """ diff --git a/src/mailman/model/docs/domains.txt b/src/mailman/model/docs/domains.txt index 9fe43a5f1..00824d65c 100644 --- a/src/mailman/model/docs/domains.txt +++ b/src/mailman/model/docs/domains.txt @@ -71,6 +71,29 @@ Domains can have explicit descriptions and contact addresses. base_url: http://lists.example.net, contact_address: postmaster@example.com> +Domains can list all associated mailing lists with the mailing_lists +property. +:: + + >>> def show_lists(domain): + ... mlists = list(domain.mailing_lists) + ... for mlist in mlists: + ... print mlist + ... if len(mlists) == 0: + ... print "no lists" + + >>> net_domain = manager['example.net'] + >>> com_domain = manager['example.com'] + >>> show_lists(net_domain) + no lists + >>> create_list('test@example.net') + <mailing list "test@example.net" at ...> + >>> transaction.commit() + >>> show_lists(net_domain) + <mailing list "test@example.net" at ...> + >>> show_lists(com_domain) + no lists + In the global domain manager, domains are indexed by their email host name. :: diff --git a/src/mailman/model/domain.py b/src/mailman/model/domain.py index 083246469..95710171f 100644 --- a/src/mailman/model/domain.py +++ b/src/mailman/model/domain.py @@ -33,6 +33,7 @@ from mailman.config import config from mailman.database.model import Model from mailman.interfaces.domain import ( BadDomainSpecificationError, IDomain, IDomainManager) +from mailman.model.mailinglist import MailingList @@ -85,6 +86,14 @@ class Domain(Model): """See `IDomain`.""" return urlparse(self.base_url).scheme + @property + def mailing_lists(self): + """See `IDomain`.""" + mlist_iter = config.db.store.find(MailingList, + MailingList.mail_host == self.email_host) + for mlist in mlist_iter: + yield mlist + def confirm_url(self, token=''): """See `IDomain`.""" return urljoin(self.base_url, 'confirm/' + token) diff --git a/src/mailman/model/listmanager.py b/src/mailman/model/listmanager.py index 67b204b2a..fbbb85c06 100644 --- a/src/mailman/model/listmanager.py +++ b/src/mailman/model/listmanager.py @@ -103,7 +103,3 @@ class ListManager: # lazr.restful will not allow this to be a generator. return list(self.mailing_lists) - def get_lists_for_domain(self, domain): - """See `IListManager`.""" - return list(config.db.store.find(MailingList, MailingList.mail_host == domain)) - diff --git a/src/mailman/rest/docs/domains.txt b/src/mailman/rest/docs/domains.txt index 35546a56d..293d54c98 100644 --- a/src/mailman/rest/docs/domains.txt +++ b/src/mailman/rest/docs/domains.txt @@ -117,6 +117,49 @@ But we get a 404 for a non-existent domain. ... HTTPError: HTTP Error 404: 404 Not Found +You can also list mailing lists for a given domain by appending +`/lists` to the URL. + + >>> dump_json('http://localhost:9001/3.0/domains/example.com/lists') + http_etag: "..." + start: 0 + total_size: 0 + + >>> dump_json('http://localhost:9001/3.0/lists', { + ... 'fqdn_listname': 'test-domains@example.com', + ... }) + content-length: 0 + date: ... + location: http://localhost:9001/3.0/lists/test-domains@example.com + ... + + >>> dump_json('http://localhost:9001/3.0/domains/example.com/lists') + entry 0: + fqdn_listname: test-domains@example.com + http_etag: "..." + ... + self_link: http://localhost:9001/3.0/lists/test-domains@example.com + http_etag: "..." + start: 0 + total_size: 1 + + >>> dump_json('http://localhost:9001/3.0/domains/lists.example.net/lists') + http_etag: "..." + start: 0 + total_size: 0 + +Here are some poorly-formed URL's for testing purposes: + + >>> dump_json('http://localhost:9001/3.0/domains/example.com/lists/wrong') + Traceback (most recent call last): + ... + HTTPError: HTTP Error 400: 400 Bad Request + + >>> dump_json('http://localhost:9001/3.0/domains/example.com/wrong') + Traceback (most recent call last): + ... + HTTPError: HTTP Error 404: 404 Not Found + Creating new domains ==================== diff --git a/src/mailman/rest/docs/lists.rst b/src/mailman/rest/docs/lists.rst index a8b100a1b..f16daf00d 100644 --- a/src/mailman/rest/docs/lists.rst +++ b/src/mailman/rest/docs/lists.rst @@ -31,6 +31,7 @@ Create a mailing list in a domain and it's accessible via the API. total_size: 1 You can also query for lists from a particular domain. +:: >>> dump_json('http://localhost:9001/3.0/domains/example.com/lists') entry 0: @@ -44,10 +45,10 @@ You can also query for lists from a particular domain. start: 0 total_size: 1 - >>> dump_json('http://localhost:9001/3.0/domains/other.com/lists') - http_etag: "..." - start: 0 - total_size: 0 + >>> dump_json('http://localhost:9001/3.0/domains/no.example.org/lists') + Traceback (most recent call last): + ... + HTTPError: HTTP Error 404: 404 Not Found Creating lists via the API ========================== diff --git a/src/mailman/rest/domains.py b/src/mailman/rest/domains.py index 1f4077e0c..61cc28ca0 100644 --- a/src/mailman/rest/domains.py +++ b/src/mailman/rest/domains.py @@ -32,8 +32,8 @@ from zope.component import getUtility from mailman.interfaces.domain import ( BadDomainSpecificationError, IDomainManager) from mailman.rest.helpers import CollectionMixin, etag, no_content, path_to -from mailman.rest.validator import Validator from mailman.rest.lists import ListsForDomain +from mailman.rest.validator import Validator @@ -84,7 +84,10 @@ class ADomain(_DomainBase): def lists(self, request, segments): """/<api>/domains/<domain>/lists""" if len(segments) == 0: - return ListsForDomain(self._domain) + domain = getUtility(IDomainManager).get(self._domain) + if domain is None: + return http.not_found() + return ListsForDomain(domain) else: return http.bad_request() diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py index 8e8242ee8..91a2d7ded 100644 --- a/src/mailman/rest/lists.py +++ b/src/mailman/rest/lists.py @@ -224,5 +224,5 @@ class ListsForDomain(_ListBase): def _get_collection(self, request): """See `CollectionMixin`.""" - return getUtility(IListManager).get_lists_for_domain(self._domain) + return list(self._domain.mailing_lists) |
