diff options
author | David Teller <D.O.Teller@gmail.com> | 2022-05-23 19:27:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-23 17:27:39 +0000 |
commit | 28199e93579b5a73841a95ed4d355322227432b5 (patch) | |
tree | c720d7ca13a54d6d7fd0405dd8bbad7921cd856d /synapse/spam_checker_api | |
parent | Prevent expired events from being filtered out when retention is disabled (#1... (diff) | |
download | synapse-28199e93579b5a73841a95ed4d355322227432b5.tar.xz |
Uniformize spam-checker API, part 2: check_event_for_spam (#12808)
Signed-off-by: David Teller <davidt@element.io>
Diffstat (limited to 'synapse/spam_checker_api')
-rw-r--r-- | synapse/spam_checker_api/__init__.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/synapse/spam_checker_api/__init__.py b/synapse/spam_checker_api/__init__.py index 73018f2d00..95132c80b7 100644 --- a/synapse/spam_checker_api/__init__.py +++ b/synapse/spam_checker_api/__init__.py @@ -12,13 +12,38 @@ # See the License for the specific language governing permissions and # limitations under the License. from enum import Enum +from typing import 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" + + +# We define the following singleton enum rather than a string to be able to +# write `Union[Allow, ..., str]` in some of the callbacks for the spam-checker +# API, where the `str` is required to maintain backwards compatibility with +# previous versions of the API. +class Allow(Enum): + """ + Singleton to allow events to pass through in SpamChecker APIs. + """ + + ALLOW = "allow" + + +Decision = Union[Allow, Codes] +""" +Union to define whether a request should be allowed or rejected. + +To accept a request, return `ALLOW`. + +To reject a request without any specific information, use `Codes.FORBIDDEN`. +""" |