Module: check_mk
Branch: master
Commit: 979a4a38d199f1d5d89e63bf9bbdde1ce09b670a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=979a4a38d199f1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 14 11:57:47 2017 +0200
Improved error handling when trying to edit/clone not existing notification rules
Change-Id: I9cde608d325bfa1caacaa3a70f2c10a80aa4b6c0
---
web/htdocs/htmllib.py | 6 +++++-
web/htdocs/wato.py | 14 ++++++++++----
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 26eed7f..f35f0a9 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1116,7 +1116,10 @@ class RequestHandler(object):
raise MKUserError(varname, _("The given text is wrong encoded. "
"You need to provide a UTF-8 encoded
text."))
- def get_integer_input(self, varname):
+ def get_integer_input(self, varname, deflt=None):
+ if deflt is not None and not self.has_var(varname):
+ return deflt
+
try:
return int(self.var(varname))
except TypeError:
@@ -1124,6 +1127,7 @@ class RequestHandler(object):
except ValueError:
raise MKUserError(varname, _("The parameter \"%s\" is not an
integer.") % varname)
+
# Returns a dictionary containing all parameters the user handed over to this
request.
# The concept is that the user can either provide the data in a single
"request" variable,
# which contains the request data encoded as JSON, or provide multiple GET/POST vars
which
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 7b7d7d4..c458be0 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8640,8 +8640,8 @@ notification_rule_start_async_repl = False
def mode_notification_rule(phase, profilemode):
global notification_rule_start_async_repl
- edit_nr = int(html.var("edit", "-1"))
- clone_nr = int(html.var("clone", "-1"))
+ edit_nr = html.get_integer_input("edit", -1)
+ clone_nr = html.get_integer_input("clone", -1)
if profilemode:
userid = config.user.id
config.user.need_permission("general.edit_notifications")
@@ -8681,11 +8681,17 @@ def mode_notification_rule(phase, profilemode):
if new:
if clone_nr >= 0 and not html.var("_clear"):
rule = {}
- rule.update(rules[clone_nr])
+ try:
+ rule.update(rules[clone_nr])
+ except IndexError:
+ raise MKUserError(None, _("This %s does not exist.") %
"notification rule")
else:
rule = {}
else:
- rule = rules[edit_nr]
+ try:
+ rule = rules[edit_nr]
+ except IndexError:
+ raise MKUserError(None, _("This %s does not exist.") %
"notification rule")
vs = vs_notification_rule(userid)