__init__.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright 2019 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from enum import Enum
  15. from typing import Union
  16. from synapse.api.errors import Codes
  17. class RegistrationBehaviour(Enum):
  18. """
  19. Enum to define whether a registration request should be allowed, denied, or shadow-banned.
  20. """
  21. ALLOW = "allow"
  22. SHADOW_BAN = "shadow_ban"
  23. DENY = "deny"
  24. # We define the following singleton enum rather than a string to be able to
  25. # write `Union[Allow, ..., str]` in some of the callbacks for the spam-checker
  26. # API, where the `str` is required to maintain backwards compatibility with
  27. # previous versions of the API.
  28. class Allow(Enum):
  29. """
  30. Singleton to allow events to pass through in SpamChecker APIs.
  31. """
  32. ALLOW = "allow"
  33. Decision = Union[Allow, Codes]
  34. """
  35. Union to define whether a request should be allowed or rejected.
  36. To accept a request, return `ALLOW`.
  37. To reject a request without any specific information, use `Codes.FORBIDDEN`.
  38. """