Module: check_mk
Branch: master
Commit: 1ee35d8aeb2eada8afb7635561a25a5a26ad31a5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1ee35d8aeb2ead…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Mar 25 17:08:17 2012 +0200
WATO: allow custom user attributes
---
web/htdocs/wato.py | 34 +++++++++++++++++++++++++++++-----
web/plugins/wato/auth.py | 2 +-
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index b90dcb4..c13a521 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -6624,6 +6624,14 @@ def delete_distributed_wato_file():
# | Mode for managing users and contacts. |
# '----------------------------------------------------------------------'
+# Custom user attributes
+user_attributes = []
+user_attribute = {}
+
+def declare_user_attribute(name, vs):
+ user_attributes.append((name, vs))
+ user_attribute[name] = vs
+
def mode_users(phase):
if phase == "title":
return _("Users & Contacts")
@@ -6904,6 +6912,11 @@ def mode_edit_user(phase):
new_user[what + "_notification_options"] = "".join(
[ opt for opt in opts if html.get_checkbox(what + "_" + opt) ])
+ # Custom attributes
+ for name, vs in user_attributes:
+ value = vs.from_html_vars('ua_' + name)
+ vs.validate_value(value, "ua_" + name)
+ new_user[name] = value
# Saving
save_users(users)
@@ -7093,6 +7106,14 @@ def mode_edit_user(phase):
select_language(user.get('language', ''))
+ for name, vs in user_attributes:
+ html.write("<tr><td colspan=2 class=legend>%s" %
vs.title())
+ if vs.help():
+ html.write("<br><i>%s</i>" % vs.help())
+ html.write("</td><td class=content>")
+ vs.render_input("ua_" + name, user.get(name, vs.default_value()))
+ html.write("</td></tr>")
+
# TODO: Later we could add custom macros here, which
# then could be used for notifications. On the other hand,
# if we implement some check_mk --notify, we could directly
@@ -7210,11 +7231,12 @@ def save_users(profiles):
# TODO: delete var/check_mk/web/$USER of non-existing users. Do we
# need to remove other references as well?
- # Keys not to put into contact definitions for Check_MK
- non_contact_keys = [ "roles", "notifications_enabled",
"password", "locked", "automation_secret",
"language" ]
+ custom_values = [ name for (name, vs) in user_attributes ]
+ # Keys not to put into contact definitions for Check_MK
+ non_contact_keys = [ "roles", "notifications_enabled",
"password", "locked", "automation_secret",
"language" ] + custom_values
# Keys to put into multisite configuration
- multisite_keys = [ "roles", "notifications_enabled",
"locked", "automation_secret", "alias",
"language", ]
+ multisite_keys = [ "roles", "notifications_enabled",
"locked", "automation_secret", "alias",
"language", ] + custom_values
# Remove multisite keys in contacts. And use only such entries
# that have any contact groups assigned to.
@@ -9724,7 +9746,6 @@ def page_user_profile():
html.footer()
#.
-#.
# .--Sampleconfig--------------------------------------------------------.
# | ____ _ __ _ |
# | / ___| __ _ _ __ ___ _ __ | | ___ ___ ___ _ __ / _(_) __ _ |
@@ -10328,10 +10349,13 @@ def load_plugins():
loaded_with_language = current_language
# Reset global vars
- global extra_buttons, configured_host_tags, host_attributes
+ global extra_buttons, configured_host_tags, host_attributes, user_attributes, \
+ user_attribute
extra_buttons = []
configured_host_tags = None
host_attributes = []
+ user_attributes = []
+ user_attribute = {}
# Declare WATO-specific permissions
config.declare_permission_section("wato", _("WATO - Check_MK's Web
Administration Tool"))
diff --git a/web/plugins/wato/auth.py b/web/plugins/wato/auth.py
index 343d9cb..0290501 100644
--- a/web/plugins/wato/auth.py
+++ b/web/plugins/wato/auth.py
@@ -80,7 +80,7 @@ def parse_php(data, lvl = 1):
elif data is None:
s += 'null'
else:
- s += data
+ s += str(data)
return s