diff --git a/locales/en.json b/locales/en.json index febcb51a9..7d95cac1a 100644 --- a/locales/en.json +++ b/locales/en.json @@ -312,10 +312,6 @@ "global_settings_key_doesnt_exists": "The key '{settings_key:s}' does not exist in the global settings, you can see all the available keys by running 'yunohost settings list'", "global_settings_reset_success": "Previous settings now backed up to {path:s}", "global_settings_setting_pop3_enabled": "Enable the POP3 protocol for the mail server", - "global_settings_setting_example_bool": "Example boolean option", - "global_settings_setting_example_enum": "Example enum option", - "global_settings_setting_example_int": "Example int option", - "global_settings_setting_example_string": "Example string option", "global_settings_setting_security_nginx_compatibility": "Compatibility vs. security tradeoff for the web server NGINX. Affects the ciphers (and other security-related aspects)", "global_settings_setting_security_password_admin_strength": "Admin password strength", "global_settings_setting_security_password_user_strength": "User password strength", diff --git a/src/yunohost/settings.py b/src/yunohost/settings.py index 71a63becd..9b8589d35 100644 --- a/src/yunohost/settings.py +++ b/src/yunohost/settings.py @@ -53,15 +53,11 @@ def is_boolean(value): # * enum (in the form of a python list) DEFAULTS = OrderedDict([ - ("example.bool", {"type": "bool", "default": True}), - ("example.int", {"type": "int", "default": 42}), - ("example.string", {"type": "string", "default": "yolo swag"}), - ("example.enum", {"type": "enum", "default": "a", "choices": ["a", "b", "c"]}), - # Password Validation # -1 disabled, 0 alert if listed, 1 8-letter, 2 normal, 3 strong, 4 strongest ("security.password.admin.strength", {"type": "int", "default": 1}), ("security.password.user.strength", {"type": "int", "default": 1}), + ("service.ssh.allow_deprecated_dsa_hostkey", {"type": "bool", "default": False}), ("security.ssh.compatibility", {"type": "enum", "default": "modern", "choices": ["intermediate", "modern"]}), @@ -69,6 +65,7 @@ DEFAULTS = OrderedDict([ "choices": ["intermediate", "modern"]}), ("security.postfix.compatibility", {"type": "enum", "default": "intermediate", "choices": ["intermediate", "modern"]}), + ("pop3.enabled", {"type": "bool", "default": False}), ("smtp.allow_ipv6", {"type": "bool", "default": True}), ("backup.compress_tar_archives", {"type": "bool", "default": False}), @@ -209,12 +206,19 @@ def settings_reset_all(): def _get_settings(): + + def get_setting_description(key): + if key.startswith("example"): + # (This is for dummy stuff used during unit tests) + return "Dummy %s setting" % key.split(".")[-1] + return m18n.n("global_settings_setting_%s" % key.replace(".", "_")) + settings = {} for key, value in DEFAULTS.copy().items(): settings[key] = value settings[key]["value"] = value["default"] - settings[key]["description"] = m18n.n("global_settings_setting_%s" % key.replace(".", "_")) + settings[key]["description"] = get_setting_description(key) if not os.path.exists(SETTINGS_PATH): return settings @@ -243,7 +247,7 @@ def _get_settings(): for key, value in local_settings.items(): if key in settings: settings[key] = value - settings[key]["description"] = m18n.n("global_settings_setting_%s" % key.replace(".", "_")) + settings[key]["description"] = get_setting_description(key) else: logger.warning(m18n.n('global_settings_unknown_setting_from_settings_file', setting_key=key)) diff --git a/src/yunohost/tests/test_settings.py b/src/yunohost/tests/test_settings.py index ea6c6922c..3fdfce67c 100644 --- a/src/yunohost/tests/test_settings.py +++ b/src/yunohost/tests/test_settings.py @@ -6,8 +6,12 @@ from yunohost.utils.error import YunohostError from yunohost.settings import settings_get, settings_list, _get_settings, \ settings_set, settings_reset, settings_reset_all, \ - SETTINGS_PATH_OTHER_LOCATION, SETTINGS_PATH + SETTINGS_PATH_OTHER_LOCATION, SETTINGS_PATH, DEFAULTS +DEFAULTS["example.bool"] = {"type": "bool", "default": True} +DEFAULTS["example.int"] = {"type": "int", "default": 42} +DEFAULTS["example.string"] = {"type": "string", "default": "yolo swag"} +DEFAULTS["example.enum"] = {"type": "enum", "default": "a", "choices": ["a", "b", "c"]} def setup_function(function): os.system("mv /etc/yunohost/settings.json /etc/yunohost/settings.json.saved") @@ -22,7 +26,7 @@ def test_settings_get_bool(): def test_settings_get_full_bool(): - assert settings_get("example.bool", True) == {"type": "bool", "value": True, "default": True, "description": "Example boolean option"} + assert settings_get("example.bool", True) == {"type": "bool", "value": True, "default": True, "description": "Dummy bool setting"} def test_settings_get_int(): @@ -30,7 +34,7 @@ def test_settings_get_int(): def test_settings_get_full_int(): - assert settings_get("example.int", True) == {"type": "int", "value": 42, "default": 42, "description": "Example int option"} + assert settings_get("example.int", True) == {"type": "int", "value": 42, "default": 42, "description": "Dummy int setting"} def test_settings_get_string(): @@ -38,7 +42,7 @@ def test_settings_get_string(): def test_settings_get_full_string(): - assert settings_get("example.string", True) == {"type": "string", "value": "yolo swag", "default": "yolo swag", "description": "Example string option"} + assert settings_get("example.string", True) == {"type": "string", "value": "yolo swag", "default": "yolo swag", "description": "Dummy string setting"} def test_settings_get_enum(): @@ -46,7 +50,7 @@ def test_settings_get_enum(): def test_settings_get_full_enum(): - assert settings_get("example.enum", True) == {"type": "enum", "value": "a", "default": "a", "description": "Example enum option", "choices": ["a", "b", "c"]} + assert settings_get("example.enum", True) == {"type": "enum", "value": "a", "default": "a", "description": "Dummy enum setting", "choices": ["a", "b", "c"]} def test_settings_get_doesnt_exists(): @@ -114,7 +118,7 @@ def test_settings_set_bad_value_enum(): def test_settings_list_modified(): settings_set("example.int", 21) - assert settings_list()["example.int"] == {'default': 42, 'description': 'Example int option', 'type': 'int', 'value': 21} + assert settings_list()["example.int"] == {'default': 42, 'description': 'Dummy int setting', 'type': 'int', 'value': 21} def test_reset():