consent_config.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 New Vector Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from ._base import Config
  16. DEFAULT_CONFIG = """\
  17. # User Consent configuration
  18. #
  19. # for detailed instructions, see
  20. # https://github.com/matrix-org/synapse/blob/master/docs/consent_tracking.md
  21. #
  22. # Parts of this section are required if enabling the 'consent' resource under
  23. # 'listeners', in particular 'template_dir' and 'version'.
  24. #
  25. # 'template_dir' gives the location of the templates for the HTML forms.
  26. # This directory should contain one subdirectory per language (eg, 'en', 'fr'),
  27. # and each language directory should contain the policy document (named as
  28. # '<version>.html') and a success page (success.html).
  29. #
  30. # 'version' specifies the 'current' version of the policy document. It defines
  31. # the version to be served by the consent resource if there is no 'v'
  32. # parameter.
  33. #
  34. # 'server_notice_content', if enabled, will send a user a "Server Notice"
  35. # asking them to consent to the privacy policy. The 'server_notices' section
  36. # must also be configured for this to work. Notices will *not* be sent to
  37. # guest users unless 'send_server_notice_to_guests' is set to true.
  38. #
  39. # 'block_events_error', if set, will block any attempts to send events
  40. # until the user consents to the privacy policy. The value of the setting is
  41. # used as the text of the error.
  42. #
  43. # user_consent:
  44. # template_dir: res/templates/privacy
  45. # version: 1.0
  46. # server_notice_content:
  47. # msgtype: m.text
  48. # body: >-
  49. # To continue using this homeserver you must review and agree to the
  50. # terms and conditions at %(consent_uri)s
  51. # send_server_notice_to_guests: True
  52. # block_events_error: >-
  53. # To continue using this homeserver you must review and agree to the
  54. # terms and conditions at %(consent_uri)s
  55. #
  56. """
  57. class ConsentConfig(Config):
  58. def __init__(self):
  59. super(ConsentConfig, self).__init__()
  60. self.user_consent_version = None
  61. self.user_consent_template_dir = None
  62. self.user_consent_server_notice_content = None
  63. self.user_consent_server_notice_to_guests = False
  64. self.block_events_without_consent_error = None
  65. def read_config(self, config):
  66. consent_config = config.get("user_consent")
  67. if consent_config is None:
  68. return
  69. self.user_consent_version = str(consent_config["version"])
  70. self.user_consent_template_dir = consent_config["template_dir"]
  71. self.user_consent_server_notice_content = consent_config.get(
  72. "server_notice_content",
  73. )
  74. self.block_events_without_consent_error = consent_config.get(
  75. "block_events_error",
  76. )
  77. self.user_consent_server_notice_to_guests = bool(consent_config.get(
  78. "send_server_notice_to_guests", False,
  79. ))
  80. def default_config(self, **kwargs):
  81. return DEFAULT_CONFIG