allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject allura git commit: Add audit log messages to disable_users.py script
Date Mon, 07 Mar 2016 15:58:49 GMT
Repository: allura
Updated Branches:
  refs/heads/master 70c0f3189 -> 672ac23b0


Add audit log messages to disable_users.py script


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/672ac23b
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/672ac23b
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/672ac23b

Branch: refs/heads/master
Commit: 672ac23b0cff2b3f59e15acc7e807f1ba8a73cf0
Parents: 70c0f31
Author: Dave Brondsema <dave@brondsema.net>
Authored: Fri Mar 4 13:20:42 2016 -0500
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Fri Mar 4 13:20:42 2016 -0500

----------------------------------------------------------------------
 Allura/allura/scripts/disable_users.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/672ac23b/Allura/allura/scripts/disable_users.py
----------------------------------------------------------------------
diff --git a/Allura/allura/scripts/disable_users.py b/Allura/allura/scripts/disable_users.py
index ed93833..6c6f8b3 100644
--- a/Allura/allura/scripts/disable_users.py
+++ b/Allura/allura/scripts/disable_users.py
@@ -22,6 +22,7 @@ import sys
 from ming.odm import session
 
 from allura.lib.plugin import AuthenticationProvider
+from allura.lib import helpers as h
 from allura.scripts import ScriptTask
 from allura import model as M
 
@@ -37,10 +38,10 @@ class DisableUsers(ScriptTask):
             usernames = [line.strip() for line in sys.stdin]
         else:
             usernames = options.usernames
-        cls.disable_users(usernames)
+        cls.disable_users(usernames, options.message)
 
     @classmethod
-    def disable_users(cls, usernames):
+    def disable_users(cls, usernames, message):
         auth_provider = AuthenticationProvider.get(request=None)
 
         # would be nice to use the BatchIndexer extension around this but that only works
for artifacts not users
@@ -56,10 +57,15 @@ class DisableUsers(ScriptTask):
                 log.info('Disabling user: %s', username)
                 auth_provider.disable_user(user)
                 session(user).flush(user)
+                if message:
+                    log_entry = h.auditlog_user(message, user=user)
+                    session(log_entry).flush(log_entry)
 
     @classmethod
     def parser(cls):
         parser = argparse.ArgumentParser(description='Disable listed users')
+        parser.add_argument('--message', '-m', dest='message', type=str, default='Account
disabled',
+                            help='Message to add to the audit log for each user (set to empty
string to skip message altogether)')
         parser.add_argument(
             '--usernames', dest='usernames', type=str, nargs='+', metavar='<username>',
required=True,
             help='List of usernames, or "-" to read from stdin')


Mime
View raw message