allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [23/27] git commit: [#7657] automatically include user who made change in auditlog, if not same user
Date Mon, 29 Sep 2014 16:17:54 GMT
[#7657] automatically include user who made change in auditlog, if not same user


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

Branch: refs/heads/db/7657
Commit: a719b4439dae253a641c5fdcc62957b1a0efe2b0
Parents: a3d64fd
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Fri Sep 26 21:16:06 2014 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Sep 26 21:57:42 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py           |  2 +-
 Allura/allura/lib/helpers.py                      |  2 ++
 Allura/allura/lib/plugin.py                       | 10 ++--------
 Allura/allura/tests/decorators.py                 |  8 ++++++--
 Allura/allura/tests/functional/test_site_admin.py |  2 +-
 Allura/allura/tests/test_plugin.py                |  4 ++--
 6 files changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/a719b443/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 9f6cc38..5b84267 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -537,7 +537,7 @@ class AdminUserDetailsController(object):
             raise HTTPNotFound()
         pwd = h.random_password()
         AuthenticationProvider.get(request).set_password(user, None, pwd)
-        h.auditlog_user('Set random password by %s', c.user.username, user=user)
+        h.auditlog_user('Set random password', user=user)
         flash('Password is set', 'ok')
         redirect(request.referer)
 

http://git-wip-us.apache.org/repos/asf/allura/blob/a719b443/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 45ff1fe..166146b 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -1208,5 +1208,7 @@ def auditlog_user(message, *args, **kwargs):
     from allura import model as M
     ip_address = request.headers.get('X-Remote-Addr', request.remote_addr)
     message = 'IP Address: {}\n'.format(ip_address) + message
+    if kwargs.get('user') and kwargs['user'] != c.user:
+        message = 'Done by user: {}\n'.format(c.user.username) + message
     M.AuditLog.log_user(message, *args, **kwargs)
 

http://git-wip-us.apache.org/repos/asf/allura/blob/a719b443/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 1ad4ef0..701f95b 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -335,18 +335,12 @@ class LocalAuthenticationProvider(AuthenticationProvider):
     def disable_user(self, user):
         user.disabled = True
         session(user).flush(user)
-        suffix = u''
-        if user != c.user:
-            suffix = u' by %s' % c.user.username
-        h.auditlog_user(u'Account disabled' + suffix, user=user)
+        h.auditlog_user(u'Account disabled', user=user)
 
     def enable_user(self, user):
         user.disabled = False
         session(user).flush(user)
-        suffix = u''
-        if user != c.user:
-            suffix = u' by %s' % c.user.username
-        h.auditlog_user(u'Account enabled' + suffix, user=user)
+        h.auditlog_user(u'Account enabled', user=user)
 
     def validate_password(self, user, password):
         return self._validate_password(user, password)

http://git-wip-us.apache.org/repos/asf/allura/blob/a719b443/Allura/allura/tests/decorators.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/decorators.py b/Allura/allura/tests/decorators.py
index df0f0b9..46369d1 100644
--- a/Allura/allura/tests/decorators.py
+++ b/Allura/allura/tests/decorators.py
@@ -165,7 +165,9 @@ def audits(*messages, **kwargs):
     M.AuditLog.query.remove()
     yield
     if kwargs.get('user'):
-        preamble = 'IP Address: .*\n'
+        actor = kwargs.get('actor', '.*')
+        ip_addr = kwargs.get('ip_addr', '.*')
+        preamble = '(Done by user: {}\n)?IP Address: {}\n'.format(actor, ip_addr)
     else:
         preamble = ''
     for message in messages:
@@ -185,7 +187,9 @@ def out_audits(*messages, **kwargs):
     M.AuditLog.query.remove()
     yield
     if kwargs.get('user'):
-        preamble = 'IP Address: .*\n'
+        actor = kwargs.get('actor', '.*')
+        ip_addr = kwargs.get('ip_addr', '.*')
+        preamble = '(Done by user: {}\n)?IP Address: {}\n'.format(actor, ip_addr)
     else:
         preamble = ''
     for message in messages:

http://git-wip-us.apache.org/repos/asf/allura/blob/a719b443/Allura/allura/tests/functional/test_site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_site_admin.py b/Allura/allura/tests/functional/test_site_admin.py
index 793f192..e24e734 100644
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -430,7 +430,7 @@ class TestUserDetails(TestController):
 
     @patch.object(LocalAuthenticationProvider, 'set_password')
     def test_set_random_password(self, set_password):
-        with td.audits('Set random password by test-admin', user=True):
+        with td.audits('Set random password', user=True, actor='test-admin'):
             r = self.app.post('/nf/admin/user/set_random_password', params={'username': 'test-user'})
         assert_in('Password is set', self.webflash(r))
         set_password.assert_called_once()

http://git-wip-us.apache.org/repos/asf/allura/blob/a719b443/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 4e9e02c..b3073f3 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -259,7 +259,7 @@ class TestLocalAuthenticationProvider(object):
     def test_enable_user(self):
         user = Mock(disabled=True, __ming__=Mock(), is_anonymous=lambda: False, _id=ObjectId())
         c.user = Mock(username='test-admin')
-        with audits('Account enabled by test-admin', user=True):
+        with audits('Account enabled', user=True, actor='test-admin'):
             self.provider.enable_user(user)
             ThreadLocalORMSession.flush_all()
         assert_equal(user.disabled, False)
@@ -267,7 +267,7 @@ class TestLocalAuthenticationProvider(object):
     def test_disable_user(self):
         user = Mock(disabled=False, __ming__=Mock(), is_anonymous=lambda: False, _id=ObjectId())
         c.user = Mock(username='test-admin')
-        with audits('Account disabled by test-admin', user=True):
+        with audits('Account disabled', user=True, actor='test-admin'):
             self.provider.disable_user(user)
             ThreadLocalORMSession.flush_all()
         assert_equal(user.disabled, True)


Mime
View raw message