forked from MirrorHub/synapse
Move shadow-ban check down into handle_new_client_event
.
This commit is contained in:
parent
b520a1bf5a
commit
2ee302d016
1 changed files with 24 additions and 8 deletions
|
@ -657,25 +657,23 @@ class EventCreationHandler:
|
||||||
Return:
|
Return:
|
||||||
The stream_id of the persisted event.
|
The stream_id of the persisted event.
|
||||||
|
|
||||||
Raises:
|
|
||||||
ShadowBanError if the requester has been shadow-banned.
|
|
||||||
"""
|
"""
|
||||||
if event.type == EventTypes.Member:
|
if event.type == EventTypes.Member:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
500, "Tried to send member event through non-member codepath"
|
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)
|
user = UserID.from_string(event.sender)
|
||||||
|
|
||||||
assert self.hs.is_mine(user), "User must be our own: %s" % (user,)
|
assert self.hs.is_mine(user), "User must be our own: %s" % (user,)
|
||||||
|
|
||||||
ev = await self.handle_new_client_event(
|
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
|
# we know it was persisted, so must have a stream ordering
|
||||||
|
@ -837,6 +835,7 @@ class EventCreationHandler:
|
||||||
context: EventContext,
|
context: EventContext,
|
||||||
ratelimit: bool = True,
|
ratelimit: bool = True,
|
||||||
extra_users: List[UserID] = [],
|
extra_users: List[UserID] = [],
|
||||||
|
ignore_shadow_ban: bool = False,
|
||||||
) -> EventBase:
|
) -> EventBase:
|
||||||
"""Processes a new event.
|
"""Processes a new event.
|
||||||
|
|
||||||
|
@ -853,11 +852,28 @@ class EventCreationHandler:
|
||||||
ratelimit
|
ratelimit
|
||||||
extra_users: Any extra users to notify about event
|
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:
|
Return:
|
||||||
If the event was deduplicated, the previous, duplicate, event. Otherwise,
|
If the event was deduplicated, the previous, duplicate, event. Otherwise,
|
||||||
`event`.
|
`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():
|
if event.is_state():
|
||||||
prev_event = await self.deduplicate_state_event(event, context)
|
prev_event = await self.deduplicate_state_event(event, context)
|
||||||
if prev_event is not None:
|
if prev_event is not None:
|
||||||
|
|
Loading…
Reference in a new issue