Module: check_mk
Branch: master
Commit: ac944ea7431eb65c5fb3470d39b0ceb5d0fd274c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ac944ea7431eb6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 3 13:05:02 2017 +0100
Fixed highlighting of rules when ruleset already matches a search
Change-Id: I5a89ce2984c59ded8487acb2be491e96a6b55459
---
web/htdocs/wato.py | 6 ++---
web/htdocs/watolib.py | 63 +++++++++++++++++++++++++++++++--------------------
2 files changed, 41 insertions(+), 28 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 9b94877..3e6f834 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -12210,9 +12210,9 @@ class ModeEditRuleset(WatoMode):
if rule.is_disabled():
css.append("disabled")
- has_rule_search_options = bool([ k for k in search_options.keys()
- if k == "fulltext" or
k.startswith("rule_") ])
- if has_rule_search_options and rule.matches_search(search_options):
+ if ruleset.has_rule_search_options(search_options) \
+ and rule.matches_search(search_options) \
+ and ("fulltext" in search_options and not
ruleset.matches_fulltext_search(search_options)):
css.append("matches_search")
table.row(css=" ".join(css) if css else None)
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index 8e3c979..83897b1 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -6217,7 +6217,7 @@ class SearchedRulesets(FilteredRulesetCollection):
e.g. by their name, title or help."""
for ruleset in self._origin_rulesets.get_rulesets().values():
- if ruleset.matches_search(self._search_options):
+ if ruleset.matches_search_with_rules(self._search_options):
self._rulesets[ruleset.name] = ruleset
@@ -6319,7 +6319,39 @@ class Ruleset(object):
return content
- def matches_search(self, search_options):
+ # Whether or not either the ruleset itself matches the search or the rules match
+ def matches_search_with_rules(self, search_options):
+ if not self.matches_ruleset_search_options(search_options):
+ return False
+
+ # The ruleset matched or did not decide to skip the whole ruleset.
+ # The ruleset should be matched in case a rule matches.
+
+ if not self.has_rule_search_options(search_options):
+ return self.matches_fulltext_search(search_options)
+
+ # Store the matching rules for later result rendering
+ self.search_matching_rules = []
+ for folder, rule_index, rule in self.get_rules():
+ if rule.matches_search(search_options):
+ self.search_matching_rules.append(rule)
+
+ if not self.search_matching_rules:
+ return self.matches_fulltext_search(search_options)
+ else:
+ return True
+
+
+ def has_rule_search_options(self, search_options):
+ return bool([ k for k in search_options.keys() if k == "fulltext" or
k.startswith("rule_") ])
+
+
+ def matches_fulltext_search(self, search_options):
+ return match_one_of_search_expression(search_options, "fulltext",
+ [self.name, self.title(), self.help()])
+
+
+ def matches_ruleset_search_options(self, search_options):
if "ruleset_deprecated" in search_options and
search_options["ruleset_deprecated"] != self.is_deprecated():
return False
@@ -6339,28 +6371,6 @@ class Ruleset(object):
if not match_search_expression(search_options, "ruleset_help",
self.help()):
return False
- has_rules_search = bool([ s for s in search_options.keys() \
- if s == "fulltext" or
s.startswith("rule_") ])
-
- if not has_rules_search and "fulltext" not in search_options:
- return True
-
- # Store the matching rules for later result rendering
- self.search_matching_rules = []
- for folder, rule_index, rule in self.get_rules():
- if rule.matches_search(search_options):
- self.search_matching_rules.append(rule)
-
- if "fulltext" not in search_options:
- return bool(self.search_matching_rules)
-
- if not match_one_of_search_expression(search_options, "fulltext",
- [self.name, self.title(), self.help()]):
- if self.search_matching_rules:
- return True
- else:
- return False
-
return True
@@ -6781,6 +6791,9 @@ class Rule(object):
if not match_search_expression(search_options, "rule_comment",
self.comment()):
return False
+ if "rule_value" in search_options and not self.ruleset.valuespec():
+ return False
+
if self.ruleset.valuespec() and \
not match_search_expression(search_options, "rule_value",
"%s" %
self.ruleset.valuespec().value_to_text(self.value)):
@@ -6843,8 +6856,8 @@ def match_one_of_search_expression(search_options, attr_name,
search_in_list):
return True
return False
-#.
+#.
# .--Read-Only-----------------------------------------------------------.
# | ____ _ ___ _ |
# | | _ \ ___ __ _ __| | / _ \ _ __ | |_ _ |