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.
 
 
 
 
 
 

68 lines
2.5 KiB

  1. # Copyright 2018 New Vector Ltd
  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 os import path
  15. from typing import Any, Optional
  16. from synapse.config import ConfigError
  17. from synapse.types import JsonDict
  18. from ._base import Config
  19. class ConsentConfig(Config):
  20. section = "consent"
  21. def __init__(self, *args: Any):
  22. super().__init__(*args)
  23. self.user_consent_version: Optional[str] = None
  24. self.user_consent_template_dir: Optional[str] = None
  25. self.user_consent_server_notice_content: Optional[JsonDict] = None
  26. self.user_consent_server_notice_to_guests = False
  27. self.block_events_without_consent_error: Optional[str] = None
  28. self.user_consent_at_registration = False
  29. self.user_consent_policy_name = "Privacy Policy"
  30. def read_config(self, config: JsonDict, **kwargs: Any) -> None:
  31. consent_config = config.get("user_consent")
  32. self.terms_template = self.read_template("terms.html")
  33. if consent_config is None:
  34. return
  35. self.user_consent_version = str(consent_config["version"])
  36. self.user_consent_template_dir = self.abspath(consent_config["template_dir"])
  37. if not isinstance(self.user_consent_template_dir, str) or not path.isdir(
  38. self.user_consent_template_dir
  39. ):
  40. raise ConfigError(
  41. "Could not find template directory '%s'"
  42. % (self.user_consent_template_dir,)
  43. )
  44. self.user_consent_server_notice_content = consent_config.get(
  45. "server_notice_content"
  46. )
  47. self.block_events_without_consent_error = consent_config.get(
  48. "block_events_error"
  49. )
  50. self.user_consent_server_notice_to_guests = bool(
  51. consent_config.get("send_server_notice_to_guests", False)
  52. )
  53. self.user_consent_at_registration = bool(
  54. consent_config.get("require_at_registration", False)
  55. )
  56. self.user_consent_policy_name = consent_config.get(
  57. "policy_name", "Privacy Policy"
  58. )