summaryrefslogtreecommitdiff
path: root/src/mailman/rest/lists.py
diff options
context:
space:
mode:
authorBarry Warsaw2010-08-10 22:10:55 -0400
committerBarry Warsaw2010-08-10 22:10:55 -0400
commit988d14e05757ee50fe944d2deb9c6bd48e680d2f (patch)
treedeeb58c340d060edc081b44726c2ea34902d46ff /src/mailman/rest/lists.py
parentde7f01e3836379e0902c2ac4b6b6691b955f2257 (diff)
downloadmailman-988d14e05757ee50fe944d2deb9c6bd48e680d2f.tar.gz
mailman-988d14e05757ee50fe944d2deb9c6bd48e680d2f.tar.zst
mailman-988d14e05757ee50fe944d2deb9c6bd48e680d2f.zip
Diffstat (limited to 'src/mailman/rest/lists.py')
-rw-r--r--src/mailman/rest/lists.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py
index 6e297d0ed..5b76abbf0 100644
--- a/src/mailman/rest/lists.py
+++ b/src/mailman/rest/lists.py
@@ -36,6 +36,7 @@ from mailman.config import config
from mailman.interfaces.domain import BadDomainSpecificationError
from mailman.interfaces.listmanager import (
IListManager, ListAlreadyExistsError)
+from mailman.interfaces.mailinglist import IAcceptableAliasSet
from mailman.interfaces.member import MemberRole
from mailman.rest.helpers import (
CollectionMixin, PATCH, Validator, etag, no_content, path_to,
@@ -96,6 +97,19 @@ def config_matcher(request, segments):
return None
+@restish_matcher
+def subresource_config_matcher(request, segments):
+ """A matcher for configuration sub-resources.
+
+ e.g. /config/acceptable_aliases
+ """
+ if len(segments) != 2 or segments[0] != 'config':
+ return None
+ # Don't check here whether it's a known subresource or not. Let that be
+ # done in subresource_config() method below.
+ return (), dict(attribute=segments[1]), ()
+
+
class _ListBase(resource.Resource, CollectionMixin):
"""Shared base class for mailing list representations."""
@@ -154,6 +168,19 @@ class AList(_ListBase):
"""Return a mailing list configuration object."""
return ListConfiguration(self._mlist)
+ @resource.child(subresource_config_matcher)
+ def subresource_config(self, request, segments, attribute):
+ """Return the subresource configuration object.
+
+ This will return a Bad Request if it isn't a known subresource.
+ """
+ missing = object()
+ subresource_class = SUBRESOURCES.get(attribute, missing)
+ if subresource_class is missing:
+ return http.bad_request(
+ [], 'Unknown attribute {0}'.format(attribute))
+ return subresource_class(self._mlist, attribute)
+
class AllLists(_ListBase):
@@ -281,3 +308,40 @@ class ListConfiguration(resource.Resource):
except ValueError as error:
return http.bad_request([], str(error))
return http.ok([], '')
+
+
+
+class AcceptableAliases(resource.Resource):
+ """Resource for the acceptable aliases of a mailing list."""
+
+ def __init__(self, mailing_list, attribute):
+ assert attribute == 'acceptable_aliases', (
+ 'unexpected attribute: {0}'.format(attribute))
+ self._mlist = mailing_list
+
+ @resource.GET()
+ def aliases(self, request):
+ """Return the mailing list's acceptable aliases."""
+ aliases = IAcceptableAliasSet(self._mlist)
+ resource = dict(aliases=list(aliases.aliases))
+ return http.ok([], etag(resource))
+
+ @resource.PUT()
+ def put_configuration(self, request):
+ """Change the acceptable aliases.
+
+ Because this is a PUT operation, all previous aliases are cleared
+ first. Thus, this is an overwrite. The keys in the request are
+ ignored.
+ """
+ aliases = IAcceptableAliasSet(self._mlist)
+ aliases.clear()
+ for alias in request.POST.values():
+ aliases.add(unicode(alias))
+ return http.ok([], '')
+
+
+
+SUBRESOURCES = dict(
+ acceptable_aliases=AcceptableAliases,
+ )