Module: check_mk
Branch: master
Commit: be846756858a7c34d62d1b9962c006e1691eb124
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=be846756858a7c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Dec 2 10:51:42 2014 +0100
#1581 FIX Single context views with missing context show an error message now
When views which have a single context defined but are missing needed
context information (not hard coded, not provided per URL) are opened,
they show an error message about the missing context now.
---
.bugs/2160 | 7 +++++--
.werks/1581 | 12 ++++++++++++
ChangeLog | 1 +
web/htdocs/views.py | 8 ++++++++
web/htdocs/visuals.py | 7 +++++++
5 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/.bugs/2160 b/.bugs/2160
index 9ab473d..b9f0b8e 100644
--- a/.bugs/2160
+++ b/.bugs/2160
@@ -1,10 +1,13 @@
Title: Visuals: when single-context views are shown without context, show proper error
Component: multisite
-State: open
+Class: bug
+State: done
Date: 2014-09-02 12:18:00
Targetversion: future
-Class: bug
In the table of all views, a single-context view should either not be clickable
(except it has its context hard coded). Also we should display a useful error
if the view is being called directly via URL.
+
+2014-12-02 10:50:14: changed state open -> done
+Fixed.
diff --git a/.werks/1581 b/.werks/1581
new file mode 100644
index 0000000..a1d853a
--- /dev/null
+++ b/.werks/1581
@@ -0,0 +1,12 @@
+Title: Single context views with missing context show an error message now
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.5i7
+Date: 1417513817
+Class: fix
+
+When views which have a single context defined but are missing needed
+context information (not hard coded, not provided per URL) are opened,
+they show an error message about the missing context now.
+
diff --git a/ChangeLog b/ChangeLog
index e0e9bf7..3481d36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -92,6 +92,7 @@
* 1577 FIX: Fixed editing of views using the "Downtime for host/service"
sorter or column...
* 1578 FIX: Folding states of containers with umlauts in titles are now persisted...
* 1580 FIX: Views: Hardcoded single context filters are not shown in filter form
anymore...
+ * 1581 FIX: Single context views with missing context show an error message now...
WATO:
* 1170 Added buttons to move rules to top/bottom of the list to ruleset edit dialog
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 3e6745e..9c057d3 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -939,8 +939,16 @@ def show_view(view, show_heading = False, show_buttons = True,
# have a hardcoded value are not changeable by the user
show_filters = visuals.visible_filters_of_visual(view, use_filters)
+ # Now populate the HTML vars with context vars from the view definition. Hard
+ # coded default values are treated differently:
+ #
+ # a) single context vars of the view are enforced
+ # b) multi context vars can be overwritten by existing HTML vars
visuals.add_context_to_uri_vars(view, datasource["infos"], only_count)
+ # Check that all needed information for configured single contexts are available
+ visuals.verify_single_contexts('views', view)
+
# Af any painter, sorter or filter needs the information about the host's
# inventory, then we load it and attach it as column "host_inventory"
need_inventory_data = False
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 0fd8a81..4dc2342 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -1117,6 +1117,13 @@ def unpack_context_after_editing(packed_context):
# | |
# '----------------------------------------------------------------------'
+def verify_single_contexts(what, visual):
+ for k, v in get_singlecontext_html_vars(visual):
+ if v == None:
+ raise MKUserError(k, _('This %s can not be displayed, because the '
+ 'necessary context information "%s" is
missing.') %
+ (visual_types[what]['title'],
k))
+
def visual_title(what, visual):
extra_titles = []