-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Check for space membership during a remote join of a restricted room. #9763
Changes from 3 commits
902987c
861f40a
94bdb01
683d02d
bb6d71c
af7a679
b25de51
778391a
0b4f1a8
9df28be
c8e2d1f
9ffd521
9fe4b0a
4e3de96
d0644b8
acc63f6
0f3e373
6f162ed
808386d
f5f9421
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add experimental support for [MSC3083](https://github.com/matrix-org/matrix-doc/pull/3083): restricting room access via group membership. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1667,16 +1667,52 @@ async def on_send_join_request(self, origin: str, pdu: EventBase) -> JsonDict: | |
| # would introduce the danger of backwards-compatibility problems. | ||
| event.internal_metadata.send_on_behalf_of = origin | ||
|
|
||
| context = await self._handle_new_event(origin, event) | ||
| # Calculate the event context. | ||
| context = await self._prep_event( | ||
| origin, event, state=None, auth_events=None, backfilled=False | ||
| ) | ||
|
|
||
| # Get the current state at the to-be created event. | ||
clokep marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| prev_state_ids = await context.get_prev_state_ids() | ||
|
|
||
| # Check if the user is already in the room or invited to the room. | ||
| user_id = event.state_key | ||
| prev_member_event_id = prev_state_ids.get((EventTypes.Member, user_id), None) | ||
| newly_joined = True | ||
| is_invite = False | ||
| if prev_member_event_id: | ||
| prev_member_event = await self.store.get_event(prev_member_event_id) | ||
| newly_joined = prev_member_event.membership != Membership.JOIN | ||
| is_invite = prev_member_event.membership == Membership.INVITE | ||
|
Comment on lines
+1684
to
+1692
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much of this logic (and the if-statement below) is now duplicated between this and local joins in The local join logic has a couple of interleaved bits though (it needs
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it would be the end of the world to have this logic in both |
||
|
|
||
| # We retrieve the room member handler here as to not cause a cyclic dependency | ||
clokep marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| member_handler = self.hs.get_room_member_handler() | ||
|
|
||
| # If the member is not already in the room, and not invited, check if | ||
| # they should be allowed access via membership in a space. | ||
| if ( | ||
| newly_joined | ||
| and not is_invite | ||
| and not await member_handler.can_join_without_invite( | ||
| prev_state_ids, | ||
| event.room_version, | ||
| user_id, | ||
| ) | ||
| ): | ||
| raise SynapseError( | ||
| 400, | ||
| "You do not belong to any of the required spaces to join this room.", | ||
| ) | ||
|
|
||
| # Persist the event. | ||
| await self._handle_new_event(origin, event, context) | ||
|
|
||
| logger.debug( | ||
| "on_send_join_request: After _handle_new_event: %s, sigs: %s", | ||
| event.event_id, | ||
| event.signatures, | ||
| ) | ||
|
|
||
| prev_state_ids = await context.get_prev_state_ids() | ||
|
|
||
| state_ids = list(prev_state_ids.values()) | ||
| auth_chain = await self.store.get_auth_chain(event.room_id, state_ids) | ||
|
|
||
|
|
@@ -1994,13 +2030,36 @@ async def _handle_new_event( | |
| self, | ||
| origin: str, | ||
| event: EventBase, | ||
| context: Optional[EventContext] = None, | ||
| state: Optional[Iterable[EventBase]] = None, | ||
| auth_events: Optional[MutableStateMap[EventBase]] = None, | ||
| backfilled: bool = False, | ||
| ) -> EventContext: | ||
| context = await self._prep_event( | ||
| origin, event, state=state, auth_events=auth_events, backfilled=backfilled | ||
| ) | ||
| """ | ||
| Process an event. | ||
|
|
||
| Args: | ||
| origin: The host the event originates from. | ||
| event: The event itself. | ||
| context: The event context, if available. Otherwise this is calculated | ||
| from state and auth_events. | ||
| state: The state events to calculate the event context from. This is | ||
| ignored if context is provided. | ||
| auth_events: The auth events to calculate the event context from. This is | ||
| ignored if context is provided. | ||
| backfilled: True if the event was backfilled. | ||
|
|
||
| Returns: | ||
| The event context. | ||
| """ | ||
| if not context: | ||
clokep marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| context = await self._prep_event( | ||
| origin, | ||
| event, | ||
| state=state, | ||
| auth_events=auth_events, | ||
| backfilled=backfilled, | ||
| ) | ||
|
|
||
| try: | ||
| if ( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.