summary refs log tree commit diff
path: root/synapse/spam_checker_api
diff options
context:
space:
mode:
authorDavid Teller <d.o.teller+github@gmail.com>2022-05-11 10:32:27 +0200
committerDavid Teller <d.o.teller+github@gmail.com>2022-05-11 10:32:30 +0200
commitae66c672fe8b5fbfe497888d03b2cbd68381de76 (patch)
tree4c837eb8b98c8b6bd1a0fa910100df30dea7161f /synapse/spam_checker_api
parentFix `/messages` throwing a 500 when querying for non-existent room (#12683) (diff)
downloadsynapse-ts/spam-errors.tar.xz
Uniformize spam-checker API: github/ts/spam-errors ts/spam-errors
- 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".
Diffstat (limited to 'synapse/spam_checker_api')
-rw-r--r--synapse/spam_checker_api/__init__.py20
1 files changed, 19 insertions, 1 deletions
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`. +"""