diff options
| -rwxr-xr-x | copybump.py | 27 | ||||
| -rw-r--r-- | src/mailman/interfaces/member.py | 4 | ||||
| -rw-r--r-- | src/mailman/interfaces/membership.py | 55 | ||||
| -rw-r--r-- | src/mailman/rest/adapters.py | 30 | ||||
| -rw-r--r-- | src/mailman/rest/configure.zcml | 6 | ||||
| -rw-r--r-- | src/mailman/rest/docs/membership.txt | 25 | ||||
| -rw-r--r-- | src/mailman/rest/urls.py | 2 | ||||
| -rw-r--r-- | src/mailman/rest/webservice.py | 2 |
8 files changed, 151 insertions, 0 deletions
diff --git a/copybump.py b/copybump.py new file mode 100755 index 000000000..0b9bdf6b9 --- /dev/null +++ b/copybump.py @@ -0,0 +1,27 @@ +#! /usr/bin/env python3 + +import os +import re +import datetime + + +FSF = 'by the Free Software Foundation, Inc.' +this_year = datetime.date.today().year +pyre = re.compile(r'^# Copyright (C) (?P<start>\d{4}-)?(?P<end>\d{4})') + + +def do_file(path): + with open(path) as in_file, open(path + '.out', 'w') as out_file: + for line in in_file: + mo = pyre.match(line) + if mo is None: + out_file.write(line) + continue + start = (mo.group('end') + if mo.group('start') is None + else mo.group('start')) + print('# Copyright (C) {}-{} {}'.format( + mo.group('end'), this_year, FSF), file=out_file) + for line in in_file: + out_file.write(line) + os.rename(path + '.out', path) diff --git a/src/mailman/interfaces/member.py b/src/mailman/interfaces/member.py index 2e966879d..e5a82060a 100644 --- a/src/mailman/interfaces/member.py +++ b/src/mailman/interfaces/member.py @@ -29,6 +29,8 @@ __all__ = [ ] +from lazr.restful.declarations import ( + export_as_webservice_entry, exported) from munepy import Enum from zope.interface import Interface, Attribute @@ -87,6 +89,8 @@ class AlreadySubscribedError(SubscriptionError): class IMember(Interface): """A member of a mailing list.""" + export_as_webservice_entry() + mailing_list = Attribute( """The mailing list subscribed to.""") diff --git a/src/mailman/interfaces/membership.py b/src/mailman/interfaces/membership.py new file mode 100644 index 000000000..0a04ff630 --- /dev/null +++ b/src/mailman/interfaces/membership.py @@ -0,0 +1,55 @@ +# Copyright (C) 2009 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Membership interface for REST.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'SubscriptionService', + ] + + +from lazr.restful.declarations import ( + collection_default_content, export_as_webservice_collection, + export_factory_operation) +from zope.interface import Interface + +from mailman.core.i18n import _ +from mailman.interfaces.member import IMember + + + +class ISubscriptionService(Interface): + """Subscription services for the REST API.""" + + export_as_webservice_collection(IMember) + + @collection_default_content() + def get_members(): + """Return a sequence of all members of all mailing lists. + + The members are sorted first by fully-qualified mailing list name, + then by subscribed email address, then by role. Because the user may + be a member of the list under multiple roles (e.g. as an owner and as + a digest member), the member can appear multiple times in this list. + Roles are sorted by: owner, moderator, member. + + :return: The list of all members. + :rtype: list of `IMember` + """ diff --git a/src/mailman/rest/adapters.py b/src/mailman/rest/adapters.py index 5389f4355..720bdd7cb 100644 --- a/src/mailman/rest/adapters.py +++ b/src/mailman/rest/adapters.py @@ -32,6 +32,8 @@ from zope.interface import implements from zope.publisher.interfaces import NotFound from mailman.interfaces.domain import IDomainCollection, IDomainManager +from mailman.interfaces.listmanager import IListManager +from mailman.interfaces.membership import ISubscriptionService from mailman.interfaces.rest import IResolvePathNames @@ -61,3 +63,31 @@ class DomainCollection: value = getUtility(IDomainManager).add( email_host, description, base_url, contact_address) return value + + + +class SubscriptionService: + """Subscription services for the REST API.""" + + implements(ISubscriptionService, IResolvePathNames) + + __name__ = 'members' + + def get_members(self): + """See `ISubscriptionService`.""" + # lazr.restful requires the return value to be a concrete list. + members = [] + address_of_member = attrgetter('address.address') + list_manager = getUtility(IListManager) + for fqdn_listname in sorted(list_manager.names): + mailing_list = list_manager.get(fqdn_listname) + members.extend( + sorted((member for member in mailing_list.owners.members), + key=address_of_member)) + members.extend( + sorted((member for member in mailing_list.moderators.members), + key=address_of_member)) + members.extend( + sorted((member for member in mailing_list.members.members), + key=address_of_member)) + return members diff --git a/src/mailman/rest/configure.zcml b/src/mailman/rest/configure.zcml index 1441472c8..6a181f671 100644 --- a/src/mailman/rest/configure.zcml +++ b/src/mailman/rest/configure.zcml @@ -10,6 +10,7 @@ <webservice:register module="mailman.interfaces.domain" /> <webservice:register module="mailman.interfaces.listmanager" /> + <webservice:register module="mailman.interfaces.membership" /> <webservice:register module="mailman.interfaces.system" /> <adapter factory="zope.publisher.http.HTTPCharsets" /> @@ -53,4 +54,9 @@ provides="mailman.interfaces.domain.IDomainCollection" /> + <utility + factory="mailman.rest.adapters.SubscriptionService" + provides="mailman.interfaces.membership.ISubscriptionService" + /> + </configure> diff --git a/src/mailman/rest/docs/membership.txt b/src/mailman/rest/docs/membership.txt new file mode 100644 index 000000000..e1b60e084 --- /dev/null +++ b/src/mailman/rest/docs/membership.txt @@ -0,0 +1,25 @@ +========== +Membership +========== + +The REST API can be used to subscribe and unsubscribe users to mailing lists. +A subscribed user is called a 'member'. There is a top level collection that +returns all the members of all known mailing lists. + +There are no mailing lists and no members yet. + + >>> dump_json('http://localhost:8001/3.0/members') + resource_type_link: http://localhost:8001/3.0/#members + start: None + total_size: 0 + +We create a mailing list, which starts out with no members. + + >>> create_list('test-one@example.com') + <mailing list "test-one@example.com" at ...> + >>> transaction.commit() + + >>> dump_json('http://localhost:8001/3.0/members') + resource_type_link: http://localhost:8001/3.0/#members + start: None + total_size: 0 diff --git a/src/mailman/rest/urls.py b/src/mailman/rest/urls.py index e631f1f9b..8f0409eb0 100644 --- a/src/mailman/rest/urls.py +++ b/src/mailman/rest/urls.py @@ -35,6 +35,7 @@ from zope.traversing.browser.interfaces import IAbsoluteURL from mailman.config import config from mailman.core.system import system from mailman.interfaces.listmanager import IListManager +from mailman.interfaces.membership import ISubscriptionService from mailman.rest.configuration import AdminWebServiceConfiguration from mailman.rest.webservice import AdminWebServiceApplication @@ -84,6 +85,7 @@ class FallbackURLMapper(BasicURLMapper): urls = { system: 'system', getUtility(IListManager): 'lists', + getUtility(ISubscriptionService): 'members', } return urls[ob] diff --git a/src/mailman/rest/webservice.py b/src/mailman/rest/webservice.py index d0c448572..914bf7d28 100644 --- a/src/mailman/rest/webservice.py +++ b/src/mailman/rest/webservice.py @@ -43,6 +43,7 @@ from mailman.config import config from mailman.core.system import system from mailman.interfaces.domain import IDomainCollection, IDomainManager from mailman.interfaces.listmanager import IListManager +from mailman.interfaces.membership import ISubscriptionService from mailman.interfaces.rest import IResolvePathNames from mailman.rest.publication import AdminWebServicePublication @@ -82,6 +83,7 @@ class AdminWebServiceApplication: system=system, domains=getUtility(IDomainCollection), lists=getUtility(IListManager), + members=getUtility(ISubscriptionService), ) next_step = top_level.get(name) log.debug('Top level name: %s -> %s', name, next_step) |
