Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Move consent config parsing into ConsentConfig
Browse files Browse the repository at this point in the history
turns out we need to reuse this, so it's better in the config class.
  • Loading branch information
richvdh committed May 22, 2018
1 parent 9ea219c commit d5dca9a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
16 changes: 15 additions & 1 deletion synapse/config/consent_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,22 @@


class ConsentConfig(Config):
def __init__(self):
super(ConsentConfig, self).__init__()

self.user_consent_version = None
self.user_consent_template_dir = None
self.user_consent_server_notice_content = None

def read_config(self, config):
self.consent_config = config.get("user_consent")
consent_config = config.get("user_consent")
if consent_config is None:
return
self.user_consent_version = str(consent_config["version"])
self.user_consent_template_dir = consent_config["template_dir"]
self.user_consent_server_notice_content = consent_config.get(
"server_notice_content",
)

def default_config(self, **kwargs):
return DEFAULT_CONFIG
8 changes: 3 additions & 5 deletions synapse/rest/consent/consent_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ def __init__(self, hs):
# this is required by the request_handler wrapper
self.clock = hs.get_clock()

consent_config = hs.config.consent_config
if consent_config is None:
self._default_consent_verison = hs.config.user_consent_version
if self._default_consent_verison is None:
raise ConfigError(
"Consent resource is enabled but user_consent section is "
"missing in config file.",
)

# daemonize changes the cwd to /, so make the path absolute now.
consent_template_directory = path.abspath(
consent_config["template_dir"],
hs.config.user_consent_template_dir,
)
if not path.isdir(consent_template_directory):
raise ConfigError(
Expand All @@ -116,8 +116,6 @@ def __init__(self, hs):
loader = jinja2.FileSystemLoader(consent_template_directory)
self._jinja_env = jinja2.Environment(loader=loader)

self._default_consent_verison = consent_config["version"]

if hs.config.form_secret is None:
raise ConfigError(
"Consent resource is enabled but form_secret is not set in "
Expand Down
10 changes: 2 additions & 8 deletions synapse/server_notices/consent_server_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,10 @@ def __init__(self, hs):
self._server_notices_manager = hs.get_server_notices_manager()
self._store = hs.get_datastore()

self._current_consent_version = None
self._server_notice_content = None
self._users_in_progress = set()

consent_config = hs.config.consent_config
if consent_config is not None:
self._current_consent_version = str(consent_config["version"])
self._server_notice_content = consent_config.get(
"server_notice_content"
)
self._current_consent_version = hs.config.user_consent_version
self._server_notice_content = hs.config.user_consent_server_notice_content

if self._server_notice_content is not None:
if not self._server_notices_manager.is_enabled():
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
config.federation_rc_concurrent = 10
config.filter_timeline_limit = 5000
config.user_directory_search_all_users = False
config.consent_config = None
config.user_consent_server_notice_content = None

# disable user directory updates, because they get done in the
# background, which upsets the test runner.
Expand Down

0 comments on commit d5dca9a

Please sign in to comment.