From 40f96320a2eb0049cb5defaf52530b8e08095a14 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 19 Jan 2021 13:59:29 -0700 Subject: 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. --- synapse/handlers/message.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'synapse/handlers/message.py') diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 9dfeab09cd..457491b75d 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -137,6 +137,7 @@ class MessageHandler: state_filter: StateFilter = StateFilter.all(), at_token: Optional[StreamToken] = None, is_guest: bool = False, + is_admin: bool = False, ) -> List[dict]: """Retrieve all state events for a given room. If the user is joined to the room then return the current state. If the user has @@ -153,6 +154,7 @@ class MessageHandler: stream token, we raise a 403 SynapseError. If None, returns the current state based on the current_state_events table. is_guest: whether this user is a guest + is_admin: whether this user is making the request as a server admin. Returns: A list of dicts representing state events. [{}, {}, {}] Raises: @@ -173,9 +175,12 @@ class MessageHandler: if not last_events: raise NotFoundError("Can't find event for token %s" % (at_token,)) - visible_events = await filter_events_for_client( - self.storage, user_id, last_events, filter_send_to_client=False - ) + if is_admin: + visible_events = last_events + else: + visible_events = await filter_events_for_client( + self.storage, user_id, last_events, filter_send_to_client=False, + ) event = last_events[0] if visible_events: @@ -197,7 +202,7 @@ class MessageHandler: room_id, user_id, allow_departed_users=True ) - if membership == Membership.JOIN: + if membership == Membership.JOIN or is_admin: state_ids = await self.store.get_filtered_current_state_ids( room_id, state_filter=state_filter ) -- cgit 1.5.1