You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2014/09/12 14:58:00 UTC

[1/4] git commit: [#7657] ticket:650 Add audit log to user details page

Repository: allura
Updated Branches:
  refs/heads/je/42cc_7657 64e50fd56 -> 4c5c02544


[#7657] ticket:650 Add audit log to user details page


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

Branch: refs/heads/je/42cc_7657
Commit: 676ca732fd85cae9b4a14b3012fd4bec604cc22d
Parents: 64e50fd
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Sep 12 14:04:20 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Fri Sep 12 14:04:20 2014 +0300

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py         | 28 +++++++++++++++++++-
 .../ext/admin/templates/widgets/audit.html      |  4 +--
 .../templates/site_admin_user_details.html      | 22 +++++++++++++++
 3 files changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/676ca732/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 9bfb9b4..08b69b9 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -474,16 +474,42 @@ class StatsController(object):
 class AdminUserDetailsController(object):
 
     @expose('jinja:allura:templates/site_admin_user_details.html')
-    def _default(self, username):
+    def _default(self, username, limit=25, page=0):
         user = M.User.by_username(username)
         if not user:
             raise HTTPNotFound()
         projects = user.my_projects().all()
+        audit_log = self._audit_log(user, limit, page)
         return {
             'user': user,
             'projects': projects,
+            'audit_log': audit_log,
         }
 
+    def _audit_log(self, user, limit, page):
+        limit = int(limit)
+        page = int(page)
+        if user is None or user.is_anonymous():
+            return dict(
+                entries=[],
+                imit=limit,
+                page=page,
+                count=0)
+        q = M.AuditLog.for_user(user)
+        count = q.count()
+        q = q.sort('timestamp', -1)
+        q = q.skip(page * limit)
+        if count > limit:
+            q = q.limit(limit)
+        else:
+            limit = count
+        c.audit_log_widget = W.audit
+        return dict(
+            entries=q.all(),
+            limit=limit,
+            page=page,
+            count=count)
+
 
 class StatsSiteAdminExtension(SiteAdminExtension):
     controllers = {'stats': StatsController}

http://git-wip-us.apache.org/repos/asf/allura/blob/676ca732/Allura/allura/ext/admin/templates/widgets/audit.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/widgets/audit.html b/Allura/allura/ext/admin/templates/widgets/audit.html
index 0339be8..5c9dc68 100644
--- a/Allura/allura/ext/admin/templates/widgets/audit.html
+++ b/Allura/allura/ext/admin/templates/widgets/audit.html
@@ -16,7 +16,7 @@
        specific language governing permissions and limitations
        under the License.
 -#}
-<div class="grid-19">
+<div class="grid-{{ grid if grid else '19' }}">
   <div style="overflow:auto">
     <table>
       <thead>
@@ -44,7 +44,7 @@
     </table>
   </div>
 </div>
-<div class="grid-19" style="clear:both">
+<div class="grid-{{ grid if grid else '19' }}" style="clear:both">
   {{widget.fields.page_list.display(limit=limit, page=page, count=count)}}
   {{widget.fields.page_size.display(limit=limit, count=count)}}
 </div>

http://git-wip-us.apache.org/repos/asf/allura/blob/676ca732/Allura/allura/templates/site_admin_user_details.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_user_details.html b/Allura/allura/templates/site_admin_user_details.html
index b69ab06..5aa7702 100644
--- a/Allura/allura/templates/site_admin_user_details.html
+++ b/Allura/allura/templates/site_admin_user_details.html
@@ -59,6 +59,18 @@
   {% block extra_info %}
   {% endblock extra_info %}
 
+  {% block audit_log %}
+    <div class="grid-23">
+      {% set al = audit_log %}
+      <fieldset>
+        <legend>Audit log</legend>
+        {% if al['entries'] %}
+          {{ c.audit_log_widget.display(entries=al['entries'], limit=al['limit'], page=al['page'], count=al['count'], grid='22') }}
+        {% endif %}
+      </fieldset>
+    </div>
+  {% endblock audit_log %}
+
   {% block user_projects %}
     <div class="grid-23">
       <fieldset>
@@ -72,3 +84,13 @@
     </div>
   {% endblock user_projects %}
 {% endblock %}
+
+{% block extra_css %}
+{{ super() }}
+<style>
+.pad table {
+  width: 860px;
+  margin-left: 0;
+}
+</style>
+{% endblock %}


[4/4] git commit: [#7657] ticket:650 Fix tests

Posted by je...@apache.org.
[#7657] ticket:650 Fix tests


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

Branch: refs/heads/je/42cc_7657
Commit: 4c5c02544eb28a4eaffebe10d25a0e3f981cc6c8
Parents: 68e5b97
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Sep 12 15:17:59 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Fri Sep 12 15:17:59 2014 +0300

----------------------------------------------------------------------
 .../allura/tests/functional/test_site_admin.py  | 77 +++++++++-----------
 1 file changed, 34 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/4c5c0254/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 a6ed3d1..cf563d1 100644
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -167,49 +167,6 @@ class TestSiteAdmin(TestController):
             task_name='allura.tests.functional.test_site_admin.test_task'))
         assert json.loads(r.body)['doc'] == 'test_task doc string'
 
-    @patch('allura.model.auth.request')
-    def test_users(self, request):
-        request.url = 'http://host.domain/path/'
-        c.user = M.User.by_username('test-user-1')
-        M.AuditLog.log_user('test activity user 1')
-        M.AuditLog.log_user('test activity user 2', user=M.User.by_username('test-user-2'))
-        r = self.app.get('/nf/admin/users')
-        assert_not_in('test activity', r)
-        r = self.app.get('/nf/admin/users?username=admin1')
-        assert_not_in('test activity', r)
-        r = self.app.get('/nf/admin/users?username=test-user-1')
-        assert_in('test activity user 1', r)
-        assert_not_in('test activity user 2', r)
-        r = self.app.get('/nf/admin/users?username=test-user-2')
-        assert_not_in('test activity user 1', r)
-        assert_in('test activity user 2', r)
-
-    def test_add_audit_trail_entry_access(self):
-        self.app.get('/nf/admin/add_audit_log_entry', status=404)  # GET is not allowed
-        r = self.app.post('/nf/admin/add_audit_log_entry',
-                          extra_environ={'username': '*anonymous'},
-                          status=302)
-        assert_equal(r.location, 'http://localhost/auth/')
-
-    def test_add_comment_on_users_trail_page(self):
-        r = self.app.get('/nf/admin/users')
-        assert_not_in('Add comment', r)
-        r = self.app.get('/nf/admin/users?username=fake-user')
-        assert_not_in('Add comment', r)
-        r = self.app.get('/nf/admin/users?username=test-user')
-        assert_in('Add comment', r)
-
-    def test_add_comment(self):
-        r = self.app.get('/nf/admin/users?username=test-user')
-        assert_not_in(u'Comment by test-admin: I was hêre!', r)
-        form = r.forms[1]
-        assert_equal(form['username'].value, 'test-user')
-        form['comment'] = u'I was hêre!'
-        r = form.submit()
-        assert_in(u'Comment added', self.webflash(r))
-        r = self.app.get('/nf/admin/users?username=test-user')
-        assert_in(u'Comment by test-admin: I was hêre!', r)
-
 
 class TestProjectsSearch(TestController):
 
@@ -297,6 +254,40 @@ class TestUserDetails(TestController):
         assert_in('Test Project', projects)
         assert_in('Adobe project 1', projects)
 
+    @patch('allura.model.auth.request')
+    def test_audit_log(self, request):
+        request.url = 'http://host.domain/path/'
+        c.user = M.User.by_username('test-user-1')
+        M.AuditLog.log_user('test activity user 1')
+        M.AuditLog.log_user('test activity user 2', user=M.User.by_username('test-user-2'))
+        r = self.app.get('/nf/admin/user/test-admin')
+        assert_in('Add comment', r)
+        assert_not_in('test activity', r)
+        r = self.app.get('/nf/admin/user/test-user-1')
+        assert_in('test activity user 1', r)
+        assert_not_in('test activity user 2', r)
+        r = self.app.get('/nf/admin/user/test-user-2')
+        assert_not_in('test activity user 1', r)
+        assert_in('test activity user 2', r)
+
+    def test_add_audit_trail_entry_access(self):
+        self.app.get('/nf/admin/user/add_audit_log_entry', status=404)  # GET is not allowed
+        r = self.app.post('/nf/admin/user/add_audit_log_entry',
+                          extra_environ={'username': '*anonymous'},
+                          status=302)
+        assert_equal(r.location, 'http://localhost/auth/')
+
+    def test_add_comment(self):
+        r = self.app.get('/nf/admin/user/test-user')
+        assert_not_in(u'Comment by test-admin: I was hêre!', r)
+        form = r.forms[0]
+        assert_equal(form['username'].value, 'test-user')
+        form['comment'] = u'I was hêre!'
+        r = form.submit()
+        assert_in(u'Comment added', self.webflash(r))
+        r = self.app.get('/nf/admin/user/test-user')
+        assert_in(u'Comment by test-admin: I was hêre!', r)
+
 
 @task
 def test_task(*args, **kw):


[2/4] git commit: [#7657] ticket:650 Add comment form to audit log

Posted by je...@apache.org.
[#7657] ticket:650 Add comment form to audit log


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

Branch: refs/heads/je/42cc_7657
Commit: 37f29e6b10a617661daafdf19f80ad2fabd2cdb8
Parents: 676ca73
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Sep 12 15:08:20 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Fri Sep 12 15:08:20 2014 +0300

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py              | 15 ++++++++++++++-
 Allura/allura/templates/site_admin_user_details.html | 13 +++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/37f29e6b/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 08b69b9..bad6075 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -476,7 +476,7 @@ class AdminUserDetailsController(object):
     @expose('jinja:allura:templates/site_admin_user_details.html')
     def _default(self, username, limit=25, page=0):
         user = M.User.by_username(username)
-        if not user:
+        if not user or user.is_anonymous():
             raise HTTPNotFound()
         projects = user.my_projects().all()
         audit_log = self._audit_log(user, limit, page)
@@ -510,6 +510,19 @@ class AdminUserDetailsController(object):
             page=page,
             count=count)
 
+    @expose()
+    @require_post()
+    def add_audit_trail_entry(self, **kw):
+        username = kw.get('username')
+        comment = kw.get('comment')
+        user = M.User.by_username(username)
+        if user and not user.is_anonymous() and comment:
+            M.AuditLog.comment_user(c.user, comment, user=user)
+            flash('Comment added', 'ok')
+        else:
+            flash('Can not add comment "%s" for user %s' % (comment, user))
+        redirect(request.referer)
+
 
 class StatsSiteAdminExtension(SiteAdminExtension):
     controllers = {'stats': StatsController}

http://git-wip-us.apache.org/repos/asf/allura/blob/37f29e6b/Allura/allura/templates/site_admin_user_details.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_user_details.html b/Allura/allura/templates/site_admin_user_details.html
index 5aa7702..c6936f6 100644
--- a/Allura/allura/templates/site_admin_user_details.html
+++ b/Allura/allura/templates/site_admin_user_details.html
@@ -64,6 +64,19 @@
       {% set al = audit_log %}
       <fieldset>
         <legend>Audit log</legend>
+        <form action='/nf/admin/user/add_audit_trail_entry' method='POST'>
+          <div class='grid-22'>
+            <label for='comment'>Comment:</label>
+          </div>
+          <div class='grid-22'>
+            <textarea name="comment" cols="38" rows="5"></textarea>
+          </div>
+          <div class='grid-5'>
+            <input type='hidden' name='username' value='{{ user.username }}'>
+            <input type='submit' value='Add comment'>
+            {{lib.csrf_token()}}
+          </div>
+        </form>
         {% if al['entries'] %}
           {{ c.audit_log_widget.display(entries=al['entries'], limit=al['limit'], page=al['page'], count=al['count'], grid='22') }}
         {% endif %}


[3/4] git commit: [#7657] ticket:650 Remove old audit log page

Posted by je...@apache.org.
[#7657] ticket:650 Remove old audit log page


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

Branch: refs/heads/je/42cc_7657
Commit: 68e5b977cd6c0a39d42eac08a361512199c5b321
Parents: 37f29e6
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Sep 12 15:11:21 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Fri Sep 12 15:11:21 2014 +0300

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py         | 43 ----------------
 .../templates/site_admin_users_audit.html       | 53 --------------------
 2 files changed, 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/68e5b977/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index bad6075..105de94 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -86,7 +86,6 @@ class SiteAdminController(object):
             SitemapEntry('New Projects', base_url + 'new_projects', ui_icon=g.icons['admin']),
             SitemapEntry('Reclone Repo', base_url + 'reclone_repo', ui_icon=g.icons['admin']),
             SitemapEntry('Task Manager', base_url + 'task_manager?state=busy', ui_icon=g.icons['stats']),
-            SitemapEntry('Users Audit Log', base_url + 'users', ui_icon=g.icons['admin']),
             SitemapEntry('Search Projects', base_url + 'search_projects', ui_icon=g.icons['search']),
         ]
         for ep_name in sorted(g.entry_points['site_admin']):
@@ -248,48 +247,6 @@ class SiteAdminController(object):
             mount_point = ''
         return dict(prefix=prefix, shortname=shortname, mount_point=mount_point)
 
-    @expose('jinja:allura:templates/site_admin_users_audit.html')
-    def users(self, username=None, limit=25, page=0, **kwargs):
-        user = M.User.by_username(username)
-        limit = int(limit)
-        page = int(page)
-        if user is None or user.is_anonymous():
-            return dict(
-                entries=[],
-                limit=limit,
-                page=page,
-                count=0,
-                username=username)
-        count = M.AuditLog.for_user(user).count()
-        q = M.AuditLog.for_user(user)
-        q = q.sort('timestamp', -1)
-        q = q.skip(page * limit)
-        if count > limit:
-            q = q.limit(limit)
-        else:
-            limit = count
-        c.widget = W.audit
-        return dict(
-            entries=q.all(),
-            limit=limit,
-            page=page,
-            count=count,
-            audit_user=user,
-            username=username)
-
-    @expose()
-    @require_post()
-    def add_audit_trail_entry(self, **kw):
-        username = kw.get('username')
-        comment = kw.get('comment')
-        user = M.User.by_username(username)
-        if user and not user.is_anonymous() and comment:
-            M.AuditLog.comment_user(c.user, comment, user=user)
-            flash('Comment added', 'ok')
-        else:
-            flash('Can not add comment "%s" for user %s' % (comment, user))
-        redirect(request.referer)
-
     @without_trailing_slash
     @expose('jinja:allura:templates/site_admin_search_projects.html')
     @validate(validators=dict(q=validators.UnicodeString(if_empty=None),

http://git-wip-us.apache.org/repos/asf/allura/blob/68e5b977/Allura/allura/templates/site_admin_users_audit.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_users_audit.html b/Allura/allura/templates/site_admin_users_audit.html
deleted file mode 100644
index 7a6859b..0000000
--- a/Allura/allura/templates/site_admin_users_audit.html
+++ /dev/null
@@ -1,53 +0,0 @@
-{#-
-       Licensed to the Apache Software Foundation (ASF) under one
-       or more contributor license agreements.  See the NOTICE file
-       distributed with this work for additional information
-       regarding copyright ownership.  The ASF licenses this file
-       to you under the Apache License, Version 2.0 (the
-       "License"); you may not use this file except in compliance
-       with the License.  You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-       Unless required by applicable law or agreed to in writing,
-       software distributed under the License is distributed on an
-       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-       KIND, either express or implied.  See the License for the
-       specific language governing permissions and limitations
-       under the License.
--#}
-
-{% extends 'allura:templates/site_admin.html' %}
-{% import 'allura:templates/jinja_master/lib.html' as lib with context %}
-
-{% block content %}
-<div class='grid-19'>
-  <form action='' method='GET'>
-    <div class='grid-7'>
-      <label for='username'>Username:</label>
-      <input name='username' value='{{ username if username else ''}}'>
-    </div>
-    <div class='grid-5'>
-      <input type='submit' value='Show'>
-    </div>
-  </form>
-  {% if audit_user and not audit_user.is_anonymous() %}
-    <form action='/nf/admin/add_audit_trail_entry' method='POST'>
-      <div class='grid-19'>
-        <label for='comment'>Comment:</label>
-      </div>
-      <div class='grid-19'>
-        <textarea name="comment" cols="38" rows="5"></textarea>
-      </div>
-      <div class='grid-5'>
-        <input type='hidden' name='username' value='{{ audit_user.username }}'>
-        <input type='submit' value='Add comment'>
-        {{lib.csrf_token()}}
-      </div>
-    </form>
-  {% endif %}
-  {% if entries %}
-    {{ c.widget.display(entries=entries, limit=limit, page=page, count=count) }}
-  {% endif %}
-</div>
-{% endblock %}