You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 rivejä
3.1 KiB

  1. # Copyright 2020 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. import logging
  15. from typing import Any
  16. from synapse.api.constants import RoomCreationPreset
  17. from synapse.types import JsonDict
  18. from ._base import Config, ConfigError
  19. logger = logging.Logger(__name__)
  20. class RoomDefaultEncryptionTypes:
  21. """Possible values for the encryption_enabled_by_default_for_room_type config option"""
  22. ALL = "all"
  23. INVITE = "invite"
  24. OFF = "off"
  25. class RoomConfig(Config):
  26. section = "room"
  27. def read_config(self, config: JsonDict, **kwargs: Any) -> None:
  28. # Whether new, locally-created rooms should have encryption enabled
  29. encryption_for_room_type = config.get(
  30. "encryption_enabled_by_default_for_room_type",
  31. RoomDefaultEncryptionTypes.OFF,
  32. )
  33. if encryption_for_room_type == RoomDefaultEncryptionTypes.ALL:
  34. self.encryption_enabled_by_default_for_room_presets = [
  35. RoomCreationPreset.PRIVATE_CHAT,
  36. RoomCreationPreset.TRUSTED_PRIVATE_CHAT,
  37. RoomCreationPreset.PUBLIC_CHAT,
  38. ]
  39. elif encryption_for_room_type == RoomDefaultEncryptionTypes.INVITE:
  40. self.encryption_enabled_by_default_for_room_presets = [
  41. RoomCreationPreset.PRIVATE_CHAT,
  42. RoomCreationPreset.TRUSTED_PRIVATE_CHAT,
  43. ]
  44. elif (
  45. encryption_for_room_type == RoomDefaultEncryptionTypes.OFF
  46. or encryption_for_room_type is False
  47. ):
  48. # PyYAML translates "off" into False if it's unquoted, so we also need to
  49. # check for encryption_for_room_type being False.
  50. self.encryption_enabled_by_default_for_room_presets = []
  51. else:
  52. raise ConfigError(
  53. "Invalid value for encryption_enabled_by_default_for_room_type"
  54. )
  55. self.default_power_level_content_override = config.get(
  56. "default_power_level_content_override",
  57. None,
  58. )
  59. if self.default_power_level_content_override is not None:
  60. for preset in self.default_power_level_content_override:
  61. if preset not in vars(RoomCreationPreset).values():
  62. raise ConfigError(
  63. "Unrecognised room preset %s in default_power_level_content_override"
  64. % preset
  65. )
  66. # We validate the actual overrides when we try to apply them.
  67. # When enabled, users will forget rooms when they leave them, either via a
  68. # leave, kick or ban.
  69. self.forget_on_leave = config.get("forget_rooms_on_leave", False)