Skip to content

Commit

Permalink
Revert "fixed notifcations catalog"
Browse files Browse the repository at this point in the history
This reverts commit 610772c.

Change-Id: I7c52d0d78a02fd693383738b82c13704a1e32567
  • Loading branch information
JonasScharpf committed Dec 27, 2024
1 parent 426d554 commit 233ef51
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 75 deletions.
3 changes: 1 addition & 2 deletions cmk/gui/wato/pages/notifications/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
110 changes: 42 additions & 68 deletions cmk/gui/watolib/notification_parameter/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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 "
"<tt>http://</tt>), absolute local urls (beginning with <tt>/</tt>) or relative "
"URLs (that are relative to <tt>check_mk/</tt>)."
),
)
),
},
),
"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 "
"<tt>http://</tt>), absolute local urls (beginning with <tt>/</tt>) or relative "
"URLs (that are relative to <tt>check_mk/</tt>)."
),
)
),
},
),
"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:
Expand Down
12 changes: 10 additions & 2 deletions cmk/gui/watolib/notification_parameter/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
),
Expand Down
7 changes: 5 additions & 2 deletions cmk/update_config/plugins/actions/migrate_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,18 @@ 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))

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(
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 233ef51

Please sign in to comment.