diff options
author | Ashish Kumar <ashfame@users.noreply.github.com> | 2022-11-11 19:38:17 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-11 15:38:17 +0000 |
commit | a3623af74e0af0d2f6cbd37b47dc54a1acd314d5 (patch) | |
tree | 75eb73d5832e371e47dffcc571bc6e35ce523939 /synapse/rest/admin/users.py | |
parent | Merge/remove `Slaved*` stores into `WorkerStores` (#14375) (diff) | |
download | synapse-a3623af74e0af0d2f6cbd37b47dc54a1acd314d5.tar.xz |
Add an Admin API endpoint for looking up users based on 3PID (#14405)
Diffstat (limited to 'synapse/rest/admin/users.py')
-rw-r--r-- | synapse/rest/admin/users.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/synapse/rest/admin/users.py b/synapse/rest/admin/users.py index 15ac2059aa..1951b8a9f2 100644 --- a/synapse/rest/admin/users.py +++ b/synapse/rest/admin/users.py @@ -1224,3 +1224,28 @@ class UserByExternalId(RestServlet): raise NotFoundError("User not found") return HTTPStatus.OK, {"user_id": user_id} + + +class UserByThreePid(RestServlet): + """Find a user based on 3PID of a particular medium""" + + PATTERNS = admin_patterns("/threepid/(?P<medium>[^/]*)/users/(?P<address>[^/]*)") + + def __init__(self, hs: "HomeServer"): + self._auth = hs.get_auth() + self._store = hs.get_datastores().main + + async def on_GET( + self, + request: SynapseRequest, + medium: str, + address: str, + ) -> Tuple[int, JsonDict]: + await assert_requester_is_admin(self._auth, request) + + user_id = await self._store.get_user_id_by_threepid(medium, address) + + if user_id is None: + raise NotFoundError("User not found") + + return HTTPStatus.OK, {"user_id": user_id} |