Skip to content

Commit

Permalink
Renames admin _config var for clarity
Browse files Browse the repository at this point in the history
There's already a `.config` attribute in the sdconfig flow, so let's
rename `._config` -> `._config_in_progress` to make the intended use
case explicit to future maintainers. The contents of the
_config_in_progress dict are consulted during validation steps as part
of `sdconfig`.
  • Loading branch information
Conor Schaefer authored and kushaldas committed Sep 25, 2019
1 parent 3adc1d8 commit 4cc5178
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions admin/securedrop_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def validate(self, document):
# Raise error if admin tries to disable v3 when v2
# is already disabled.
if text == 'no' and \
not self.caller._config.get("v2_onion_services"):
not self.caller._config_in_progress.get("v2_onion_services"): # noqa: E501
raise ValidationError(message="Since you disabled v2 onion services, you must enable v3 onion services.") # noqa: E501
if text == 'yes' or text == 'no':
return True
Expand Down Expand Up @@ -276,8 +276,9 @@ def validate(self, document):
def __init__(self, args):
self.args = args
self.config = {}
# This is to hold runtime configuration before save
self._config = {}
# Hold runtime configuration before save, to support
# referencing other responses during validation
self._config_in_progress = {}
translations = SiteConfig.Locales(
self.args.app_path).get_translations()
translations = " ".join(translations)
Expand Down Expand Up @@ -464,23 +465,23 @@ def check_for_v3_onion(self):
"""
Check if v3 onion services should be enabled by default or not.
"""
v2_value = self._config.get("v2_onion_services", False)
v2_value = self._config_in_progress.get("v2_onion_services", False)
# We need to see the value in the configuration file
# for v3_onion_services
v3_value = self.config.get("v3_onion_services", True)
return v3_value or not v2_value

def user_prompt_config(self):
self._config = {}
self._config_in_progress = {}
for desc in self.desc:
(var, default, type, prompt, validator, transform,
condition) = desc
if not condition(self._config):
self._config[var] = ''
if not condition(self._config_in_progress):
self._config_in_progress[var] = ''
continue
self._config[var] = self.user_prompt_config_one(desc,
self._config_in_progress[var] = self.user_prompt_config_one(desc,
self.config.get(var)) # noqa: E501
return self._config
return self._config_in_progress

def user_prompt_config_one(self, desc, from_config):
(var, default, type, prompt, validator, transform, condition) = desc
Expand Down
2 changes: 1 addition & 1 deletion admin/tests/test_securedrop-admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def verify_prompt_boolean_for_v3(
# Now we will set v2_onion_services as True so that we
# can set v3_onion_service as False. This is the case
# when an admin particularly marked v3 as False.
site_config._config = {"v2_onion_services": True}
site_config._config_in_progress = {"v2_onion_services": True}
site_config.config = {"v3_onion_services": False}

# The next two tests should use the default from the above line,
Expand Down

0 comments on commit 4cc5178

Please sign in to comment.