summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/rest/docs/users.txt9
-rw-r--r--src/mailman/rest/users.py17
2 files changed, 24 insertions, 2 deletions
diff --git a/src/mailman/rest/docs/users.txt b/src/mailman/rest/docs/users.txt
index fcdbdd952..3dfa29bc8 100644
--- a/src/mailman/rest/docs/users.txt
+++ b/src/mailman/rest/docs/users.txt
@@ -82,3 +82,12 @@ It is of course an error to access a non-existent user id.
...
HTTPError: HTTP Error 404: 404 Not Found
+Because email addresses just have an ``@`` sign in then, there's no confusing
+them with user ids. Thus, a user can be retrieved via its email address.
+
+ >>> dump_json('http://localhost:9001/3.0/users/bart@example.com')
+ created_on: 2005-08-01T07:49:23
+ http_etag: "..."
+ password: None
+ real_name: Bart Person
+ user_id: 2
diff --git a/src/mailman/rest/users.py b/src/mailman/rest/users.py
index b8972f3f5..9a00cecd2 100644
--- a/src/mailman/rest/users.py
+++ b/src/mailman/rest/users.py
@@ -95,8 +95,21 @@ class AllUsers(_UserBase):
class AUser(_UserBase):
"""A user."""
- def __init__(self, user_id):
- self._user = getUtility(IUserManager).get_user_by_id(user_id)
+ def __init__(self, user_identifier):
+ """Get a user by various type of identifiers.
+
+ :param user_identifier: The identifier used to retrieve the user. The
+ identifier may either be an integer user-id, or an email address
+ controlled by the user. The type of identifier is auto-detected
+ by looking for an `@` symbol, in which case it's taken as an email
+ address, otherwise it's assumed to be an integer.
+ :type user_identifier: str
+ """
+ user_manager = getUtility(IUserManager)
+ if '@' in user_identifier:
+ self._user = user_manager.get_user(user_identifier)
+ else:
+ self._user = user_manager.get_user_by_id(user_identifier)
@resource.GET()
def user(self, request):