From e133b163dfc6b29fb7f181b74645c9c3d44a012f Mon Sep 17 00:00:00 2001 From: ljf Date: Sun, 12 Sep 2021 17:34:05 +0200 Subject: [PATCH] [wip] Check question are initialize --- locales/en.json | 2 ++ src/yunohost/utils/config.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/locales/en.json b/locales/en.json index 588e37357..481e7c644 100644 --- a/locales/en.json +++ b/locales/en.json @@ -142,6 +142,8 @@ "certmanager_warning_subdomain_dns_record": "Subdomain '{subdomain}' does not resolve to the same IP address as '{domain}'. Some features will not be available until you fix this and regenerate the certificate.", "config_apply_failed": "Applying the new configuration failed: {error}", "config_cant_set_value_on_section": "You can't set a single value on an entire config section.", + "config_forbidden_keyword": "The keyword '{keyword}' is reserved, you can't create or use a config panel with a question with this id.", + "config_missing_init_value": "Config panel question '{question}' should be initialize with a value during install or upgrade.", "config_no_panel": "No config panel found.", "config_unknown_filter_key": "The filter key '{filter_key}' is incorrect.", "config_version_not_supported": "Config panel versions '{version}' are not supported.", diff --git a/src/yunohost/utils/config.py b/src/yunohost/utils/config.py index d13038b2b..429606dfe 100644 --- a/src/yunohost/utils/config.py +++ b/src/yunohost/utils/config.py @@ -209,7 +209,6 @@ class ConfigPanel: "default": {} } } - def convert(toml_node, node_type): """Convert TOML in internal format ('full' mode used by webadmin) Here are some properties of 1.0 config panel in toml: @@ -264,6 +263,16 @@ class ConfigPanel: "config_unknown_filter_key", filter_key=self.filter_key ) + # List forbidden keywords from helpers and sections toml (to avoid conflict) + forbidden_keywords = ["old", "app", "changed", "file_hash", "binds", "types", + "formats", "getter", "setter", "short_setting", "type", + "bind", "nothing_changed", "changes_validated", "result", + "max_progression"] + forbidden_keywords += format_description["sections"] + + for _, _, option in self._iterate(): + if option["id"] in forbidden_keywords: + raise YunohostError("config_forbidden_keyword", keyword=option["id"]) return self.config def _hydrate(self): @@ -787,9 +796,9 @@ class FileQuestion(Question): def __init__(self, question, user_answers): super().__init__(question, user_answers) if question.get("accept"): - self.accept = question.get("accept").replace(" ", "").split(",") + self.accept = question.get("accept") else: - self.accept = [] + self.accept = "" if Moulinette.interface.type == "api": if user_answers.get(f"{self.name}[name]"): self.value = { @@ -816,7 +825,7 @@ class FileQuestion(Question): return filename = self.value if isinstance(self.value, str) else self.value["filename"] - if "." not in filename or "." + filename.split(".")[-1] not in self.accept: + if "." not in filename or "." + filename.split(".")[-1] not in self.accept.replace(" ", "").split(","): raise YunohostValidationError( "app_argument_invalid", name=self.name,