Module: check_mk
Branch: master
Commit: 328a58cb1b4c4021e9dfd48de057e265a63ae711
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=328a58cb1b4c40…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 18 14:09:49 2015 +0200
#2615 FIX Fixed bug in legacy dashboard conversion when having users not permitted to
access embedded views
When you have legacy dashoards (defined via plugin, located below
local/share/check_mk/web/plugins/dashboards) defined which include a view where some of
your users don't have access to and these
users are the first ones to access the GUI after apache reload/restart, this could result
in exceptions like this for other users: "KeyError: 'datasource'".
---
.werks/2615 | 12 +++++++++++
ChangeLog | 1 +
web/htdocs/dashboard.py | 52 +++++++++++++++++++++++++++++++++--------------
web/htdocs/views.py | 3 +++
4 files changed, 53 insertions(+), 15 deletions(-)
diff --git a/.werks/2615 b/.werks/2615
new file mode 100644
index 0000000..77e199b
--- /dev/null
+++ b/.werks/2615
@@ -0,0 +1,12 @@
+Title: Fixed bug in legacy dashboard conversion when having users not permitted to access
embedded views
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i3
+Date: 1442578060
+
+When you have legacy dashoards (defined via plugin, located below
local/share/check_mk/web/plugins/dashboards) defined which include a view where some of
your users don't have access to and these
+users are the first ones to access the GUI after apache reload/restart, this could
result
+in exceptions like this for other users: "KeyError: 'datasource'".
diff --git a/ChangeLog b/ChangeLog
index 601b674..ede647a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -239,6 +239,7 @@
* 2597 FIX: Fix settings downtimes on BI aggregates in distributed environment...
* 2598 FIX: Remove button for removing downtimes an BI aggregates because it cannot
work...
* 2607 FIX: Fixed broken links from BI views to aggregation group views
+ * 2615 FIX: Fixed bug in legacy dashboard conversion when having users not permitted
to access embedded views...
WATO:
* 2365 Removed old deprecated notification global options for plain emails...
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index e85bd67..e37b121 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -180,7 +180,7 @@ def transform_builtin_dashboards():
view_name = dashlet['view'].split('&')[0]
# Copy the view definition into the dashlet
- load_view_into_dashlet(dashlet, nr, view_name)
+ load_view_into_dashlet(dashlet, nr, view_name, load_from_all_views=True)
del dashlet['view']
else:
@@ -206,21 +206,44 @@ def transform_builtin_dashboards():
dashboard.setdefault('description', dashboard.get('title',
''))
builtin_dashboards_transformed = True
-def load_view_into_dashlet(dashlet, nr, view_name, add_context=None):
+def load_view_into_dashlet(dashlet, nr, view_name, add_context=None,
load_from_all_views=False):
import views
views.load_views()
- views = views.permitted_views()
- if view_name in views:
- view = copy.deepcopy(views[view_name])
- dashlet.update(view)
- if add_context:
- dashlet['context'].update(add_context)
-
- # Overwrite the views default title with the context specific title
- dashlet['title'] = visuals.visual_title('view', view)
- dashlet['title_url'] = html.makeuri_contextless(
- [('view_name', view_name)] +
visuals.get_singlecontext_vars(view).items(),
- filename='view.py')
+
+ permitted_views = views.permitted_views()
+
+ # it is random which user is first accessing
+ # an apache python process, initializing the dashboard loading and conversion of
+ # old dashboards. In case of the conversion we really try hard to make the
conversion
+ # work in all cases. So we need all views instead of the views of the user.
+ if load_from_all_views and view_name not in permitted_views:
+ # This is not really 100% correct according to the logic of visuals.available(),
+ # but we do this for the rare edge case during legacy dashboard conversion, so
+ # this should be sufficient
+ view = None
+ for (u, n), this_view in views.all_views().items():
+ # take the first view with a matching name
+ if view_name == n:
+ view = this_view
+ break
+
+ if not view:
+ raise MKGeneralException(_("Failed to convert a builtin dashboard which
is referencing "
+ "the view \"%s\". You will have to
migrate it to the new "
+ "dashboard format on your own to work
properly." % view_name))
+ else:
+ view = permitted_views[view_name]
+
+ view = copy.deepcopy(view) # Clone the view
+ dashlet.update(view)
+ if add_context:
+ dashlet['context'].update(add_context)
+
+ # Overwrite the views default title with the context specific title
+ dashlet['title'] = visuals.visual_title('view', view)
+ dashlet['title_url'] = html.makeuri_contextless(
+ [('view_name', view_name)] +
visuals.get_singlecontext_vars(view).items(),
+ filename='view.py')
dashlet['type'] = 'view'
dashlet['name'] = 'dashlet_%d' % nr
@@ -681,7 +704,6 @@ def ajax_dashlet():
if the_dashlet['type'] not in dashlet_types:
raise MKGeneralException(_('The requested dashlet type does not
exist.'))
-
render_dashlet_content(ident, the_dashlet, stash_html_vars=False)
#.
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 360ab29..284c85c 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -101,6 +101,9 @@ def permitted_views():
load_views()
return available_views
+def all_views():
+ return multisite_views
+
# Convert views that are saved in the pre 1.2.6-style
# FIXME: Can be removed one day. Mark as incompatible change or similar.
def transform_old_views():