|
19 | 19 | from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple |
20 | 20 |
|
21 | 21 | from synapse import types |
22 | | -from synapse.api.constants import AccountDataTypes, EventTypes, JoinRules, Membership |
| 22 | +from synapse.api.constants import AccountDataTypes, EventTypes, Membership |
23 | 23 | from synapse.api.errors import ( |
24 | 24 | AuthError, |
25 | 25 | Codes, |
|
28 | 28 | SynapseError, |
29 | 29 | ) |
30 | 30 | from synapse.api.ratelimiting import Ratelimiter |
31 | | -from synapse.api.room_versions import RoomVersion |
32 | 31 | from synapse.events import EventBase |
33 | 32 | from synapse.events.snapshot import EventContext |
34 | 33 | from synapse.types import JsonDict, Requester, RoomAlias, RoomID, StateMap, UserID |
@@ -64,6 +63,7 @@ def __init__(self, hs: "HomeServer"): |
64 | 63 | self.profile_handler = hs.get_profile_handler() |
65 | 64 | self.event_creation_handler = hs.get_event_creation_handler() |
66 | 65 | self.account_data_handler = hs.get_account_data_handler() |
| 66 | + self.event_auth_handler = hs.get_event_auth_handler() |
67 | 67 |
|
68 | 68 | self.member_linearizer = Linearizer(name="member") |
69 | 69 |
|
@@ -178,62 +178,6 @@ async def ratelimit_invite( |
178 | 178 |
|
179 | 179 | await self._invites_per_user_limiter.ratelimit(requester, invitee_user_id) |
180 | 180 |
|
181 | | - async def _can_join_without_invite( |
182 | | - self, state_ids: StateMap[str], room_version: RoomVersion, user_id: str |
183 | | - ) -> bool: |
184 | | - """ |
185 | | - Check whether a user can join a room without an invite. |
186 | | -
|
187 | | - When joining a room with restricted joined rules (as defined in MSC3083), |
188 | | - the membership of spaces must be checked during join. |
189 | | -
|
190 | | - Args: |
191 | | - state_ids: The state of the room as it currently is. |
192 | | - room_version: The room version of the room being joined. |
193 | | - user_id: The user joining the room. |
194 | | -
|
195 | | - Returns: |
196 | | - True if the user can join the room, false otherwise. |
197 | | - """ |
198 | | - # This only applies to room versions which support the new join rule. |
199 | | - if not room_version.msc3083_join_rules: |
200 | | - return True |
201 | | - |
202 | | - # If there's no join rule, then it defaults to public (so this doesn't apply). |
203 | | - join_rules_event_id = state_ids.get((EventTypes.JoinRules, ""), None) |
204 | | - if not join_rules_event_id: |
205 | | - return True |
206 | | - |
207 | | - # If the join rule is not restricted, this doesn't apply. |
208 | | - join_rules_event = await self.store.get_event(join_rules_event_id) |
209 | | - if join_rules_event.content.get("join_rule") != JoinRules.MSC3083_RESTRICTED: |
210 | | - return True |
211 | | - |
212 | | - # If allowed is of the wrong form, then only allow invited users. |
213 | | - allowed_spaces = join_rules_event.content.get("allow", []) |
214 | | - if not isinstance(allowed_spaces, list): |
215 | | - return False |
216 | | - |
217 | | - # Get the list of joined rooms and see if there's an overlap. |
218 | | - joined_rooms = await self.store.get_rooms_for_user(user_id) |
219 | | - |
220 | | - # Pull out the other room IDs, invalid data gets filtered. |
221 | | - for space in allowed_spaces: |
222 | | - if not isinstance(space, dict): |
223 | | - continue |
224 | | - |
225 | | - space_id = space.get("space") |
226 | | - if not isinstance(space_id, str): |
227 | | - continue |
228 | | - |
229 | | - # The user was joined to one of the spaces specified, they can join |
230 | | - # this room! |
231 | | - if space_id in joined_rooms: |
232 | | - return True |
233 | | - |
234 | | - # The user was not in any of the required spaces. |
235 | | - return False |
236 | | - |
237 | 181 | async def _local_membership_update( |
238 | 182 | self, |
239 | 183 | requester: Requester, |
@@ -302,7 +246,7 @@ async def _local_membership_update( |
302 | 246 | if ( |
303 | 247 | newly_joined |
304 | 248 | and not user_is_invited |
305 | | - and not await self._can_join_without_invite( |
| 249 | + and not await self.event_auth_handler.can_join_without_invite( |
306 | 250 | prev_state_ids, event.room_version, user_id |
307 | 251 | ) |
308 | 252 | ): |
|
0 commit comments