mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
configpanel: forbid extra props on BaseOption + accordingly fix tests
This commit is contained in:
parent
9134515604
commit
c4c79c61fe
2 changed files with 14 additions and 1 deletions
|
@ -16,6 +16,7 @@ from yunohost import app, domain, user
|
|||
from yunohost.utils.form import (
|
||||
OPTIONS,
|
||||
FORBIDDEN_PASSWORD_CHARS,
|
||||
READONLY_TYPES,
|
||||
ask_questions_and_parse_answers,
|
||||
BaseChoicesOption,
|
||||
BaseInputOption,
|
||||
|
@ -444,6 +445,9 @@ class BaseTest:
|
|||
def _test_basic_attrs(self):
|
||||
raw_option = self.get_raw_option(optional=True)
|
||||
|
||||
if raw_option["type"] in READONLY_TYPES:
|
||||
del raw_option["optional"]
|
||||
|
||||
if raw_option["type"] == "select":
|
||||
raw_option["choices"] = ["one"]
|
||||
|
||||
|
|
|
@ -258,6 +258,12 @@ class OptionType(str, Enum):
|
|||
group = "group"
|
||||
|
||||
|
||||
READONLY_TYPES = {
|
||||
OptionType.display_text,
|
||||
OptionType.markdown,
|
||||
OptionType.alert,
|
||||
OptionType.button,
|
||||
}
|
||||
FORBIDDEN_READONLY_TYPES = {
|
||||
OptionType.password,
|
||||
OptionType.app,
|
||||
|
@ -310,6 +316,7 @@ class BaseOption(BaseModel):
|
|||
arbitrary_types_allowed = True
|
||||
use_enum_values = True
|
||||
validate_assignment = True
|
||||
extra = Extra.forbid
|
||||
|
||||
@staticmethod
|
||||
def schema_extra(schema: dict[str, Any], model: Type["BaseOption"]) -> None:
|
||||
|
@ -1314,9 +1321,11 @@ class OptionsModel(BaseModel):
|
|||
"type",
|
||||
OptionType.select if "choices" in data else OptionType.string,
|
||||
),
|
||||
"optional": data.get("optional", optional),
|
||||
}
|
||||
|
||||
if option["type"] not in READONLY_TYPES:
|
||||
option["optional"] = option.get("optional", optional)
|
||||
|
||||
# LEGACY (`choices` in option `string` used to be valid)
|
||||
if "choices" in option and option["type"] == OptionType.string:
|
||||
logger.warning(
|
||||
|
|
Loading…
Add table
Reference in a new issue