summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/app/docs/lifecycle.txt2
-rw-r--r--src/mailman/rest/docs/lists.txt42
-rw-r--r--src/mailman/rest/helpers.py10
-rw-r--r--src/mailman/rest/lists.py15
-rw-r--r--src/mailman/tests/test_documentation.py1
5 files changed, 65 insertions, 5 deletions
diff --git a/src/mailman/app/docs/lifecycle.txt b/src/mailman/app/docs/lifecycle.txt
index a1cd50825..959c08cc8 100644
--- a/src/mailman/app/docs/lifecycle.txt
+++ b/src/mailman/app/docs/lifecycle.txt
@@ -121,7 +121,7 @@ the system, they won't be created again.
[u'Anne Person', u'Bart Person', u'Caty Person', u'Dirk Person']
-Removing a list
+Deleting a list
===============
Removing a mailing list deletes the list, all its subscribers, and any related
diff --git a/src/mailman/rest/docs/lists.txt b/src/mailman/rest/docs/lists.txt
index 6abf29a1d..504d16feb 100644
--- a/src/mailman/rest/docs/lists.txt
+++ b/src/mailman/rest/docs/lists.txt
@@ -48,7 +48,9 @@ The mailing list exists in the database.
>>> from mailman.interfaces.listmanager import IListManager
>>> from zope.component import getUtility
- >>> getUtility(IListManager).get('test-two@example.com')
+ >>> list_manager = getUtility(IListManager)
+
+ >>> list_manager.get('test-two@example.com')
<mailing list "test-two@example.com" at ...>
# The above starts a Storm transaction, which will lock the database
@@ -83,3 +85,41 @@ Nor can you create a mailing list that already exists.
Traceback (most recent call last):
...
HTTPError: HTTP Error 400: Bad Request
+
+
+Deleting lists via the API
+==========================
+
+Existing mailing lists can be deleted through the API, by doing an HTTP DELETE
+on the mailing list URL.
+
+ >>> dump_json('http://localhost:8001/3.0/lists/test-two@example.com',
+ ... method='DELETE')
+ content-length: 0
+ date: ...
+ server: ...
+ status: 204
+
+ # The above starts a Storm transaction, which will lock the database
+ # unless we abort it.
+ >>> transaction.abort()
+
+The mailing list does not exist.
+
+ >>> print list_manager.get('test-two@example.com')
+ None
+
+You cannot delete a mailing list that does not exist or has already been
+deleted.
+
+ >>> dump_json('http://localhost:8001/3.0/lists/test-two@example.com',
+ ... method='DELETE')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 404: Not Found
+
+ >>> dump_json('http://localhost:8001/3.0/lists/test-ten@example.com',
+ ... method='DELETE')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 404: Not Found
diff --git a/src/mailman/rest/helpers.py b/src/mailman/rest/helpers.py
index 8a82ebb60..be5d2b565 100644
--- a/src/mailman/rest/helpers.py
+++ b/src/mailman/rest/helpers.py
@@ -23,6 +23,7 @@ __metaclass__ = type
__all__ = [
'ContainerMixin',
'etag',
+ 'no_content',
'path_to',
'restish_matcher',
]
@@ -32,8 +33,11 @@ import json
import hashlib
from lazr.config import as_boolean
+from restish.http import Response
+
from mailman.config import config
+
COMMASPACE = ', '
@@ -173,3 +177,9 @@ def restish_matcher(function):
"""Decorator for restish matchers."""
function.score = ()
return function
+
+
+# restish doesn't support HTTP response code 204.
+def no_content():
+ """204 No Content."""
+ return Response('204 No Content', [], None)
diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py
index 5d7ed0c86..ddda613c9 100644
--- a/src/mailman/rest/lists.py
+++ b/src/mailman/rest/lists.py
@@ -29,13 +29,13 @@ __all__ = [
from restish import http, resource
from zope.component import getUtility
-from mailman.app.lifecycle import create_list
+from mailman.app.lifecycle import create_list, remove_list
from mailman.interfaces.domain import BadDomainSpecificationError
from mailman.interfaces.listmanager import (
IListManager, ListAlreadyExistsError)
from mailman.interfaces.member import MemberRole
from mailman.rest.helpers import (
- CollectionMixin, Validator, etag, path_to, restish_matcher)
+ CollectionMixin, Validator, etag, no_content, path_to, restish_matcher)
from mailman.rest.members import AMember, MembersOfList
@@ -112,6 +112,17 @@ class AList(_ListBase):
return http.not_found()
return http.ok([], self._resource_as_json(self._mlist))
+ @resource.DELETE()
+ def delete_list(self, request):
+ """Delete the named mailing list."""
+ if self._mlist is None:
+ return http.not_found()
+ remove_list(self._mlist.fqdn_listname, self._mlist,
+ # XXX 2010-07-06 barry we need a way to remove the list
+ # archives either with the mailing list or afterward.
+ archives=False)
+ return no_content()
+
@resource.child(member_matcher)
def member(self, request, segments, role, address):
"""Return a single member representation."""
diff --git a/src/mailman/tests/test_documentation.py b/src/mailman/tests/test_documentation.py
index 255725356..b8e98d162 100644
--- a/src/mailman/tests/test_documentation.py
+++ b/src/mailman/tests/test_documentation.py
@@ -134,7 +134,6 @@ def dump_json(url, data=None, method=None):
# exception, for backward compatibility with existing doctests.
if response.status // 100 != 2:
raise HTTPError(url, response.status, response.reason, response, None)
- # fp does not support the context manager protocol.
if len(content) == 0:
for header in sorted(response):
print '{0}: {1}'.format(header, response[header])