diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 1 | ||||
| -rw-r--r-- | src/mailman/rest/docs/users.rst (renamed from src/mailman/rest/docs/users.txt) | 23 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_users.py | 64 | ||||
| -rw-r--r-- | src/mailman/rest/users.py | 10 |
4 files changed, 94 insertions, 4 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 1057e2962..b83c0186a 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -33,6 +33,7 @@ REST * Remove role plurals from /lists/<fqdn_listname/rosters/<role> * Fixed incorrect error code for /members/<bogus> (LP: #821020). Given by Stephen A. Goss. + * DELETE users via the REST API. (LP: #820660) Commands -------- diff --git a/src/mailman/rest/docs/users.txt b/src/mailman/rest/docs/users.rst index 114ca4e49..4f73e12e7 100644 --- a/src/mailman/rest/docs/users.txt +++ b/src/mailman/rest/docs/users.rst @@ -13,14 +13,14 @@ There are no users yet. http_etag: "..." start: 0 total_size: 0 - + When there are users in the database, they can be retrieved as a collection. :: >>> from zope.component import getUtility >>> from mailman.interfaces.usermanager import IUserManager >>> user_manager = getUtility(IUserManager) - + >>> anne = user_manager.create_user('anne@example.com', 'Anne Person') >>> transaction.commit() >>> dump_json('http://localhost:9001/3.0/users') @@ -44,7 +44,7 @@ A user might not have a real name, in which case, the attribute will not be returned in the REST API. >>> dave = user_manager.create_user('dave@example.com') - >>> transaction.commit() + >>> transaction.commit() >>> dump_json('http://localhost:9001/3.0/users') entry 0: created_on: 2005-08-01T07:49:23 @@ -134,6 +134,23 @@ therefore cannot be retrieved. It can be reset though. user_id: 4 +Deleting users via the API +========================== + +Users can also be deleted via the API. + + >>> dump_json('http://localhost:9001/3.0/users/cris@example.com', + ... method='DELETE') + content-length: 0 + date: ... + server: ... + status: 204 + >>> dump_json('http://localhost:9001/3.0/users/cris@example.com') + Traceback (most recent call last): + ... + HTTPError: HTTP Error 404: 404 Not Found + + Missing users ============= diff --git a/src/mailman/rest/tests/test_users.py b/src/mailman/rest/tests/test_users.py new file mode 100644 index 000000000..8b31010f3 --- /dev/null +++ b/src/mailman/rest/tests/test_users.py @@ -0,0 +1,64 @@ +# Copyright (C) 2011 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/>. + +"""REST user tests.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'test_suite', + ] + + +import unittest + +from urllib2 import HTTPError +from zope.component import getUtility + +from mailman.app.lifecycle import create_list +from mailman.config import config +from mailman.interfaces.usermanager import IUserManager +from mailman.testing.helpers import call_api +from mailman.testing.layers import RESTLayer + + + +class TestUsers(unittest.TestCase): + layer = RESTLayer + + def setUp(self): + self._mlist = create_list('test@example.com') + config.db.commit() + self._usermanager = getUtility(IUserManager) + + def test_delete_bogus_user(self): + # Try to delete a user that does not exist. + try: + # For Python 2.6. + call_api('http://localhost:9001/3.0/users/99', method='DELETE') + except HTTPError as exc: + self.assertEqual(exc.code, 404) + else: + raise AssertionError('Expected HTTPError') + + + +def test_suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestUsers)) + return suite diff --git a/src/mailman/rest/users.py b/src/mailman/rest/users.py index a75b448e7..29a18a45f 100644 --- a/src/mailman/rest/users.py +++ b/src/mailman/rest/users.py @@ -32,7 +32,7 @@ from zope.component import getUtility from mailman.interfaces.address import ExistingAddressError from mailman.interfaces.usermanager import IUserManager from mailman.rest.addresses import UserAddresses -from mailman.rest.helpers import CollectionMixin, etag, path_to +from mailman.rest.helpers import CollectionMixin, etag, no_content, path_to from mailman.rest.validator import Validator from mailman.utilities.passwords import ( encrypt_password, make_user_friendly_password) @@ -134,3 +134,11 @@ class AUser(_UserBase): def addresses(self, request, segments): """/users/<uid>/addresses""" return UserAddresses(self._user) + + @resource.DELETE() + def delete_user(self, request): + """Delete the named user.""" + if self._user is None: + return http.not_found() + getUtility(IUserManager).delete_user(self._user) + return no_content() |
