diff options
author | Travis Ralston <travpc@gmail.com> | 2021-01-19 13:59:29 -0700 |
---|---|---|
committer | Travis Ralston <travpc@gmail.com> | 2021-01-19 13:59:29 -0700 |
commit | 40f96320a2eb0049cb5defaf52530b8e08095a14 (patch) | |
tree | a5192ffbc0f48de65b16313409ca5d197c3e79ac /synapse/rest/admin/rooms.py | |
parent | Validate the server name for the /publicRooms endpoint. (#9161) (diff) | |
download | synapse-40f96320a2eb0049cb5defaf52530b8e08095a14.tar.xz |
Add an admin API to get the current room state
This could arguably replace the existing admin API for `/members`, however that is out of scope of this change. This sort of endpoint is ideal for moderation use cases as well as other applications, such as needing to retrieve various bits of information about a room to perform a task (like syncing power levels between two places). This endpoint exposes nothing more than an admin would be able to access with a `select *` query on their database.
Diffstat (limited to 'synapse/rest/admin/rooms.py')
-rw-r--r-- | synapse/rest/admin/rooms.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/synapse/rest/admin/rooms.py b/synapse/rest/admin/rooms.py index ab7cc9102a..4c0331b197 100644 --- a/synapse/rest/admin/rooms.py +++ b/synapse/rest/admin/rooms.py @@ -292,6 +292,38 @@ class RoomMembersRestServlet(RestServlet): return 200, ret +class RoomStateRestServlet(RestServlet): + """ + Get full state within a room. + """ + + PATTERNS = admin_patterns("/rooms/(?P<room_id>[^/]+)/state") + + def __init__(self, hs: "HomeServer"): + self.hs = hs + self.auth = hs.get_auth() + self.store = hs.get_datastore() + self.message_handler = hs.get_message_handler() + + async def on_GET( + self, request: SynapseRequest, room_id: str + ) -> Tuple[int, JsonDict]: + await assert_requester_is_admin(self.auth, request) + + ret = await self.store.get_room(room_id) + if not ret: + raise NotFoundError("Room not found") + + room_state = await self.message_handler.get_state_events( + user_id=request.requester.user.to_string(), + room_id=room_id, + is_admin=True, # already verified above + ) + ret = {"state": room_state} + + return 200, ret + + class JoinRoomAliasServlet(RestServlet): PATTERNS = admin_patterns("/join/(?P<room_identifier>[^/]*)") |