Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits: 5ba4b41f by Abhilash Raj at 2020-12-15T12:06:32+05:30 Allow updating display_name attribute of an Address. Closes #786 - - - - - 551f6fac by Abhilash Raj at 2020-12-16T09:21:32+00:00 Merge branch 'edit-address-name' into 'master' Allow updating display_name attribute of an Address. Closes #786 See merge request mailman/mailman!746 - - - - - 4 changed files: - src/mailman/docs/NEWS.rst - src/mailman/rest/addresses.py - src/mailman/rest/docs/addresses.rst - src/mailman/rest/tests/test_addresses.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== @@ -41,6 +41,7 @@ REST ---- * List configuration option ``send_goodbye_message`` is now exposed through the REST API. (See !737) +* Allow updating an Addresses' display_name attribute. (Closes #786) 3.3.2 ===== ===================================== src/mailman/rest/addresses.py ===================================== @@ -155,6 +155,24 @@ class AnAddress(_AddressBase): else: okay(response, self._resource_as_json(self._address)) + def on_patch(self, request, response): + """Patch an existing Address.""" + if self._address is None: + not_found(response) + else: + # The only attribute of a address that can be PATCH'd is the + # display_name. To change the verified_on, use the /verify + # endpoint. + validator = Validator(display_name=str) + try: + data = validator(request) + except ValueError as error: + bad_request(response, str(error)) + return + display_name = data.pop('display_name') + self._address.display_name = display_name + no_content(response) + def on_delete(self, request, response): if self._address is None: not_found(response) ===================================== src/mailman/rest/docs/addresses.rst ===================================== @@ -138,6 +138,29 @@ Now Cris's address is unverified. self_link: http://localhost:9001/3.0/addresses/c...@example.com +Updating +======== + +Each address has a ``display_name`` associated with it. This name can be +updated by PATCH'ing the address resource:: + + >>> dump_json('http://localhost:9001/3.0/addresses/c...@example.com', + ... method='PATCH', data={'display_name': 'Cris P. Person'}) + date: ... + server: ... + status: 204 + +This should update the display_name associated:: + + >>> dump_json('http://localhost:9001/3.0/addresses/c...@example.com') + display_name: Cris P. Person + email: c...@example.com + http_etag: "..." + original_email: c...@example.com + registered_on: 2005-08-01T07:49:23 + self_link: http://localhost:9001/3.0/addresses/c...@example.com + + The user ======== @@ -168,7 +191,7 @@ The user is now created and the address is linked to it: A link to the user resource is now available as a sub-resource. >>> dump_json('http://localhost:9001/3.0/addresses/c...@example.com') - display_name: Cris Person + display_name: Cris P. Person email: c...@example.com http_etag: "..." original_email: c...@example.com ===================================== src/mailman/rest/tests/test_addresses.py ===================================== @@ -498,6 +498,34 @@ class TestAddresses(unittest.TestCase): 'nob...@example.com/addresses') self.assertEqual(cm.exception.code, 404) + def test_update_display_name(self): + verified_on = now() + with transaction(): + anne = getUtility(IUserManager).create_address('a...@example.com') + anne.verified_on = verified_on + json, response = call_api( + 'http://localhost:9001/3.0/addresses/a...@example.com') + # By default, there won't be any display_name since we didn't specify + # any above when creating the address. + self.assertFalse('display_name' in json) + json, response = call_api( + 'http://localhost:9001/3.0/addresses/a...@example.com', + method='PATCH', data={'display_name': 'Anne Person'}) + self.assertEqual(response.status_code, 204) + # Now the address should have a display_name set. + json, response = call_api( + 'http://localhost:9001/3.0/addresses/a...@example.com') + self.assertEqual(json['display_name'], 'Anne Person') + # This name can also be updated. + json, response = call_api( + 'http://localhost:9001/3.0/addresses/a...@example.com', + method='PATCH', data={'display_name': 'Anne P. Person'}) + self.assertEqual(response.status_code, 204) + # Now the address should have a display_name updated to new one. + json, response = call_api( + 'http://localhost:9001/3.0/addresses/a...@example.com') + self.assertEqual(json['display_name'], 'Anne P. Person') + class TestAPI31Addresses(unittest.TestCase): """UUIDs are represented as hex instead of int in API 3.1 View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/cd6c23b7f962f6022183fd1f742ebd2e96247fa9...551f6facd65d99bdff3591b50442a889e92dee5e -- View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/cd6c23b7f962f6022183fd1f742ebd2e96247fa9...551f6facd65d99bdff3591b50442a889e92dee5e You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list -- mailman-checkins@python.org To unsubscribe send an email to mailman-checkins-le...@python.org https://mail.python.org/mailman3/lists/mailman-checkins.python.org/ Member address: arch...@jab.org