From 2f7ec5b368b5b393dcc166077e970eda96281baf Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 21 Jan 2022 20:05:59 +0100 Subject: [PATCH 1/2] configpanels: config_get should return possible choices for domain, user questions (and other dynamic-choices questions) --- src/utils/config.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/config.py b/src/utils/config.py index 99a002404..90bc0be9f 100644 --- a/src/utils/config.py +++ b/src/utils/config.py @@ -285,8 +285,10 @@ class ConfigPanel: ask = m18n.n(self.config["i18n"] + "_" + option["id"]) if mode == "full": - # edit self.config directly option["ask"] = ask + question_class = ARGUMENTS_TYPE_PARSERS[option.get("type", "string")] + # FIXME : maybe other properties should be taken from the question, not just choices ?. + option["choices"] = question_class(option).choices else: result[key] = {"ask": ask} if "current_value" in option: @@ -1109,7 +1111,7 @@ class DomainQuestion(Question): if self.default is None: self.default = _get_maindomain() - self.choices = domain_list()["domains"] + self.choices = {domain: domain + ' ★' if domain == self.default else '' for domain in domain_list()['domains']} @staticmethod def normalize(value, option={}): @@ -1134,7 +1136,9 @@ class UserQuestion(Question): from yunohost.domain import _get_maindomain super().__init__(question, context, hooks) - self.choices = list(user_list()["users"].keys()) + + self.choices = {username: f"{infos['fullname']} ({infos['mail']})" + for username, infos in user_list()["users"].items()} if not self.choices: raise YunohostValidationError( From dfa021fbf7482243f30b1d0e50df92ba099f2bc4 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 22 Jan 2022 15:44:37 +0100 Subject: [PATCH 2/2] Fix tests --- src/tests/test_app_config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tests/test_app_config.py b/src/tests/test_app_config.py index 8de03bfd5..d6cf8045d 100644 --- a/src/tests/test_app_config.py +++ b/src/tests/test_app_config.py @@ -19,6 +19,7 @@ from yunohost.app import ( app_config_set, app_ssowatconf, ) +from yunohost.user import user_create, user_delete from yunohost.utils.error import YunohostError, YunohostValidationError @@ -101,6 +102,8 @@ def config_app(request): def test_app_config_get(config_app): + user_create("alice", "Alice", "White", _get_maindomain(), "test123Ynh") + assert isinstance(app_config_get(config_app), dict) assert isinstance(app_config_get(config_app, full=True), dict) assert isinstance(app_config_get(config_app, export=True), dict) @@ -108,6 +111,8 @@ def test_app_config_get(config_app): assert isinstance(app_config_get(config_app, "main.components"), dict) assert app_config_get(config_app, "main.components.boolean") == "0" + user_delete("alice") + def test_app_config_nopanel(legacy_app):