diff options
author | Richard van der Hoff <richard@matrix.org> | 2020-10-13 18:53:56 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2020-10-13 23:24:50 +0100 |
commit | 617e8a46538af56bd5abbb2c9e4df8025841c338 (patch) | |
tree | 80335f25c52b7b240d33fc32570d59d6c1ab1ff7 /synapse/events/third_party_rules.py | |
parent | Move third_party_rules check to event creation time (diff) | |
download | synapse-617e8a46538af56bd5abbb2c9e4df8025841c338.tar.xz |
Allow ThirdPartyRules modules to replace event content
Support returning a new event dict from `check_event_allowed`.
Diffstat (limited to 'synapse/events/third_party_rules.py')
-rw-r--r-- | synapse/events/third_party_rules.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/synapse/events/third_party_rules.py b/synapse/events/third_party_rules.py index 1535cc5339..a9aabe00df 100644 --- a/synapse/events/third_party_rules.py +++ b/synapse/events/third_party_rules.py @@ -12,7 +12,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from typing import Callable + +from typing import Callable, Union from synapse.events import EventBase from synapse.events.snapshot import EventContext @@ -44,15 +45,20 @@ class ThirdPartyEventRules: async def check_event_allowed( self, event: EventBase, context: EventContext - ) -> bool: + ) -> Union[bool, dict]: """Check if a provided event should be allowed in the given context. + The module can return: + * True: the event is allowed. + * False: the event is not allowed, and should be rejected with M_FORBIDDEN. + * a dict: replacement event data. + Args: event: The event to be checked. context: The context of the event. Returns: - True if the event should be allowed, False if not. + The result from the ThirdPartyRules module, as above """ if self.third_party_rules is None: return True |