diff options
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 2 | ||||
| -rw-r--r-- | src/mailman/rest/addresses.py | 7 | ||||
| -rw-r--r-- | src/mailman/rest/docs/addresses.rst | 61 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_addresses.py | 9 |
4 files changed, 79 insertions, 0 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index a235a98a3..600b9f151 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -40,6 +40,8 @@ REST ---- * You can now view the contents of, inject messages into, and delete messages from the various queue directories via the ``<api>/queues`` resource. + * You can now DELETE an address. If the address is linked to a user, the + user is not delete, it is just unlinked. 3.0 beta 5 -- "Carve Away The Stone" diff --git a/src/mailman/rest/addresses.py b/src/mailman/rest/addresses.py index 2ce456b98..ca00938ba 100644 --- a/src/mailman/rest/addresses.py +++ b/src/mailman/rest/addresses.py @@ -114,6 +114,13 @@ class AnAddress(_AddressBase): else: okay(response, self._resource_as_json(self._address)) + def on_delete(self, request, response): + if self._address is None: + not_found(response) + else: + getUtility(IUserManager).delete_address(self._address) + no_content(response) + @child() def memberships(self, request, segments): """/addresses/<email>/memberships""" diff --git a/src/mailman/rest/docs/addresses.rst b/src/mailman/rest/docs/addresses.rst index bcffd6830..8629bb8ae 100644 --- a/src/mailman/rest/docs/addresses.rst +++ b/src/mailman/rest/docs/addresses.rst @@ -446,3 +446,64 @@ does not show up in the list of memberships for his other address. http_etag: "..." start: 0 total_size: 1 + + + + +Deleting +======== + +Addresses can be deleted via the REST API. +:: + + >>> fred = user_manager.create_address('fred@example.com', 'Fred Person') + >>> transaction.commit() + >>> dump_json('http://localhost:9001/3.0/addresses/fred@example.com') + display_name: Fred Person + email: fred@example.com + http_etag: "..." + original_email: fred@example.com + registered_on: 2005-08-01T07:49:23 + self_link: http://localhost:9001/3.0/addresses/fred@example.com + + >>> dump_json('http://localhost:9001/3.0/addresses/fred@example.com', + ... method='DELETE') + content-length: 0 + date: ... + server: ... + status: 204 + >>> transaction.abort() + + >>> print(user_manager.get_address('fred@example.com')) + None + +If an address is linked to a user, deleting the address does not delete the +user, it just unlinks it. +:: + + >>> gwen = user_manager.create_user('gwen@example.com', 'Gwen Person') + >>> transaction.commit() + >>> dump_json('http://localhost:9001/3.0/users/5/addresses') + entry 0: + display_name: Gwen Person + email: gwen@example.com + http_etag: "..." + original_email: gwen@example.com + registered_on: 2005-08-01T07:49:23 + self_link: http://localhost:9001/3.0/addresses/gwen@example.com + user: http://localhost:9001/3.0/users/5 + http_etag: "795b0680c57ec2df3dceb68ccce2619fecdc7225" + start: 0 + total_size: 1 + + >>> dump_json('http://localhost:9001/3.0/addresses/gwen@example.com', + ... method='DELETE') + content-length: 0 + date: ... + server: ... + status: 204 + + >>> dump_json('http://localhost:9001/3.0/users/5/addresses') + http_etag: "..." + start: 0 + total_size: 0 diff --git a/src/mailman/rest/tests/test_addresses.py b/src/mailman/rest/tests/test_addresses.py index 584b81695..d03dc79d7 100644 --- a/src/mailman/rest/tests/test_addresses.py +++ b/src/mailman/rest/tests/test_addresses.py @@ -382,3 +382,12 @@ class TestAddresses(unittest.TestCase): anne_addr = user_manager.get_address('anne@example.com') self.assertIsNotNone(anne_addr) self.assertEqual(anne_addr.user, anne_person) + + def test_delete_missing_address(self): + # DELETEing an address through the REST API that doesn't exist returns + # a 404 error. + with self.assertRaises(HTTPError) as cm: + response, headers = call_api( + 'http://localhost:9001/3.0/addresses/anne@example.com', + method='DELETE') + self.assertEqual(cm.exception.code, 404) |
