[checkmk-commits] Check_MK Git: check_mk: User/Fehler-Handling verbessert

git version control git at mathias-kettner.de
Wed Nov 21 14:35:07 CET 2012


Module: check_mk
Branch: master
Commit: 12a6d36e7affd99bc31527811fde44b142f3cf30
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=12a6d36e7affd99bc31527811fde44b142f3cf30

Author: Lars Michelsen <lm at mathias-kettner.de>
Date:   Fri Nov 16 12:37:29 2012 +0100

User/Fehler-Handling verbessert

---

 web/htdocs/userdb.py                       |    9 +++++++--
 web/htdocs/valuespec.py                    |    5 +++++
 web/htdocs/wato.css                        |    4 ++++
 web/htdocs/wato.py                         |   25 +++++++++++++++++--------
 web/plugins/wato/check_mk_configuration.py |    3 ++-
 5 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/web/htdocs/userdb.py b/web/htdocs/userdb.py
index a216ec0..2ebd0e0 100644
--- a/web/htdocs/userdb.py
+++ b/web/htdocs/userdb.py
@@ -61,13 +61,18 @@ def enabled_connectors():
             connectors.append(connector)
     return connectors
 
-# Returns the connector dictionary of the given id
-def get_connector(connector_id):
+def get_connector_id(connector_id):
     if connector_id is None:
         connector_id = 'htpasswd'
+    return connector_id
+
+# Returns the connector dictionary of the given id
+def get_connector(connector_id):
+    connector_id = get_connector_id(connector_id)
     for connector in enabled_connectors():
         if connector['id'] == connector_id:
             return connector
+    return {}
 
 # Returns a list of locked attributes
 def locked_attributes(connector_id):
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index d9c8231..a1437c5 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1063,6 +1063,7 @@ class ListChoice(ValueSpec):
         ValueSpec.__init__(self, **kwargs)
         self._choices = kwargs.get("choices")
         self._columns = kwargs.get("columns", 1)
+        self._allow_empty = kwargs.get("allow_empty", True)
         self._loaded_at = None
         self._render_function = kwargs.get("render_function", 
                   lambda id, val: val)
@@ -1119,6 +1120,10 @@ class ListChoice(ValueSpec):
             if v not in d:
                 raise MKUserError(varprefix, _("%s is not an allowed value") % v)
 
+    def validate_value(self, value, varprefix):
+        if not self._allow_empty and not value:
+            raise MKUserError(varprefix, _('You have not selected any connector. You have to select at least one.'))
+
 
 # A alternative way of editing list choices
 class MultiSelect(ListChoice):
diff --git a/web/htdocs/wato.css b/web/htdocs/wato.css
index fb19dd9..6a5e7cc 100644
--- a/web/htdocs/wato.css
+++ b/web/htdocs/wato.css
@@ -173,6 +173,10 @@ Boston, MA 02110-1301 USA.
     color: #f00;
 }
 
+.wato td.error {
+    color: #f00;
+}
+
 .wato td.takeall {
     /* width: 100%; */
 }
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index c5858a9..1bcd017 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7802,23 +7802,32 @@ def mode_users(phase):
         odd = odd == "odd" and "even" or "odd"
         html.write('<tr class="data %s0">' % odd)
 
+        connector = userdb.get_connector(user.get('connector'))
+
         # Buttons
-        edit_url = make_link([("mode", "edit_user"), ("edit", id)])
-        delete_url = html.makeactionuri([("_delete", id)])
-        clone_url = make_link([("mode", "edit_user"), ("clone", id)])
         html.write("<td class=buttons>")
-        html.icon_button(edit_url, _("Properties"), "edit")
-        html.icon_button(clone_url, _("Create a copy of this user"), "clone")
+        if connector: # only show edit buttons when the connector is available and enabled
+            edit_url = make_link([("mode", "edit_user"), ("edit", id)])
+            html.icon_button(edit_url, _("Properties"), "edit")
+
+            clone_url = make_link([("mode", "edit_user"), ("clone", id)])
+            html.icon_button(clone_url, _("Create a copy of this user"), "clone")
+
+        delete_url = html.makeactionuri([("_delete", id)])
         html.icon_button(delete_url, _("Delete"), "delete")
+
         html.write("</td>")
 
         # ID
         html.write("<td>%s</td>" % id)
 
         # Connector
-        html.write("<td>%s</td>" % userdb.get_connector(user.get('connector'))['title'])
-
-        locked_attributes = userdb.locked_attributes(user.get('connector'))
+        if connector:
+            html.write("<td>%s</td>" % connector['title'])
+            locked_attributes = userdb.locked_attributes(user.get('connector'))
+        else:
+            html.write("<td class=error>%s (disabled)</td>" % userdb.get_connector_id(user.get('connector')))
+            locked_attributes = []
 
         # Authentication
         if "automation_secret" in user:
diff --git a/web/plugins/wato/check_mk_configuration.py b/web/plugins/wato/check_mk_configuration.py
index 4f806a7..6b21477 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -285,7 +285,8 @@ register_configvar(group,
                   'to extend or replace the default authentication mechanism (htpasswd) e.g. '
                   'with ldap based mechanism.'),
         default_value = [ 'htpasswd' ],
-        choices = userdb.list_user_connectors,
+        choices       = userdb.list_user_connectors,
+        allow_empty   = False,
     ),
     domain = "multisite",
 )



More information about the checkmk-commits mailing list