Skip to content

Commit

Permalink
Quick setup: fix validation of all stages
Browse files Browse the repository at this point in the history
Change-Id: I31b9c632eef70fae085348523f4f2a178b1d8ce1
  • Loading branch information
loocars committed Oct 23, 2024
1 parent 0e2709b commit ae47e34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cmk/gui/openapi/endpoints/quick_setup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from cmk.gui.quick_setup.v0_unstable._registry import quick_setup_registry
from cmk.gui.quick_setup.v0_unstable.definitions import QuickSetupSaveRedirect
from cmk.gui.quick_setup.v0_unstable.setups import QuickSetupActionMode
from cmk.gui.quick_setup.v0_unstable.type_defs import ParsedFormData, RawFormData
from cmk.gui.quick_setup.v0_unstable.type_defs import ParsedFormData, RawFormData, StageIndex

from cmk import fields

Expand Down Expand Up @@ -164,6 +164,7 @@ def quicksetup_validate_stage_and_retrieve_next(params: Mapping[str, Any]) -> Re
errors := validate_stage(
quick_setup=quick_setup,
stages_raw_formspecs=[RawFormData(stage["form_data"]) for stage in body["stages"]],
stage_index=StageIndex(len(body["stages"]) - 1),
)
) is not None:
return _serve_data(Stage(errors=errors), status_code=400)
Expand Down
7 changes: 4 additions & 3 deletions cmk/gui/quick_setup/to_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def quick_setup_guided_mode(
def validate_stage(
quick_setup: QuickSetup,
stages_raw_formspecs: Sequence[RawFormData],
stage_index: StageIndex,
) -> Errors | None:
errors = Errors()
stages = [stage() for stage in quick_setup.stages]
Expand All @@ -236,7 +237,7 @@ def validate_stage(
if errors.exist():
return errors

for custom_validator in stages[StageIndex(len(stages_raw_formspecs) - 1)].custom_validators:
for custom_validator in stages[stage_index].custom_validators:
errors.stage_errors.extend(
custom_validator(
quick_setup.id,
Expand All @@ -253,8 +254,8 @@ def validate_stages(
) -> Sequence[Errors] | None:
return [
errors
for raw_formspec in stages_raw_formspecs
if (errors := validate_stage(quick_setup, [raw_formspec]))
for stage_index, raw_formspec in enumerate(stages_raw_formspecs)
if (errors := validate_stage(quick_setup, [raw_formspec], StageIndex(stage_index)))
] or None


Expand Down

0 comments on commit ae47e34

Please sign in to comment.