summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2020-10-02 18:03:21 +0100
committerRichard van der Hoff <richard@matrix.org>2020-10-05 18:55:06 +0100
commit2ee302d0164b3e0495c3cd1ebb6b906fd3e04e27 (patch)
tree05006d956affcd0fe9f896ffcf5f535c4dbc9e1d
parentDe-duplicate duplicate handling (diff)
downloadsynapse-2ee302d0164b3e0495c3cd1ebb6b906fd3e04e27.tar.xz
Move shadow-ban check down into `handle_new_client_event`.
-rw-r--r--synapse/handlers/message.py32
1 files changed, 24 insertions, 8 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index ea8e3517d7..8852db4eaf 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -657,25 +657,23 @@ class EventCreationHandler:
         Return:
             The stream_id of the persisted event.
 
-        Raises:
-            ShadowBanError if the requester has been shadow-banned.
+
         """
         if event.type == EventTypes.Member:
             raise SynapseError(
                 500, "Tried to send member event through non-member codepath"
             )
 
-        if not ignore_shadow_ban and requester.shadow_banned:
-            # We randomly sleep a bit just to annoy the requester.
-            await self.clock.sleep(random.randint(1, 10))
-            raise ShadowBanError()
-
         user = UserID.from_string(event.sender)
 
         assert self.hs.is_mine(user), "User must be our own: %s" % (user,)
 
         ev = await self.handle_new_client_event(
-            requester=requester, event=event, context=context, ratelimit=ratelimit
+            requester=requester,
+            event=event,
+            context=context,
+            ratelimit=ratelimit,
+            ignore_shadow_ban=ignore_shadow_ban,
         )
 
         # we know it was persisted, so must have a stream ordering
@@ -837,6 +835,7 @@ class EventCreationHandler:
         context: EventContext,
         ratelimit: bool = True,
         extra_users: List[UserID] = [],
+        ignore_shadow_ban: bool = False,
     ) -> EventBase:
         """Processes a new event.
 
@@ -853,11 +852,28 @@ class EventCreationHandler:
             ratelimit
             extra_users: Any extra users to notify about event
 
+            ignore_shadow_ban: True if shadow-banned users should be allowed to
+                send this event.
+
         Return:
             If the event was deduplicated, the previous, duplicate, event. Otherwise,
             `event`.
+
+        Raises:
+            ShadowBanError if the requester has been shadow-banned.
         """
 
+        # we don't apply shadow-banning to membership events, so that the user
+        # can come and go as they want.
+        if (
+            event.type != EventTypes.Member
+            and not ignore_shadow_ban
+            and requester.shadow_banned
+        ):
+            # We randomly sleep a bit just to annoy the requester.
+            await self.clock.sleep(random.randint(1, 10))
+            raise ShadowBanError()
+
         if event.is_state():
             prev_event = await self.deduplicate_state_event(event, context)
             if prev_event is not None: