Skip to content
Snippets Groups Projects
Commit d5dca9a0 authored by Richard van der Hoff's avatar Richard van der Hoff
Browse files

Move consent config parsing into ConsentConfig

turns out we need to reuse this, so it's better in the config class.
parent 9ea219c5
No related branches found
No related tags found
No related merge requests found
...@@ -45,8 +45,22 @@ DEFAULT_CONFIG = """\ ...@@ -45,8 +45,22 @@ DEFAULT_CONFIG = """\
class ConsentConfig(Config): 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): 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): def default_config(self, **kwargs):
return DEFAULT_CONFIG return DEFAULT_CONFIG
...@@ -95,8 +95,8 @@ class ConsentResource(Resource): ...@@ -95,8 +95,8 @@ class ConsentResource(Resource):
# this is required by the request_handler wrapper # this is required by the request_handler wrapper
self.clock = hs.get_clock() self.clock = hs.get_clock()
consent_config = hs.config.consent_config self._default_consent_verison = hs.config.user_consent_version
if consent_config is None: if self._default_consent_verison is None:
raise ConfigError( raise ConfigError(
"Consent resource is enabled but user_consent section is " "Consent resource is enabled but user_consent section is "
"missing in config file.", "missing in config file.",
...@@ -104,7 +104,7 @@ class ConsentResource(Resource): ...@@ -104,7 +104,7 @@ class ConsentResource(Resource):
# daemonize changes the cwd to /, so make the path absolute now. # daemonize changes the cwd to /, so make the path absolute now.
consent_template_directory = path.abspath( consent_template_directory = path.abspath(
consent_config["template_dir"], hs.config.user_consent_template_dir,
) )
if not path.isdir(consent_template_directory): if not path.isdir(consent_template_directory):
raise ConfigError( raise ConfigError(
...@@ -116,8 +116,6 @@ class ConsentResource(Resource): ...@@ -116,8 +116,6 @@ class ConsentResource(Resource):
loader = jinja2.FileSystemLoader(consent_template_directory) loader = jinja2.FileSystemLoader(consent_template_directory)
self._jinja_env = jinja2.Environment(loader=loader) self._jinja_env = jinja2.Environment(loader=loader)
self._default_consent_verison = consent_config["version"]
if hs.config.form_secret is None: if hs.config.form_secret is None:
raise ConfigError( raise ConfigError(
"Consent resource is enabled but form_secret is not set in " "Consent resource is enabled but form_secret is not set in "
......
...@@ -35,16 +35,10 @@ class ConsentServerNotices(object): ...@@ -35,16 +35,10 @@ class ConsentServerNotices(object):
self._server_notices_manager = hs.get_server_notices_manager() self._server_notices_manager = hs.get_server_notices_manager()
self._store = hs.get_datastore() self._store = hs.get_datastore()
self._current_consent_version = None
self._server_notice_content = None
self._users_in_progress = set() self._users_in_progress = set()
consent_config = hs.config.consent_config self._current_consent_version = hs.config.user_consent_version
if consent_config is not None: self._server_notice_content = hs.config.user_consent_server_notice_content
self._current_consent_version = str(consent_config["version"])
self._server_notice_content = consent_config.get(
"server_notice_content"
)
if self._server_notice_content is not None: if self._server_notice_content is not None:
if not self._server_notices_manager.is_enabled(): if not self._server_notices_manager.is_enabled():
......
...@@ -63,7 +63,7 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs): ...@@ -63,7 +63,7 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
config.federation_rc_concurrent = 10 config.federation_rc_concurrent = 10
config.filter_timeline_limit = 5000 config.filter_timeline_limit = 5000
config.user_directory_search_all_users = False 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 # disable user directory updates, because they get done in the
# background, which upsets the test runner. # background, which upsets the test runner.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment