Module: check_mk
Branch: master
Commit: 74bb44a176cd73edc2b8dc70ca9b9e5e15418ce4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=74bb44a176cd73…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Aug 23 11:02:09 2018 +0200
Sidebar loading: Moved legacy transforms to dedicated helpers
CMK-855
Change-Id: Icd7a1ff9878599aed8fd878175803ac42be3e331
---
cmk/gui/sidebar.py | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/cmk/gui/sidebar.py b/cmk/gui/sidebar.py
index 35a392a..4f26ea1 100644
--- a/cmk/gui/sidebar.py
+++ b/cmk/gui/sidebar.py
@@ -365,23 +365,35 @@ class UserSidebarConfig(object):
(dictionary) on the fly"""
user_config = self._user_config()
- if type(user_config) == list:
- user_config = {
- "snapins" : user_config,
- "fold": False,
- }
-
- # Remove entries the user is not allowed for or which have state "off"
(from legacy version)
- # silently skip configured but not existant snapins
+ user_config = self._transform_legacy_list_config(user_config)
+ user_config = self._transform_legacy_off_state(user_config)
+
+ # Remove entries the user is not allowed for and silently skip
+ # configured but not existing snapins
user_config["snapins"] = [
entry for entry in user_config["snapins"]
if entry[0] in snapin_registry
- and entry[1] != "off"
and self._user.may("sidesnap." + entry[0])]
return user_config
+ def _transform_legacy_list_config(self, user_config):
+ if not isinstance(user_config, list):
+ return user_config
+
+ return {
+ "snapins" : user_config,
+ "fold": False,
+ }
+
+
+ def _transform_legacy_off_state(self, user_config):
+ user_config = user_config.copy()
+ user_config["snapins"] = [ e for e in user_config["snapins"]
if e[1] != "off" ]
+ return user_config
+
+
def save(self):
if self._user.may("general.configure_sidebar"):
self._user.save_file("sidebar", self._config)