Module: check_mk
Branch: master
Commit: 0dccf586af43aacae58ec662c009eb4746da9f73
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0dccf586af43aa…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Jan 19 13:02:20 2016 +0100
#2925 FIX Editing a notification rule for a missing user selected random other user
This problem happened when a user was removed from the system but a
notification rule still referred to that user. You cannot save any changes
now unless you select another user or deselect the whole option now.
---
.bugs/2360 | 9 ++++++---
.bugs/848 | 7 +++++--
.werks/2925 | 11 +++++++++++
ChangeLog | 1 +
web/htdocs/valuespec.py | 32 +++++++++++++++++++++++---------
web/htdocs/wato.py | 1 +
6 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/.bugs/2360 b/.bugs/2360
index 9078342..7ab250a 100644
--- a/.bugs/2360
+++ b/.bugs/2360
@@ -1,8 +1,11 @@
Title: "Fake check results" on hosts doesn't work
Component: multisite
-State: open
+Class: bug
+State: works4me
Date: 2015-08-31 16:26:06
Targetversion: 1.2.7
-Class: bug
-The "Fake check results" feature on hosts allows to set the status of the host
to "up", "down" or "unreachable" but this has no effect, the
host status stays as it was.
\ No newline at end of file
+The "Fake check results" feature on hosts allows to set the status of the host
to "up", "down" or "unreachable" but this has no effect, the
host status stays as it was.
+2016-01-19 12:39:14: changed state open -> works4me
+Works for me. Could be be cause of Smart PING that updates the
+state *really* fast.
diff --git a/.bugs/848 b/.bugs/848
index e1bb1c3..ae25f84 100644
--- a/.bugs/848
+++ b/.bugs/848
@@ -1,8 +1,11 @@
Title: RBN: Rules after user removal
Component: wato
-State: open
+Class: bug
+State: done
Date: 2015-05-13 14:56:09
Targetversion: 1.2.7
-Class: bug
After removing a user in wato and editing a rbn rule explicity containg this user, the
next user from the list will choiced when saving
+
+2016-01-19 13:00:26: changed state open -> done
+The user is now forced to select a different user.
diff --git a/.werks/2925 b/.werks/2925
new file mode 100644
index 0000000..40af2f8
--- /dev/null
+++ b/.werks/2925
@@ -0,0 +1,11 @@
+Title: Editing a notification rule for a missing user selected random other user
+Level: 1
+Component: wato
+Compatible: compat
+Version: 1.2.7i4
+Date: 1453204832
+Class: fix
+
+This problem happened when a user was removed from the system but a
+notification rule still referred to that user. You cannot save any changes
+now unless you select another user or deselect the whole option now.
diff --git a/ChangeLog b/ChangeLog
index 248f06a..d1341f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -249,6 +249,7 @@
* 2845 FIX: LDAP: Fixed exception in connection test on complain issue during
connection creation
* 2779 FIX: Fix moving of folders...
* 2825 FIX: Parameter overview page no longer raises an exception in certain
scenarios...
+ * 2925 FIX: Editing a notification rule for a missing user selected random other
user...
Notifications:
* 2811 Mail notifications: Now able to add Host/Service Notes Url...
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 3e77416..c691b3c 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1225,14 +1225,14 @@ class Checkbox(ValueSpec):
class DropdownChoice(ValueSpec):
def __init__(self, **kwargs):
ValueSpec.__init__(self, **kwargs)
- self._choices = kwargs["choices"]
- self._help_separator = kwargs.get("help_separator")
- self._label = kwargs.get("label")
- self._prefix_values = kwargs.get("prefix_values", False)
- self._sorted = kwargs.get("sorted", False)
- self._empty_text = kwargs.get("empty_text", _("There are no
elements defined for this selection yet."))
-
- self._no_preselect = kwargs.get("no_preselect", False)
+ self._choices = kwargs["choices"]
+ self._help_separator = kwargs.get("help_separator")
+ self._label = kwargs.get("label")
+ self._prefix_values = kwargs.get("prefix_values", False)
+ self._sorted = kwargs.get("sorted", False)
+ self._empty_text = kwargs.get("empty_text", _("There are
no elements defined for this selection yet."))
+ self._invalid_choice = kwargs.get("invalid_choice",
"replace") # also possible: "complain"
+ self._no_preselect = kwargs.get("no_preselect", False)
self._no_preselect_value = kwargs.get("no_preselect_value", None)
self._no_preselect_title = kwargs.get("no_preselect_title",
"") # if not preselected
self._no_preselect_error = kwargs.get("no_preselect_error",
_("Please make a selection"))
@@ -1268,6 +1268,11 @@ class DropdownChoice(ValueSpec):
options.append((str(n),) + entry[1:])
if entry[0] == value:
defval = str(n)
+
+ if self._invalid_choice == "complain" and
self._value_is_invalid(value):
+ defval = "invalid"
+ options.append((defval, _("(element does not exist anymore)")))
+
if len(options) == 0:
html.write(self._empty_text)
elif len(options[0]) == 3:
@@ -1294,7 +1299,10 @@ class DropdownChoice(ValueSpec):
val = entry[0]
if sel == str(n):
return val
- return self.default_value() # can only happen if user garbled URL or len(choices)
== 0
+ if self._invalid_choice == "replace":
+ return self.default_value() # garbled URL or len(choices) == 0
+ else:
+ raise MKUserError(varprefix, _("The selected element is not longer
available. Please select something else."))
def validate_value(self, value, varprefix):
if self._no_preselect and value == self._no_preselect_value:
@@ -1314,6 +1322,12 @@ class DropdownChoice(ValueSpec):
raise MKUserError(varprefix, _("Invalid value %s, must be in %s") %
(value, ", ".join([v for (v,t) in choices])))
+ def _value_is_invalid(self, value):
+ for entry in self.choices():
+ if entry[0] == value:
+ return False
+ return True
+
# Special conveniance variant for monitoring states
class MonitoringState(DropdownChoice):
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 64f5cf3..102d926 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -10495,6 +10495,7 @@ class UserSelection(DropdownChoice):
def __init__(self, **kwargs):
only_contacts = kwargs.get("only_contacts", False)
kwargs["choices"] =
generate_wato_users_elements_function(kwargs.get("none"), only_contacts =
only_contacts)
+ kwargs["invalid_choice"] = "complain" # handle vanished users
correctly!
DropdownChoice.__init__(self, **kwargs)
def value_to_text(self, value):