Module: check_mk
Branch: master
Commit: 4cb485a1413a64802d3894ca53ec944bb89aaec9
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4cb485a1413a64…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu Mar 23 11:28:19 2017 +0100
Prepared WATO password modes and introduced WATO password mode for customers and sidebar snapin
Change-Id: I945c287bc119fc84a48d162dff5f350e71638b06
---
web/htdocs/wato.py | 161 ++++++++++++++++++++++++++++-------------------------
1 file changed, 86 insertions(+), 75 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index ceb0b58..c76c8193 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -15726,6 +15726,11 @@ class PasswordStore(object):
class ModePasswords(WatoMode, PasswordStore):
+ def __init__(self):
+ super(ModePasswords, self).__init__()
+ self._contact_groups = userdb.load_group_information().get("contact", {})
+
+
def title(self):
return _("Passwords")
@@ -15770,38 +15775,41 @@ class ModePasswords(WatoMode, PasswordStore):
"including this password store, are needed in plain text to contact remote systems "
"for monitoring. So all those passwords have to be stored readable by the monitoring."))
- contact_groups = userdb.load_group_information().get("contact", {})
-
- def contact_group_alias(name):
- return contact_groups.get(name, {"alias": name})["alias"]
passwords = self._owned_passwords()
table.begin("passwords", _("Passwords"))
for ident, password in sorted(passwords.items(), key=lambda e: e[1]["title"]):
table.row()
-
- table.cell(_("Actions"), css="buttons")
- edit_url = html.makeuri_contextless([("mode", "edit_password"), ("ident", ident)])
- html.icon_button(edit_url, _("Edit this password"), "edit")
- delete_url = make_action_link([("mode", "passwords"), ("_delete", ident)])
- html.icon_button(delete_url, _("Delete this password"), "delete")
-
- table.cell(_("Title"), html.attrencode(password["title"]))
- table.cell(_("Editable by"))
- if password["owned_by"] == None:
- html.write_text(_("Administrators (having the permission "
- "\"Write access to all passwords\")"))
- else:
- html.write_text(contact_group_alias(password["owned_by"]))
- table.cell(_("Shared with"))
- if not password["shared_with"]:
- html.write_text(_("Not shared"))
- else:
- html.write(html.attrencode(", ".join([ contact_group_alias(g) for g in password["shared_with"]])))
+ self._password_row(ident, password)
table.end()
+ def _password_row(self, ident, password):
+ table.cell(_("Actions"), css="buttons")
+ edit_url = html.makeuri_contextless([("mode", "edit_password"), ("ident", ident)])
+ html.icon_button(edit_url, _("Edit this password"), "edit")
+ delete_url = make_action_link([("mode", "passwords"), ("_delete", ident)])
+ html.icon_button(delete_url, _("Delete this password"), "delete")
+
+ table.cell(_("Title"), html.attrencode(password["title"]))
+ table.cell(_("Editable by"))
+ if password["owned_by"] == None:
+ html.write_text(_("Administrators (having the permission "
+ "\"Write access to all passwords\")"))
+ else:
+ html.write_text(self._contact_group_alias(password["owned_by"]))
+ table.cell(_("Shared with"))
+ if not password["shared_with"]:
+ html.write_text(_("Not shared"))
+ else:
+ html.write(html.attrencode(", ".join([ self._contact_group_alias(g) for g in password["shared_with"]])))
+
+
+ def _contact_group_alias(self, name):
+ return self._contact_groups.get(name, {"alias": name})["alias"]
+
+
class ModeEditPassword(WatoMode, PasswordStore):
def __init__(self):
@@ -15814,15 +15822,15 @@ class ModeEditPassword(WatoMode, PasswordStore):
except KeyError:
raise MKUserError("ident", _("This password does not exist."))
- self._new = False
- self._ident = ident
- self._cfg = password
- self._title = _("Edit password: %s") % password["title"]
+ self._new = False
+ self._ident = ident
+ self._cfg = password
+ self._title = _("Edit password: %s") % password["title"]
else:
- self._new = True
- self._ident = None
- self._cfg = {}
- self._title = _("New password")
+ self._new = True
+ self._ident = None
+ self._cfg = {}
+ self._title = _("New password")
def title(self):
@@ -15834,6 +15842,14 @@ class ModeEditPassword(WatoMode, PasswordStore):
def valuespec(self):
+ return Dictionary(
+ title = _("Password"),
+ elements = self._vs_elements(),
+ optional_keys = ["contact_groups"],
+ render = "form", )
+
+
+ def _vs_elements(self):
if self._new:
ident_attr = [
("ident", ID(
@@ -15862,50 +15878,45 @@ class ModeEditPassword(WatoMode, PasswordStore):
else:
admin_element = []
- return Dictionary(
- title = _("Password"),
- elements = ident_attr + [
- ("title", TextUnicode(
- title = _("Title"),
- allow_empty = False,
- size = 64,
- )),
- ("password", PasswordSpec(
- title = _("Password"),
- allow_empty = False,
- hidden = True,
- )),
- ("owned_by", Alternative(
- title = _("Editable by"),
- help = _("Each password is owned by a group of users which are able to edit, "
- "delete and use existing passwords."),
- style = "dropdown",
- elements = admin_element + [
- DropdownChoice(
- title = _("Members of the contact group:"),
- choices = lambda: self.__contact_group_choices(only_own=True),
- invalid_choice = "complain",
- empty_text = _("You need to be member of at least one contact group to be able to "
- "create a password."),
- invalid_choice_title = _("Group not existant or not member"),
- invalid_choice_error = _("The choosen group is either not existant "
- "anymore or you are not a member of this "
- "group. Please choose another one."),
- ),
- ]
- )),
- ("shared_with", DualListChoice(
- title = _("Share with"),
- help = _("By default only the members of the owner contact group are permitted "
- "to use a a configured password. It is possible to share a password with "
- "other groups of users to make them able to use a password in checks."),
- choices = self.__contact_group_choices,
- autoheight = False,
- )),
- ],
- optional_keys = ["contact_groups"],
- render = "form",
- )
+ return ident_attr + [
+ ("title", TextUnicode(
+ title = _("Title"),
+ allow_empty = False,
+ size = 64,
+ )),
+ ("password", PasswordSpec(
+ title = _("Password"),
+ allow_empty = False,
+ hidden = True,
+ )),
+ ("owned_by", Alternative(
+ title = _("Editable by"),
+ help = _("Each password is owned by a group of users which are able to edit, "
+ "delete and use existing passwords."),
+ style = "dropdown",
+ elements = admin_element + [
+ DropdownChoice(
+ title = _("Members of the contact group:"),
+ choices = lambda: self.__contact_group_choices(only_own=True),
+ invalid_choice = "complain",
+ empty_text = _("You need to be member of at least one contact group to be able to "
+ "create a password."),
+ invalid_choice_title = _("Group not existant or not member"),
+ invalid_choice_error = _("The choosen group is either not existant "
+ "anymore or you are not a member of this "
+ "group. Please choose another one."),
+ ),
+ ]
+ )),
+ ("shared_with", DualListChoice(
+ title = _("Share with"),
+ help = _("By default only the members of the owner contact group are permitted "
+ "to use a a configured password. It is possible to share a password with "
+ "other groups of users to make them able to use a password in checks."),
+ choices = self.__contact_group_choices,
+ autoheight = False,
+ )),
+ ]
def __contact_group_choices(self, only_own=False):
Module: check_mk
Branch: master
Commit: d3ec484efd66f9339dbf850c3ab2128a312bb91d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d3ec484efd66f9…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 22 12:44:34 2017 +0100
Fixed possible exception when visuals use an integer as single info key
(recently introduced error)
Change-Id: I920b9c6d3f664825365f4ff8568e49d8d3ee7d3b
---
web/htdocs/visuals.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 3c18941..e62fb37 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -1055,7 +1055,7 @@ def add_context_to_uri_vars(visual, only_infos=None, only_count=False):
# filter vars in "multiple" context are not enforced.
for key in get_single_info_keys(visual):
if key in visual['context']:
- html.set_var(key, visual['context'][key])
+ html.set_var(key, "%s" % visual['context'][key])
# Now apply the multiple context filters
for info_key in only_infos:
@@ -1070,7 +1070,7 @@ def add_context_to_uri_vars(visual, only_infos=None, only_count=False):
break
if not skip or only_count:
for uri_varname, value in filter_vars.items():
- html.set_var(uri_varname, value)
+ html.set_var(uri_varname, "%s" % value)
# Vice versa: find all filters that belong to the current URI variables
# and create a context dictionary from that.