Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit e0d6244

Browse files
Remove unused parameter from, and add safeguard in, get_room_data (#8174)
Small cleanup PR. * Removed the unused `is_guest` argument * Added a safeguard to a (currently) impossible code path, fixing static checking at the same time.
1 parent ed18f32 commit e0d6244

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

changelog.d/8174.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove unused `is_guest` parameter from, and add safeguard to, `MessageHandler.get_room_data`.

synapse/handlers/message.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,7 @@ def __init__(self, hs):
9595
)
9696

9797
async def get_room_data(
98-
self,
99-
user_id: str,
100-
room_id: str,
101-
event_type: str,
102-
state_key: str,
103-
is_guest: bool,
98+
self, user_id: str, room_id: str, event_type: str, state_key: str,
10499
) -> dict:
105100
""" Get data from a room.
106101
@@ -109,11 +104,10 @@ async def get_room_data(
109104
room_id
110105
event_type
111106
state_key
112-
is_guest
113107
Returns:
114108
The path data content.
115109
Raises:
116-
SynapseError if something went wrong.
110+
SynapseError or AuthError if the user is not in the room
117111
"""
118112
(
119113
membership,
@@ -130,6 +124,16 @@ async def get_room_data(
130124
[membership_event_id], StateFilter.from_types([key])
131125
)
132126
data = room_state[membership_event_id].get(key)
127+
else:
128+
# check_user_in_room_or_world_readable, if it doesn't raise an AuthError, should
129+
# only ever return a Membership.JOIN/LEAVE object
130+
#
131+
# Safeguard in case it returned something else
132+
logger.error(
133+
"Attempted to retrieve data from a room for a user that has never been in it. "
134+
"This should not have happened."
135+
)
136+
raise SynapseError(403, "User not in room", errcode=Codes.FORBIDDEN)
133137

134138
return data
135139

synapse/rest/client/v1/room.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ async def on_GET(self, request, room_id, event_type, state_key):
171171
room_id=room_id,
172172
event_type=event_type,
173173
state_key=state_key,
174-
is_guest=requester.is_guest,
175174
)
176175

177176
if not data:

tests/rest/client/test_retention.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def _test_retention_event_purged(self, room_id: str, increment: float):
178178
message_handler = self.hs.get_message_handler()
179179
create_event = self.get_success(
180180
message_handler.get_room_data(
181-
self.user_id, room_id, EventTypes.Create, state_key="", is_guest=False
181+
self.user_id, room_id, EventTypes.Create, state_key=""
182182
)
183183
)
184184

0 commit comments

Comments
 (0)