configpanel: misc fix + add section visible evaluation

This commit is contained in:
axolotle 2022-10-02 17:10:05 +02:00
parent 9a3d65c313
commit 3d4909bbf5
3 changed files with 9 additions and 10 deletions

View file

@ -107,7 +107,6 @@ i18n = "domain_config"
style = "success" style = "success"
visible = "issuer != 'letsencrypt'" visible = "issuer != 'letsencrypt'"
enabled = "acme_eligible || cert_no_checks" enabled = "acme_eligible || cert_no_checks"
args = ["cert_no_checks"]
[cert.cert.cert_renew] [cert.cert.cert_renew]
ask = "Renew Let's Encrypt certificate" ask = "Renew Let's Encrypt certificate"

View file

@ -1539,7 +1539,7 @@ ynh_app_config_run $1
if ret != 0: if ret != 0:
if action == "show": if action == "show":
raise YunohostError("app_config_unable_to_read") raise YunohostError("app_config_unable_to_read")
elif action == "show": elif action == "apply":
raise YunohostError("app_config_unable_to_apply") raise YunohostError("app_config_unable_to_apply")
else: else:
raise YunohostError("app_action_failed", action=action) raise YunohostError("app_action_failed", action=action)

View file

@ -49,6 +49,7 @@ from yunohost.log import OperationLogger
logger = getActionLogger("yunohost.config") logger = getActionLogger("yunohost.config")
CONFIG_PANEL_VERSION_SUPPORTED = 1.0 CONFIG_PANEL_VERSION_SUPPORTED = 1.0
# Those js-like evaluate functions are used to eval safely visible attributes # Those js-like evaluate functions are used to eval safely visible attributes
# The goal is to evaluate in the same way than js simple-evaluate # The goal is to evaluate in the same way than js simple-evaluate
# https://github.com/shepherdwind/simple-evaluate # https://github.com/shepherdwind/simple-evaluate
@ -675,6 +676,11 @@ class ConfigPanel:
for panel, section, obj in self._iterate(["panel", "section"]): for panel, section, obj in self._iterate(["panel", "section"]):
if section and section.get("visible") and not evaluate_simple_js_expression(
section["visible"], context=self.new_values
):
continue
# Ugly hack to skip action section ... except when when explicitly running actions # Ugly hack to skip action section ... except when when explicitly running actions
if not for_action: if not for_action:
if section and section["is_action_section"]: if section and section["is_action_section"]:
@ -878,7 +884,8 @@ class Question:
text_for_user_input_in_cli = self._format_text_for_user_input_in_cli() text_for_user_input_in_cli = self._format_text_for_user_input_in_cli()
if self.readonly: if self.readonly:
Moulinette.display(text_for_user_input_in_cli) Moulinette.display(text_for_user_input_in_cli)
return {} self.value = self.values[self.name] = self.current_value
return self.values
elif self.value is None: elif self.value is None:
self._prompt(text_for_user_input_in_cli) self._prompt(text_for_user_input_in_cli)
@ -1459,13 +1466,6 @@ class FileQuestion(Question):
class ButtonQuestion(Question): class ButtonQuestion(Question):
argument_type = "button" argument_type = "button"
#def __init__(
# self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
#):
# super().__init__(question, context, hooks)
ARGUMENTS_TYPE_PARSERS = { ARGUMENTS_TYPE_PARSERS = {
"string": StringQuestion, "string": StringQuestion,