From ae66c672fe8b5fbfe497888d03b2cbd68381de76 Mon Sep 17 00:00:00 2001 From: David Teller Date: Wed, 11 May 2022 10:32:27 +0200 Subject: Uniformize spam-checker API: - Some callbacks should return `True` to allow, `False` to deny, while others should return `True` to deny and `False` to allow. With this PR, all callbacks return `ALLOW` to allow or a `Codes` (typically `Codes.FORBIDDEN`) to deny. - Similarly, some methods returned `True` to allow, `False` to deny, while others returned `True` to deny and `False` to allow. They now all return `ALLOW` to allow or a `Codes` to deny. - Spam-checker implementations may now return an explicit code, e.g. to differentiate between "User account has been suspended" (which is in practice required by law in some countries, including UK) and "This message looks like spam". --- synapse/spam_checker_api/__init__.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'synapse/spam_checker_api') diff --git a/synapse/spam_checker_api/__init__.py b/synapse/spam_checker_api/__init__.py index 73018f2d00..074f4356f7 100644 --- a/synapse/spam_checker_api/__init__.py +++ b/synapse/spam_checker_api/__init__.py @@ -12,13 +12,31 @@ # See the License for the specific language governing permissions and # limitations under the License. from enum import Enum +from typing import NewType, Union + +from synapse.api.errors import Codes class RegistrationBehaviour(Enum): """ - Enum to define whether a registration request should allowed, denied, or shadow-banned. + Enum to define whether a registration request should be allowed, denied, or shadow-banned. """ ALLOW = "allow" SHADOW_BAN = "shadow_ban" DENY = "deny" + + +Allow = NewType("Allow", str) + +ALLOW = Allow("Allow") +""" +Return this constant to allow a message to pass. +""" + +Decision = Union[ALLOW, Codes] +""" +Union to define whether a request should be allowed or rejected. + +To reject a request without any specific information, use `Codes.FORBIDDEN`. +""" -- cgit 1.5.1