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

Commit 05e35ce

Browse files
committed
Raise an error if an authorising user cannot be found.
1 parent 8b2cac2 commit 05e35ce

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

synapse/handlers/event_auth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Membership,
2121
RestrictedJoinRuleTypes,
2222
)
23-
from synapse.api.errors import AuthError
23+
from synapse.api.errors import AuthError, SynapseError
2424
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion
2525
from synapse.events import EventBase
2626
from synapse.events.builder import EventBuilder
@@ -92,7 +92,7 @@ def compute_auth_events(
9292

9393
async def get_user_which_could_invite(
9494
self, room_id: str, current_state_ids: StateMap[str]
95-
) -> Optional[str]:
95+
) -> str:
9696
"""
9797
Searches the room state for a local user who has the power level necessary
9898
to invite other users.
@@ -132,8 +132,8 @@ async def get_user_which_could_invite(
132132
if chosen_user:
133133
return chosen_user
134134

135-
# TODO What to do if no user is found?
136-
return None
135+
# No user was found.
136+
raise SynapseError(400, "Unable to find a user which could issue an invite")
137137

138138
async def check_host_in_room(self, room_id: str, host: str) -> bool:
139139
with Measure(self._clock, "check_host_in_room"):

synapse/handlers/federation.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,18 +1715,12 @@ async def on_make_join_request(
17151715
)
17161716

17171717
if include_auth_user_id:
1718-
authorised_user_id = (
1719-
await self._event_auth_handler.get_user_which_could_invite(
1720-
room_id,
1721-
state_ids,
1722-
)
1718+
event_content[
1719+
"join_authorised_via_users_server"
1720+
] = await self._event_auth_handler.get_user_which_could_invite(
1721+
room_id,
1722+
state_ids,
17231723
)
1724-
if authorised_user_id:
1725-
event_content[
1726-
"join_authorised_via_users_server"
1727-
] = authorised_user_id
1728-
1729-
# TODO What if there's no authorised user?
17301724

17311725
builder = self.event_builder_factory.new(
17321726
room_version.identifier,

synapse/handlers/room_member.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,13 +916,12 @@ async def _should_perform_remote_join(
916916
# If this is going to be a local join, additional information must
917917
# be included in the event content in order to efficiently validate
918918
# the event.
919-
authorised_user_id = await self.event_auth_handler.get_user_which_could_invite(
919+
content[
920+
"join_authorised_via_users_server"
921+
] = await self.event_auth_handler.get_user_which_could_invite(
920922
room_id,
921923
current_state_ids,
922924
)
923-
if authorised_user_id:
924-
content["join_authorised_via_users_server"] = authorised_user_id
925-
# TODO If no authorised user is found then something bad happened.
926925

927926
return False, []
928927

0 commit comments

Comments
 (0)