Module: check_mk
Branch: master
Commit: 918eaee8f1b1277b6deab072a2b1475421500fef
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=918eaee8f1b127…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Mar 21 10:05:48 2016 +0100
3304 Bulk deleting users is now available
---
.werks/3304 | 9 +++++++++
ChangeLog | 1 +
web/htdocs/wato.py | 46 ++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/.werks/3304 b/.werks/3304
new file mode 100644
index 0000000..20517c2
--- /dev/null
+++ b/.werks/3304
@@ -0,0 +1,9 @@
+Title: Bulk deleting users is now available
+Level: 1
+Component: wato
+Compatible: compat
+Version: 1.2.9i1
+Date: 1458551082
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 8ded7e5..50cffd8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -120,6 +120,7 @@
* 3244 WATO BI Module: swap order of aggregation function and child node
selection...
* 3002 Treasure script wato_import.py: now able to set wato host tag groups
* 3003 New treasure script: migrate_oldcmk2wato.py...
+ * 3304 Bulk deleting users is now available
* 3060 FIX: Folder properties: Fixed exception when a user has no alias set...
* 3062 FIX: Git integration: Fixed not adding files in WATO folders to git control
* 3203 FIX: Distributed WATO: Fixed exception in remote host service discovery...
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 15f1c04..c690c19 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -9811,11 +9811,11 @@ def mode_users(phase):
c = wato_confirm(_("Confirm deletion of user %s" % delid),
_("Do you really want to delete the user %s?" %
delid))
if c:
- del users[delid]
+ delete_user(delid, users)
userdb.save_users(users)
- log_pending(SYNCRESTART, None, "edit-users", _("Deleted
user %s" % (delid)))
elif c == False:
return ""
+
elif html.var('_sync'):
try:
if userdb.hook_sync(add_to_changelog = True, raise_exc = True):
@@ -9827,6 +9827,9 @@ def mode_users(phase):
else:
raise MKUserError(None, str(e))
+ elif html.var("_bulk_delete_users"):
+ return bulk_delete_users_after_confirm(users)
+
return None
visible_custom_attrs = [
@@ -9839,11 +9842,21 @@ def mode_users(phase):
entries = users.items()
entries.sort(cmp = lambda a, b: cmp(a[1].get("alias", a[0]).lower(),
b[1].get("alias", b[0]).lower()))
+ html.begin_form("bulk_delete_form", method = "POST")
+
table.begin("users", None, empty_text = _("No users are defined
yet."))
online_threshold = time.time() - config.user_online_maxage
for id, user in entries:
table.row()
+ # Checkboxes
+ table.cell("<input type=button class=checkgroup name=_toggle_group"
+ " onclick=\"toggle_all_rows();\" value=\"%s\"
/>" % _('X'),
+ sortable=False, css="buttons")
+
+ if id != config.user_id:
+ html.checkbox("_c_user_%s" % id)
+
user_connection_id = userdb.cleanup_connection_id(user.get('connector'))
connection = userdb.get_connection(user_connection_id)
@@ -9954,6 +9967,10 @@ def mode_users(phase):
table.end()
+ html.button("_bulk_delete_users", _("Bulk Delete"),
"submit", style="margin-top:10px")
+ html.hidden_fields()
+ html.end_form()
+
if not userdb.load_group_information().get("contact", {}):
url = "wato.py?mode=contact_groups"
html.write("<div class=info>" +
@@ -9963,6 +9980,31 @@ def mode_users(phase):
"notifications.") % url + "</div>")
+def bulk_delete_users_after_confirm(users):
+ selected_users = []
+ for varname in html.all_varnames_with_prefix("_c_user_"):
+ if html.get_checkbox(varname):
+ user = varname.split("_c_user_")[-1]
+ if user in users:
+ selected_users.append(user)
+
+ if selected_users:
+ c = wato_confirm(_("Confirm deletion of %d users" %
len(selected_users)),
+ _("Do you really want to delete %d users?" %
len(selected_users)))
+ if c:
+ for user in selected_users:
+ delete_user(user, users)
+ elif c == False:
+ return ""
+
+ userdb.save_users(users)
+ return
+
+
+def delete_user(delid, users):
+ del users[delid]
+ log_pending(SYNCRESTART, None, "edit-users", _("Deleted user %s"
% (delid)))
+
def mode_edit_user(phase):
# Check if rule based notifications are enabled (via WATO)