From 4fea56eb4e1b3c113bebe6e023b02341a6403dd5 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Wed, 10 Mar 2021 12:00:52 +0200 Subject: [PATCH 1/4] Fix spam checker modules documentation example A parse_config method is mandatory on spam checked modules. This relates to #8944 as well. Signed-off-by: Jason Robinson --- changelog.d/9580.doc | 1 + docs/spam_checker.md | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 changelog.d/9580.doc diff --git a/changelog.d/9580.doc b/changelog.d/9580.doc new file mode 100644 index 000000000000..7db0f074c02b --- /dev/null +++ b/changelog.d/9580.doc @@ -0,0 +1 @@ +Fix spam checker modules documentation example to clarify parse_config is a required method. diff --git a/docs/spam_checker.md b/docs/spam_checker.md index e615ac99103f..42498a4e257a 100644 --- a/docs/spam_checker.md +++ b/docs/spam_checker.md @@ -14,6 +14,7 @@ The Python class is instantiated with two objects: * An instance of `synapse.module_api.ModuleApi`. It then implements methods which return a boolean to alter behavior in Synapse. +All the methods are mandatory to be defined. There's a generic method for checking every event (`check_event_for_spam`), as well as some specific methods: @@ -31,6 +32,10 @@ are documented in the `synapse.events.spamcheck.SpamChecker` class. The `ModuleApi` class provides a way for the custom spam checker class to call back into the homeserver internals. +Additionally, a `parse_config` method is mandatory and receives the plugin config +dictionary. After possible sanitizing, It must return a dictionary which +will be passed to `__init__` later. + ### Example ```python @@ -41,6 +46,10 @@ class ExampleSpamChecker: self.config = config self.api = api + @staticmethod + def parse_config(config): + return config + async def check_event_for_spam(self, foo): return False # allow all events From 233a8cf44b553e7884ebf4a0a35c337e90998dc2 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Wed, 10 Mar 2021 16:08:29 +0200 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Patrick Cloke --- changelog.d/9580.doc | 2 +- docs/spam_checker.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog.d/9580.doc b/changelog.d/9580.doc index 7db0f074c02b..f9c8b328b32d 100644 --- a/changelog.d/9580.doc +++ b/changelog.d/9580.doc @@ -1 +1 @@ -Fix spam checker modules documentation example to clarify parse_config is a required method. +Clarify the spam checker modules documentation example to mention that `parse_config` is a required method. diff --git a/docs/spam_checker.md b/docs/spam_checker.md index 42498a4e257a..40f450ab9e28 100644 --- a/docs/spam_checker.md +++ b/docs/spam_checker.md @@ -14,7 +14,7 @@ The Python class is instantiated with two objects: * An instance of `synapse.module_api.ModuleApi`. It then implements methods which return a boolean to alter behavior in Synapse. -All the methods are mandatory to be defined. +All the methods are must be defined. There's a generic method for checking every event (`check_event_for_spam`), as well as some specific methods: @@ -33,8 +33,8 @@ The `ModuleApi` class provides a way for the custom spam checker class to call back into the homeserver internals. Additionally, a `parse_config` method is mandatory and receives the plugin config -dictionary. After possible sanitizing, It must return a dictionary which -will be passed to `__init__` later. +dictionary. After parsing, It must return an object which will be +passed to `__init__` later. ### Example From 03c81e972f89f1eebdc27c203c69dfec95d3f8e3 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Wed, 10 Mar 2021 16:10:18 +0200 Subject: [PATCH 3/4] Fix typo Signed-off-by: Jason Robinson --- docs/spam_checker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/spam_checker.md b/docs/spam_checker.md index 40f450ab9e28..31e1005a3802 100644 --- a/docs/spam_checker.md +++ b/docs/spam_checker.md @@ -14,7 +14,7 @@ The Python class is instantiated with two objects: * An instance of `synapse.module_api.ModuleApi`. It then implements methods which return a boolean to alter behavior in Synapse. -All the methods are must be defined. +All the methods must be defined. There's a generic method for checking every event (`check_event_for_spam`), as well as some specific methods: From a849b30ce04f819fbd584e6b6448c5e76513a55d Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Wed, 10 Mar 2021 16:11:49 +0200 Subject: [PATCH 4/4] Add check_media_file_for_spam to list of methods in spam_checker.md Signed-off-by: Jason Robinson --- docs/spam_checker.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/spam_checker.md b/docs/spam_checker.md index 31e1005a3802..2020eb900615 100644 --- a/docs/spam_checker.md +++ b/docs/spam_checker.md @@ -25,6 +25,7 @@ well as some specific methods: * `user_may_publish_room` * `check_username_for_spam` * `check_registration_for_spam` +* `check_media_file_for_spam` The details of each of these methods (as well as their inputs and outputs) are documented in the `synapse.events.spamcheck.SpamChecker` class.