mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
config: update SettingsConfigPanel.reset
This commit is contained in:
parent
b45515049d
commit
54cc23c90c
1 changed files with 17 additions and 12 deletions
|
@ -23,7 +23,7 @@ from typing import TYPE_CHECKING, Any, Union
|
||||||
|
|
||||||
from moulinette import m18n
|
from moulinette import m18n
|
||||||
from yunohost.utils.error import YunohostError, YunohostValidationError
|
from yunohost.utils.error import YunohostError, YunohostValidationError
|
||||||
from yunohost.utils.configpanel import ConfigPanel
|
from yunohost.utils.configpanel import ConfigPanel, parse_filter_key
|
||||||
from yunohost.utils.form import BaseOption
|
from yunohost.utils.form import BaseOption
|
||||||
from yunohost.regenconf import regen_conf
|
from yunohost.regenconf import regen_conf
|
||||||
from yunohost.firewall import firewall_reload
|
from yunohost.firewall import firewall_reload
|
||||||
|
@ -31,6 +31,8 @@ from yunohost.log import is_unit_operation
|
||||||
from yunohost.utils.legacy import translate_legacy_settings_to_configpanel_settings
|
from yunohost.utils.legacy import translate_legacy_settings_to_configpanel_settings
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from yunohost.log import OperationLogger
|
||||||
|
|
||||||
from pydantic.typing import AbstractSetIntStr, MappingIntStrAny
|
from pydantic.typing import AbstractSetIntStr, MappingIntStrAny
|
||||||
|
|
||||||
from yunohost.utils.configpanel import (
|
from yunohost.utils.configpanel import (
|
||||||
|
@ -148,25 +150,26 @@ class SettingsConfigPanel(ConfigPanel):
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def reset(self, key="", operation_logger=None):
|
def reset(self, key: Union[str, None] = None, operation_logger: Union["OperationLogger", None] = None,):
|
||||||
self.filter_key = key
|
self.filter_key = parse_filter_key(key)
|
||||||
|
|
||||||
# Read config panel toml
|
# Read config panel toml
|
||||||
self._get_config_panel()
|
self.config, self.form = self._get_config_panel(prevalidate=True)
|
||||||
|
|
||||||
if not self.config:
|
# FIXME find a better way to exclude previous settings
|
||||||
raise YunohostValidationError("config_no_panel")
|
previous_settings = self.form.dict()
|
||||||
|
|
||||||
# Replace all values with default values
|
for option in self.config.options:
|
||||||
self.values = self._get_default_values()
|
if not option.readonly and (option.optional or option.default not in {None, ""}):
|
||||||
|
self.form[option.id] = option.normalize(option.default, option)
|
||||||
|
|
||||||
BaseOption.operation_logger = operation_logger
|
# FIXME Not sure if this is need (redact call to operation logger does it on all the instances)
|
||||||
|
# BaseOption.operation_logger = operation_logger
|
||||||
|
|
||||||
if operation_logger:
|
if operation_logger:
|
||||||
operation_logger.start()
|
operation_logger.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._apply()
|
self._apply(self.form, previous_settings)
|
||||||
except YunohostError:
|
except YunohostError:
|
||||||
raise
|
raise
|
||||||
# Script got manually interrupted ...
|
# Script got manually interrupted ...
|
||||||
|
@ -184,6 +187,8 @@ class SettingsConfigPanel(ConfigPanel):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
logger.success(m18n.n("global_settings_reset_success"))
|
logger.success(m18n.n("global_settings_reset_success"))
|
||||||
|
|
||||||
|
if operation_logger:
|
||||||
operation_logger.success()
|
operation_logger.success()
|
||||||
|
|
||||||
def _get_raw_config(self) -> "RawConfig":
|
def _get_raw_config(self) -> "RawConfig":
|
||||||
|
|
Loading…
Add table
Reference in a new issue