diff options
author | Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> | 2020-09-18 16:26:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-18 15:26:36 +0100 |
commit | d688b4bafca58dfff1be35615d6ff1e202d47cc6 (patch) | |
tree | 0fc4045148dc3876cf748c00541b1086ae5773fe /synapse/rest/admin/users.py | |
parent | Catch-up after Federation Outage (bonus): Catch-up on Synapse Startup (#8322) (diff) | |
download | synapse-d688b4bafca58dfff1be35615d6ff1e202d47cc6.tar.xz |
Admin API for querying rooms where a user is a member (#8306)
Add a new admin API `GET /_synapse/admin/v1/users/<user_id>/joined_rooms` to list all rooms where a user is a member.
Diffstat (limited to 'synapse/rest/admin/users.py')
-rw-r--r-- | synapse/rest/admin/users.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/synapse/rest/admin/users.py b/synapse/rest/admin/users.py index 0f537031c4..20dc1d0e05 100644 --- a/synapse/rest/admin/users.py +++ b/synapse/rest/admin/users.py @@ -683,3 +683,29 @@ class UserAdminServlet(RestServlet): await self.store.set_server_admin(target_user, set_admin_to) return 200, {} + + +class UserMembershipRestServlet(RestServlet): + """ + Get room list of an user. + """ + + PATTERNS = admin_patterns("/users/(?P<user_id>[^/]+)/joined_rooms$") + + def __init__(self, hs): + self.is_mine = hs.is_mine + self.auth = hs.get_auth() + self.store = hs.get_datastore() + + async def on_GET(self, request, user_id): + await assert_requester_is_admin(self.auth, request) + + if not self.is_mine(UserID.from_string(user_id)): + raise SynapseError(400, "Can only lookup local users") + + room_ids = await self.store.get_rooms_for_user(user_id) + if not room_ids: + raise NotFoundError("User not found") + + ret = {"joined_rooms": list(room_ids), "total": len(room_ids)} + return 200, ret |