diff options
| author | Barry Warsaw | 2011-04-05 18:54:31 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2011-04-05 18:54:31 -0400 |
| commit | d8ecd977cf11b60ce4851315ecc9855be71d9596 (patch) | |
| tree | f9c2b8892a8ee481d1f5eca0c05ede314d5ba99f | |
| parent | b8cf7e9df8bd9e979a3236054caaf4d28af35a94 (diff) | |
| download | mailman-d8ecd977cf11b60ce4851315ecc9855be71d9596.tar.gz mailman-d8ecd977cf11b60ce4851315ecc9855be71d9596.tar.zst mailman-d8ecd977cf11b60ce4851315ecc9855be71d9596.zip | |
| -rw-r--r-- | src/mailman/rest/docs/users.txt | 9 | ||||
| -rw-r--r-- | src/mailman/rest/users.py | 17 |
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): |
