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.
 
 
 
 
 
 

120 lines
4.4 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 synapse.config import ConfigError
  16. from ._base import Config
  17. DEFAULT_CONFIG = """\
  18. # User Consent configuration
  19. #
  20. # for detailed instructions, see
  21. # https://github.com/matrix-org/synapse/blob/master/docs/consent_tracking.md
  22. #
  23. # Parts of this section are required if enabling the 'consent' resource under
  24. # 'listeners', in particular 'template_dir' and 'version'.
  25. #
  26. # 'template_dir' gives the location of the templates for the HTML forms.
  27. # This directory should contain one subdirectory per language (eg, 'en', 'fr'),
  28. # and each language directory should contain the policy document (named as
  29. # '<version>.html') and a success page (success.html).
  30. #
  31. # 'version' specifies the 'current' version of the policy document. It defines
  32. # the version to be served by the consent resource if there is no 'v'
  33. # parameter.
  34. #
  35. # 'server_notice_content', if enabled, will send a user a "Server Notice"
  36. # asking them to consent to the privacy policy. The 'server_notices' section
  37. # must also be configured for this to work. Notices will *not* be sent to
  38. # guest users unless 'send_server_notice_to_guests' is set to true.
  39. #
  40. # 'block_events_error', if set, will block any attempts to send events
  41. # until the user consents to the privacy policy. The value of the setting is
  42. # used as the text of the error.
  43. #
  44. # 'require_at_registration', if enabled, will add a step to the registration
  45. # process, similar to how captcha works. Users will be required to accept the
  46. # policy before their account is created.
  47. #
  48. # 'policy_name' is the display name of the policy users will see when registering
  49. # for an account. Has no effect unless `require_at_registration` is enabled.
  50. # Defaults to "Privacy Policy".
  51. #
  52. #user_consent:
  53. # template_dir: res/templates/privacy
  54. # version: 1.0
  55. # server_notice_content:
  56. # msgtype: m.text
  57. # body: >-
  58. # To continue using this homeserver you must review and agree to the
  59. # terms and conditions at %(consent_uri)s
  60. # send_server_notice_to_guests: true
  61. # block_events_error: >-
  62. # To continue using this homeserver you must review and agree to the
  63. # terms and conditions at %(consent_uri)s
  64. # require_at_registration: false
  65. # policy_name: Privacy Policy
  66. #
  67. """
  68. class ConsentConfig(Config):
  69. section = "consent"
  70. def __init__(self, *args):
  71. super().__init__(*args)
  72. self.user_consent_version = None
  73. self.user_consent_template_dir = None
  74. self.user_consent_server_notice_content = None
  75. self.user_consent_server_notice_to_guests = False
  76. self.block_events_without_consent_error = None
  77. self.user_consent_at_registration = False
  78. self.user_consent_policy_name = "Privacy Policy"
  79. def read_config(self, config, **kwargs):
  80. consent_config = config.get("user_consent")
  81. self.terms_template = self.read_template("terms.html")
  82. if consent_config is None:
  83. return
  84. self.user_consent_version = str(consent_config["version"])
  85. self.user_consent_template_dir = self.abspath(consent_config["template_dir"])
  86. if not path.isdir(self.user_consent_template_dir):
  87. raise ConfigError(
  88. "Could not find template directory '%s'"
  89. % (self.user_consent_template_dir,)
  90. )
  91. self.user_consent_server_notice_content = consent_config.get(
  92. "server_notice_content"
  93. )
  94. self.block_events_without_consent_error = consent_config.get(
  95. "block_events_error"
  96. )
  97. self.user_consent_server_notice_to_guests = bool(
  98. consent_config.get("send_server_notice_to_guests", False)
  99. )
  100. self.user_consent_at_registration = bool(
  101. consent_config.get("require_at_registration", False)
  102. )
  103. self.user_consent_policy_name = consent_config.get(
  104. "policy_name", "Privacy Policy"
  105. )
  106. def generate_config_section(self, **kwargs):
  107. return DEFAULT_CONFIG