summaryrefslogtreecommitdiff
path: root/src/mailman/rest/members.py
diff options
context:
space:
mode:
authorBarry Warsaw2014-04-15 17:54:35 -0400
committerBarry Warsaw2014-04-15 17:54:35 -0400
commit13823e4d2b9bea190dd207a02a8107bc43ee49fe (patch)
tree0917bab22a2d9d422567c80d2c27a4e601103ea2 /src/mailman/rest/members.py
parent29d6d587389c32eb84d7faa51e3072e02e385c2d (diff)
downloadmailman-13823e4d2b9bea190dd207a02a8107bc43ee49fe.tar.gz
mailman-13823e4d2b9bea190dd207a02a8107bc43ee49fe.tar.zst
mailman-13823e4d2b9bea190dd207a02a8107bc43ee49fe.zip
* Fixed a crash in the REST server when searching for nonmembers via
``/find`` which we've never seen before, because those members only have an address record, not a user record. This requires a small change in the API where the JSON response's ``address`` key now contains the URL to the address resource, the new ``email`` key contains the email address as a string, and the ``user`` key is optional.
Diffstat (limited to 'src/mailman/rest/members.py')
-rw-r--r--src/mailman/rest/members.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/mailman/rest/members.py b/src/mailman/rest/members.py
index 5be7a4525..4aef93e34 100644
--- a/src/mailman/rest/members.py
+++ b/src/mailman/rest/members.py
@@ -56,18 +56,25 @@ class _MemberBase(resource.Resource, CollectionMixin):
def _resource_as_dict(self, member):
"""See `CollectionMixin`."""
enum, dot, role = str(member.role).partition('.')
- # Both the user_id and the member_id are UUIDs. We need to use the
- # integer equivalent in the URL.
- user_id = member.user.user_id.int
- member_id = member.member_id.int
- return dict(
+ # The member will always have a member id and an address id. It will
+ # only have a user id if the address is linked to a user.
+ # E.g. nonmembers we've only seen via postings to lists they are not
+ # subscribed to will not have a user id. The user_id and the
+ # member_id are UUIDs. We need to use the integer equivalent in the
+ # URL.
+ response = dict(
list_id=member.list_id,
- address=member.address.email,
+ email=member.address.email,
role=role,
- user=path_to('users/{0}'.format(user_id)),
- self_link=path_to('members/{0}'.format(member_id)),
+ address=path_to('addresses/{}'.format(member.address.email)),
+ self_link=path_to('members/{}'.format(member.member_id.int)),
delivery_mode=member.delivery_mode,
)
+ # Add the user link if there is one.
+ user = member.user
+ if user is not None:
+ response['user'] = path_to('users/{}'.format(user.user_id.int))
+ return response
@paginate
def _get_collection(self, request):