diff --git a/src/migrations/0024_global_settings_to_configpanel.py b/src/migrations/0024_global_settings_to_configpanel.py index bb232ab94..25339a47c 100644 --- a/src/migrations/0024_global_settings_to_configpanel.py +++ b/src/migrations/0024_global_settings_to_configpanel.py @@ -2,10 +2,13 @@ import subprocess import time import urllib import os -import json from yunohost.utils.error import YunohostError from moulinette.utils.log import getActionLogger +from moulinette.utils.filesystem import ( + read_json, + write_to_yaml +) from yunohost.tools import Migration from yunohost.settings import settings_set @@ -13,6 +16,7 @@ from yunohost.utils.legacy import translate_legacy_settings_to_configpanel_setti logger = getActionLogger("yunohost.migration") +SETTINGS_PATH = "/etc/yunohost/settings.yml" OLD_SETTINGS_PATH = "/etc/yunohost/settings.json" class MyMigration(Migration): @@ -26,7 +30,7 @@ class MyMigration(Migration): return try: - old_settings = json.load(open(OLD_SETTINGS_PATH)) + old_settings = read_json(OLD_SETTINGS_PATH) except Exception as e: raise YunohostError("global_settings_cant_open_settings", reason=e) @@ -35,5 +39,6 @@ class MyMigration(Migration): if settings.get('email.smtp.smtp_relay_host') != "": settings['email.smtp.smtp_relay_enabled'] = "True" - args = urllib.parse.urlencode(settings) - settings_set(args=args) + # Here we don't use settings_set() from settings.py to prevent + # Questions to be asked when one run the migration from CLI. + write_to_yaml(SETTINGS_PATH, settings) diff --git a/src/utils/password.py b/src/utils/password.py index 26f7adad7..7b6c864ee 100644 --- a/src/utils/password.py +++ b/src/utils/password.py @@ -21,11 +21,9 @@ import sys import os -import json import string import subprocess - -from yunohost.settings import settings_get +import yaml SMALL_PWD_LIST = [ "yunohost", @@ -69,10 +67,9 @@ class PasswordValidator: # from settings.py because this file is also meant to be # use as a script by ssowat. # (or at least that's my understanding -- Alex) - # Meh... I'll try to use settings_get() anyway... What could go - # wrong ? And who even change password from SSOwat ? -- Tagada + settings = yaml.load(open("/etc/yunohost/settings.yml", "r")) setting_key = "security.password." + profile + "_strength" - self.validation_strength = settings_get(setting_key) + self.validation_strength = int(settings[setting_key]) except Exception: # Fallback to default value if we can't fetch settings for some reason self.validation_strength = 1