diff --git a/cmk/gui/wato/pages/notifications/modes.py b/cmk/gui/wato/pages/notifications/modes.py index 260384856e6..1df3363dcc5 100644 --- a/cmk/gui/wato/pages/notifications/modes.py +++ b/cmk/gui/wato/pages/notifications/modes.py @@ -44,7 +44,6 @@ from cmk.gui.breadcrumb import Breadcrumb from cmk.gui.config import active_config from cmk.gui.exceptions import MKUserError -from cmk.gui.form_specs.converter import TransformDataForLegacyFormatOrRecomposeFunction from cmk.gui.form_specs.private import Catalog, LegacyValueSpec from cmk.gui.form_specs.vue.form_spec_visitor import parse_data_from_frontend, render_form_spec from cmk.gui.form_specs.vue.visitors import DataOrigin, DEFAULT_VALUE @@ -3631,7 +3630,7 @@ def _log_text(self, edit_nr: int) -> str: return _("Created new notification parameter") return _("Changed notification parameter #%s") % edit_nr - def _form_spec(self) -> TransformDataForLegacyFormatOrRecomposeFunction: + def _form_spec(self) -> Catalog: return notification_parameter_registry.form_spec(self._method()) def action(self) -> ActionResult: diff --git a/cmk/gui/watolib/notification_parameter/_registry.py b/cmk/gui/watolib/notification_parameter/_registry.py index 72cdf81e2a9..fad514afb66 100644 --- a/cmk/gui/watolib/notification_parameter/_registry.py +++ b/cmk/gui/watolib/notification_parameter/_registry.py @@ -18,7 +18,6 @@ import cmk.gui.rulespec as _rulespec import cmk.gui.watolib.rulespecs as _rulespecs from cmk.gui.exceptions import MKUserError -from cmk.gui.form_specs.converter import TransformDataForLegacyFormatOrRecomposeFunction from cmk.gui.form_specs.private import ( Catalog, CommentTextArea, @@ -28,7 +27,6 @@ Topic, ) from cmk.gui.form_specs.private.catalog import TopicElement -from cmk.gui.form_specs.vue.visitors import DefaultValue from cmk.gui.utils.rule_specs.loader import LoadedRuleSpec from cmk.gui.valuespec import Dictionary as ValueSpecDictionary from cmk.gui.valuespec import Migrate as ValueSpecMigrate @@ -90,7 +88,7 @@ def parameter_called(self) -> Dictionary: }, ) - def form_spec(self, method: str) -> TransformDataForLegacyFormatOrRecomposeFunction: + def form_spec(self, method: str) -> Catalog: try: param_form_spec = self._entries[method]()._form_spec() except KeyError: @@ -110,72 +108,48 @@ def form_spec(self, method: str) -> TransformDataForLegacyFormatOrRecomposeFunct % (method, e), ) - def _add_method_key(value: object) -> object: - if not isinstance(value, dict): - return value - - if parameter_properties := value.get("parameter_properties"): - if isinstance(parameter_properties, DefaultValue): - return value - if "method_parameters" not in parameter_properties: - value["parameter_properties"] = {"method_parameters": parameter_properties} - - return value - - def _remove_method_key(value: object) -> object: - if not isinstance(value, dict): - return value - if parameter_properties := value.get("parameter_properties"): - if "method_parameters" in parameter_properties: - value["parameter_properties"] = parameter_properties["method_parameters"] - return value - - return TransformDataForLegacyFormatOrRecomposeFunction( - from_disk=_add_method_key, - to_disk=_remove_method_key, - wrapped_form_spec=Catalog( - elements={ - "general": Topic( - title=Title("Parameter properties"), - elements={ - "description": TopicElement( - parameter_form=String( - title=Title("Description"), - field_size=FieldSize.LARGE, - custom_validate=[not_empty()], - ), - required=True, - ), - "comment": TopicElement( - parameter_form=CommentTextArea( - title=Title("Comment"), - ) - ), - "docu_url": TopicElement( - parameter_form=String( - title=Title("Documentation URL"), - help_text=Help( - "An optional URL pointing to documentation or any other page. This will be " - "displayed as an icon and open " - "a new page when clicked. You can use either global URLs (beginning with " - "http://), absolute local urls (beginning with /) or relative " - "URLs (that are relative to check_mk/)." - ), - ) - ), - }, - ), - "parameter_properties": Topic( - title=Title("Parameter properties"), - elements={ - "method_parameters": TopicElement( - required=True, - parameter_form=param_form_spec, + return Catalog( + elements={ + "general": Topic( + title=Title("Parameter properties"), + elements={ + "description": TopicElement( + parameter_form=String( + title=Title("Description"), + field_size=FieldSize.LARGE, + custom_validate=[not_empty()], ), - }, - ), - } - ), + required=True, + ), + "comment": TopicElement( + parameter_form=CommentTextArea( + title=Title("Comment"), + ) + ), + "docu_url": TopicElement( + parameter_form=String( + title=Title("Documentation URL"), + help_text=Help( + "An optional URL pointing to documentation or any other page. This will be " + "displayed as an icon and open " + "a new page when clicked. You can use either global URLs (beginning with " + "http://), absolute local urls (beginning with /) or relative " + "URLs (that are relative to check_mk/)." + ), + ) + ), + }, + ), + "parameter_properties": Topic( + title=Title("Parameter properties"), + elements={ + "method_parameters": TopicElement( + required=True, + parameter_form=param_form_spec, + ), + }, + ), + } ) def _construct_form_spec_from_valuespec(self, method: str) -> Dictionary: diff --git a/cmk/gui/watolib/notification_parameter/_utils.py b/cmk/gui/watolib/notification_parameter/_utils.py index bf9cebdd86d..e2c0bc85a07 100644 --- a/cmk/gui/watolib/notification_parameter/_utils.py +++ b/cmk/gui/watolib/notification_parameter/_utils.py @@ -53,7 +53,7 @@ def _to_param_item(data: object) -> NotificationParameterItem: comment=general.get("comment", ""), docu_url=general.get("docu_url", ""), ), - parameter_properties=data["parameter_properties"], + parameter_properties=data["parameter_properties"]["method_parameters"], ) except KeyError as exc: raise ValueError from exc @@ -121,6 +121,14 @@ class NotificationParameter(NamedTuple): data: Mapping +def _add_method_key(item: object) -> object: + if not isinstance(item, dict): + return item + if "parameter_properties" in item: + item["parameter_properties"] = {"method_parameters": item["parameter_properties"]} + return item + + def get_notification_parameter( registry: NotificationParameterRegistry, parameter_id: NotificationParameterID, @@ -133,7 +141,7 @@ def get_notification_parameter( notification_parameter = NotificationParameterConfigFile().load_for_reading() method, item = next( ( - (method, item.get(parameter_id)) + (method, _add_method_key(item.get(parameter_id))) for method, item in notification_parameter.items() if parameter_id in item ), diff --git a/cmk/update_config/plugins/actions/migrate_notifications.py b/cmk/update_config/plugins/actions/migrate_notifications.py index 7a0a5cbdaa6..b9e59957001 100644 --- a/cmk/update_config/plugins/actions/migrate_notifications.py +++ b/cmk/update_config/plugins/actions/migrate_notifications.py @@ -123,7 +123,7 @@ def _get_data_for_disk( comment="Auto migrated on update", docu_url="", ), - parameter_properties=parameter, + parameter_properties={"method_parameters": parameter}, ) form_spec = notification_parameter_registry.form_spec(method) visitor = get_visitor(form_spec, VisitorOptions(DataOrigin.DISK)) @@ -131,7 +131,10 @@ def _get_data_for_disk( validation_errors = visitor.validate(data) process_validation_messages(validation_errors) - return visitor.to_disk(data) + # The catalog formspec uses "method_parameters" as additional nested key, we don't need it + disk_data = visitor.to_disk(data) + disk_data["parameter_properties"] = disk_data["parameter_properties"]["method_parameters"] + return disk_data update_action_registry.register( diff --git a/tests/Makefile b/tests/Makefile index 0ed401f71cc..0f0ad5bc02f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -420,7 +420,7 @@ test-cycles: $$($(UVENV) scripts/find_cmk_namespace_package_paths.py) \ $$(realpath -L ..)/omd/packages/omd/omdlib \ --strategy johnson \ - --threshold 116 \ + --threshold 114 \ --verbose test-cycles-docker: