Module: check_mk
Branch: master
Commit: a689fcc247f6f7be5eaa573d4ec9c8ae77260e06
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a689fcc247f6f7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jul 3 09:38:35 2013 +0200
Added option to disable automatic userdb synchronizations in multisite
---
ChangeLog | 1 +
web/htdocs/userdb.py | 4 +++
web/htdocs/wato.py | 41 ++++++++++++++++------------
web/plugins/config/builtin.py | 17 ++++++------
web/plugins/wato/check_mk_configuration.py | 19 +++++++++++++
5 files changed, 57 insertions(+), 25 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 829ce94..f8cd5ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -73,6 +73,7 @@
searches (Can be enabled in connection settings)
* Added option to enable browser scrollbar to the multisite sidebar (only
via "sidebar_show_scrollbar = True" in multisite.mk
+ * Added option to disable automatic userdb synchronizations in multisite
WATO:
* Allow to configure check-/retry_interval in second precision
diff --git a/web/htdocs/userdb.py b/web/htdocs/userdb.py
index f864524..25d06da 100644
--- a/web/htdocs/userdb.py
+++ b/web/htdocs/userdb.py
@@ -530,6 +530,7 @@ def hook_sync(connector_id = None, add_to_changelog = False,
only_username = Non
else:
connectors = enabled_connectors()
+ no_errors = True
for connector in connectors:
handler = connector.get('sync', None)
if handler:
@@ -547,12 +548,15 @@ def hook_sync(connector_id = None, add_to_changelog = False,
only_username = Non
"<h3>" + _("Error executing sync hook")
+ "</h3>"
"<pre>%s</pre>" % (e)
)
+ no_errors = False
except:
import traceback
html.show_error(
"<h3>" + _("Error executing sync hook") +
"</h3>"
"<pre>%s</pre>" % (traceback.format_exc())
)
+ no_errors = False
+ return no_errors
# Hook function can be registered here to be executed during saving of the
# new user construct
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index f808789..b0f570a 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7928,13 +7928,15 @@ def mode_users(phase):
elif phase == "buttons":
global_buttons()
- html.context_button(_("New user"), make_link([("mode",
"edit_user")]), "new")
+ html.context_button(_("New User"), make_link([("mode",
"edit_user")]), "new")
+ if 'wato_users' not in config.userdb_automatic_sync:
+ html.context_button(_("Sync Users"),
html.makeactionuri([("_sync", 1)]), "replicate")
return
# Execute all connectors synchronisations of users. This must be done before
# loading the users, because it might modify the users list. But don't execute
# it during actions, this should save some time.
- if phase != "action":
+ if phase != "action" and 'wato_users' in
config.userdb_automatic_sync:
userdb.hook_sync(add_to_changelog = True)
roles = userdb.load_roles()
@@ -7943,23 +7945,28 @@ def mode_users(phase):
contact_groups = userdb.load_group_information().get("contact", {})
if phase == "action":
- delid = html.var("_delete")
- if delid == config.user_id:
- raise MKUserError(None, _("You cannot delete your own account!"))
+ if html.var('_delete'):
+ delid = html.var("_delete")
+ if delid == config.user_id:
+ raise MKUserError(None, _("You cannot delete your own
account!"))
- if delid not in users:
- return None # The account does not exist (anymore), no deletion needed
+ if delid not in users:
+ return None # The account does not exist (anymore), no deletion needed
- c = wato_confirm(_("Confirm deletion of user %s" % delid),
- _("Do you really want to delete the user %s?" %
delid))
- if c:
- del users[delid]
- userdb.save_users(users)
- log_pending(SYNCRESTART, None, "edit-users", _("Deleted user
%s" % (delid)))
- return None
- elif c == False:
- return ""
- else:
+ c = wato_confirm(_("Confirm deletion of user %s" % delid),
+ _("Do you really want to delete the user %s?" %
delid))
+ if c:
+ del users[delid]
+ userdb.save_users(users)
+ log_pending(SYNCRESTART, None, "edit-users", _("Deleted
user %s" % (delid)))
+ return None
+ elif c == False:
+ return ""
+ else:
+ return None
+ elif html.var('_sync'):
+ if userdb.hook_sync(add_to_changelog = True):
+ html.message(_("The user synchronization completed
successfully."))
return None
entries = users.items()
diff --git a/web/plugins/config/builtin.py b/web/plugins/config/builtin.py
index be85e05..7398ebc 100644
--- a/web/plugins/config/builtin.py
+++ b/web/plugins/config/builtin.py
@@ -196,14 +196,15 @@ pagetitle_date_format = None
# \___/|___/\___|_| |____/|____/
#
-user_connectors = ['htpasswd']
-ldap_connection = {}
-ldap_userspec = {}
-ldap_groupspec = {}
-ldap_active_plugins = {'email': {}, 'alias': {}, 'auth_expire':
{}}
-ldap_cache_livetime = 300
-ldap_debug_log = None
-default_user_profile = {
+user_connectors = ['htpasswd']
+userdb_automatic_sync = [ 'wato_users', 'page' ]
+ldap_connection = {}
+ldap_userspec = {}
+ldap_groupspec = {}
+ldap_active_plugins = {'email': {}, 'alias': {}, 'auth_expire':
{}}
+ldap_cache_livetime = 300
+ldap_debug_log = None
+default_user_profile = {
'roles': ['user'],
}
lock_on_logon_failures = False
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index f6b1537..213fcd2 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -398,6 +398,25 @@ register_configvar(group,
)
register_configvar(group,
+ "userdb_automatic_sync",
+ ListChoice(
+ title = _('Automatic User Synchronization'),
+ help = _('By default the users are synchronized automatically in several
situations. '
+ 'The sync is started when opening the "Users &
Contacts" page in configuration and '
+ 'during each page rendering. Each connector can then specify if it
wants to perform '
+ 'any actions. For example the LDAP connector will start the sync
once the cached user '
+ 'information are too old.'),
+ default_value = [ 'wato_users', 'page' ],
+ choices = [
+ ('wato_users', 'When opening WATO Users & Contacts'),
+ ('page', 'During regular page processing'),
+ ],
+ allow_empty = False,
+ ),
+ domain = "multisite",
+)
+
+register_configvar(group,
"ldap_connection",
Dictionary(
title = _("LDAP Connection Settings"),