Exemplo n.º 1
0
    async def _locally_reject_invite(
        self,
        invite_event: EventBase,
        txn_id: Optional[str],
        requester: Requester,
        content: JsonDict,
    ) -> Tuple[str, int]:
        """Generate a local invite rejection

        This is called after we fail to reject an invite via a remote server. It
        generates an out-of-band membership event locally.

        Args:
            invite_event: the invite to be rejected
            txn_id: optional transaction ID supplied by the client
            requester:  user making the rejection request, according to the access token
            content: additional content to include in the rejection event.
               Normally an empty dict.
        """

        room_id = invite_event.room_id
        target_user = invite_event.state_key

        content["membership"] = Membership.LEAVE

        event_dict = {
            "type": EventTypes.Member,
            "room_id": room_id,
            "sender": target_user,
            "content": content,
            "state_key": target_user,
        }

        # the auth events for the new event are the same as that of the invite, plus
        # the invite itself.
        #
        # the prev_events are just the invite.
        prev_event_ids = [invite_event.event_id]
        auth_event_ids = invite_event.auth_event_ids() + prev_event_ids

        event, context = await self.event_creation_handler.create_event(
            requester,
            event_dict,
            txn_id=txn_id,
            prev_event_ids=prev_event_ids,
            auth_event_ids=auth_event_ids,
        )
        event.internal_metadata.outlier = True
        event.internal_metadata.out_of_band_membership = True

        result_event = await self.event_creation_handler.handle_new_client_event(
            requester, event, context, extra_users=[UserID.from_string(target_user)],
        )
        # we know it was persisted, so must have a stream ordering
        assert result_event.internal_metadata.stream_ordering

        return result_event.event_id, result_event.internal_metadata.stream_ordering
Exemplo n.º 2
0
 async def check_auth_rules_from_context(
     self,
     room_version_obj: RoomVersion,
     event: EventBase,
     context: EventContext,
 ) -> None:
     """Check an event passes the auth rules at its own auth events"""
     auth_event_ids = event.auth_event_ids()
     auth_events_by_id = await self._store.get_events(auth_event_ids)
     check_auth_rules_for_event(room_version_obj, event, auth_events_by_id.values())
Exemplo n.º 3
0
 async def check_auth_rules_from_context(
     self,
     event: EventBase,
     context: EventContext,
 ) -> None:
     """Check an event passes the auth rules at its own auth events"""
     await check_state_independent_auth_rules(self._store, event)
     auth_event_ids = event.auth_event_ids()
     auth_events_by_id = await self._store.get_events(auth_event_ids)
     check_state_dependent_auth_rules(event, auth_events_by_id.values())