Merge pull request #1420 from YunoHost/config-panel-choices

configpanels: config_get should return possible choices for domain, user questions (and other dynamic-choices questions)
This commit is contained in:
Alexandre Aubin 2022-01-24 18:12:45 +01:00 committed by GitHub
commit 3543821df0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -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):

View file

@ -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(