-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Support modifying event content from ThirdPartyRules modules #8535
Changes from 2 commits
d59378d
123711e
617e8a4
898196f
091e948
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 |
|---|---|---|
|
|
@@ -1507,18 +1507,9 @@ async def on_make_join_request( | |
| event, context = await self.event_creation_handler.create_new_client_event( | ||
| builder=builder | ||
| ) | ||
| except AuthError as e: | ||
| except SynapseError as e: | ||
| logger.warning("Failed to create join to %s because %s", room_id, e) | ||
| raise e | ||
|
|
||
| event_allowed = await self.third_party_event_rules.check_event_allowed( | ||
| event, context | ||
| ) | ||
| if not event_allowed: | ||
| logger.info("Creation of join %s forbidden by third-party rules", event) | ||
| raise SynapseError( | ||
| 403, "This event is not allowed in this context", Codes.FORBIDDEN | ||
| ) | ||
| raise | ||
|
|
||
| # The remote hasn't signed it yet, obviously. We'll do the full checks | ||
| # when we get the event back in `on_send_join_request` | ||
|
|
@@ -1567,15 +1558,6 @@ async def on_send_join_request(self, origin, pdu): | |
|
|
||
| context = await self._handle_new_event(origin, event) | ||
|
|
||
| event_allowed = await self.third_party_event_rules.check_event_allowed( | ||
| event, context | ||
| ) | ||
| if not event_allowed: | ||
| logger.info("Sending of join %s forbidden by third-party rules", event) | ||
| raise SynapseError( | ||
| 403, "This event is not allowed in this context", Codes.FORBIDDEN | ||
| ) | ||
|
|
||
| logger.debug( | ||
| "on_send_join_request: After _handle_new_event: %s, sigs: %s", | ||
| event.event_id, | ||
|
|
@@ -1748,15 +1730,6 @@ async def on_make_leave_request( | |
| builder=builder | ||
| ) | ||
|
|
||
| event_allowed = await self.third_party_event_rules.check_event_allowed( | ||
| event, context | ||
| ) | ||
| if not event_allowed: | ||
| logger.warning("Creation of leave %s forbidden by third-party rules", event) | ||
| raise SynapseError( | ||
| 403, "This event is not allowed in this context", Codes.FORBIDDEN | ||
| ) | ||
|
|
||
| try: | ||
| # The remote hasn't signed it yet, obviously. We'll do the full checks | ||
| # when we get the event back in `on_send_leave_request` | ||
|
|
@@ -1789,16 +1762,7 @@ async def on_send_leave_request(self, origin, pdu): | |
|
|
||
| event.internal_metadata.outlier = False | ||
|
|
||
| context = await self._handle_new_event(origin, event) | ||
|
|
||
| event_allowed = await self.third_party_event_rules.check_event_allowed( | ||
| event, context | ||
| ) | ||
| if not event_allowed: | ||
| logger.info("Sending of leave %s forbidden by third-party rules", event) | ||
| raise SynapseError( | ||
| 403, "This event is not allowed in this context", Codes.FORBIDDEN | ||
| ) | ||
| await self._handle_new_event(origin, event) | ||
|
|
||
| logger.debug( | ||
| "on_send_leave_request: After _handle_new_event: %s, sigs: %s", | ||
|
|
@@ -2694,18 +2658,6 @@ async def exchange_third_party_invite( | |
| builder=builder | ||
| ) | ||
|
|
||
| event_allowed = await self.third_party_event_rules.check_event_allowed( | ||
| event, context | ||
| ) | ||
| if not event_allowed: | ||
| logger.info( | ||
| "Creation of threepid invite %s forbidden by third-party rules", | ||
| event, | ||
| ) | ||
| raise SynapseError( | ||
| 403, "This event is not allowed in this context", Codes.FORBIDDEN | ||
| ) | ||
|
|
||
|
Comment on lines
-2697
to
-2708
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. afaict, this was redundant, because we later call |
||
| event, context = await self.add_display_name_to_third_party_invite( | ||
| room_version, event_dict, event, context | ||
| ) | ||
|
|
@@ -2756,18 +2708,6 @@ async def on_exchange_third_party_invite_request( | |
| event, context = await self.event_creation_handler.create_new_client_event( | ||
| builder=builder | ||
| ) | ||
|
|
||
| event_allowed = await self.third_party_event_rules.check_event_allowed( | ||
| event, context | ||
| ) | ||
| if not event_allowed: | ||
| logger.warning( | ||
| "Exchange of threepid invite %s forbidden by third-party rules", event | ||
| ) | ||
| raise SynapseError( | ||
| 403, "This event is not allowed in this context", Codes.FORBIDDEN | ||
| ) | ||
|
|
||
|
Comment on lines
-2759
to
-2770
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. (ditto) |
||
| event, context = await self.add_display_name_to_third_party_invite( | ||
| room_version, event_dict, event, context | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -795,6 +795,17 @@ async def create_new_client_event( | |
| if requester: | ||
| context.app_service = requester.app_service | ||
|
|
||
| event_allowed = await self.third_party_event_rules.check_event_allowed( | ||
| event, context | ||
| ) | ||
| if not event_allowed: | ||
| logger.info( | ||
| "Event %s forbidden by third-party rules", event, | ||
| ) | ||
| raise SynapseError( | ||
| 403, "This event is not allowed in this context", Codes.FORBIDDEN | ||
| ) | ||
|
|
||
| self.validator.validate_new(event, self.config) | ||
|
|
||
| # If this event is an annotation then we check that that the sender | ||
|
|
@@ -881,14 +892,6 @@ async def handle_new_client_event( | |
| else: | ||
| room_version = await self.store.get_room_version_id(event.room_id) | ||
|
|
||
| event_allowed = await self.third_party_event_rules.check_event_allowed( | ||
|
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. this call path is somewhat less obvious than the others, since there are 6 callers of
All the above create the event by calling
This one is brought in line by #8537. |
||
| event, context | ||
| ) | ||
| if not event_allowed: | ||
| raise SynapseError( | ||
| 403, "This event is not allowed in this context", Codes.FORBIDDEN | ||
| ) | ||
|
|
||
| if event.internal_metadata.is_out_of_band_membership(): | ||
| # the only sort of out-of-band-membership events we expect to see here | ||
| # are invite rejections we have generated ourselves. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm changing this because
create_new_client_eventwill now raise a SynapseError if the third_party_rules check blocks the event.