incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [05/16] git commit: [#6134] ticket:365 Sort the _members page
Date Tue, 04 Jun 2013 20:03:01 GMT
[#6134] ticket:365 Sort the _members page


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

Branch: refs/heads/cj/6218
Commit: 3fe4b3c1db2a41720f24da96ce5f8b78acaee799
Parents: d07ea1e
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Wed May 29 11:41:08 2013 +0400
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Tue Jun 4 14:48:16 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py        |   25 +++++++++++++++------
 Allura/allura/templates/members.html        |    2 +-
 Allura/allura/tests/functional/test_home.py |   22 +++++++++++++++++++
 3 files changed, 41 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3fe4b3c1/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index da39e5d..9436e87 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -340,16 +340,27 @@ class ProjectController(FeedController):
     @with_trailing_slash
     def _members(self, **kw):
         users = []
+        admins = []
+        developers = []
         for user in c.project.users():
             roles = M.ProjectRole.query.find({'_id': {'$in': user.project_role().roles}})
             roles = set([r.name for r in roles])
-            users.append(dict(
-                display_name=user.display_name,
-                username=user.username,
-                url=user.url(),
-                roles=roles,
-                ))
-        return dict(users=users)
+            u = dict(
+                    display_name=user.display_name,
+                    username=user.username,
+                    url=user.url(),
+                    roles=' '.join(sorted(roles)))
+            if 'Admin' in roles:
+                admins.append(u)
+            elif 'Developer' in roles:
+                developers.append(u)
+            else:
+                users.append(u)
+        get_username = lambda user: user['username']
+        admins = sorted(admins, key=get_username)
+        developers = sorted(developers, key=get_username)
+        users = sorted(users, key=get_username)
+        return dict(users=admins + developers + users)
 
     def _check_security(self):
         require_access(c.project, 'read')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3fe4b3c1/Allura/allura/templates/members.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/members.html b/Allura/allura/templates/members.html
index 2eac1d0..d455a93 100644
--- a/Allura/allura/templates/members.html
+++ b/Allura/allura/templates/members.html
@@ -35,7 +35,7 @@
     <tr>
         <td>{{ user.display_name }}</td>
         <td><a href="{{ user.url }}">{{ user.username }}</a></td>
-        <td>{{user.roles|join(', ')}}</td>
+        <td>{{user.roles}}</td>
     </tr>
     {%endfor%}
 </table>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3fe4b3c1/Allura/allura/tests/functional/test_home.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_home.py b/Allura/allura/tests/functional/test_home.py
index 73ff80c..aa9a684 100644
--- a/Allura/allura/tests/functional/test_home.py
+++ b/Allura/allura/tests/functional/test_home.py
@@ -23,6 +23,7 @@ from pylons import tmpl_context as c
 from allura.tests import TestController
 from allura.tests import decorators as td
 from allura import model as M
+from ming.orm import ThreadLocalORMSession
 
 from nose.tools import assert_equal, assert_not_in
 
@@ -105,10 +106,31 @@ class TestProjectHome(TestController):
         assert_equal(j['options'], expected)
 
     def test_members(self):
+        nbhd = M.Neighborhood.query.get(name='Projects')
+        self.app.post('/admin/groups/create', params={'name': 'B_role'})
+        test_project = M.Project.query.get(shortname='test', neighborhood_id=nbhd._id)
+        test_project.add_user(M.User.by_username('test-user-1'), ['B_role'])
+        test_project.add_user(M.User.by_username('test-user'), ['Developer'])
+        test_project.add_user(M.User.by_username('test-user-0'), ['Member'])
+        test_project.add_user(M.User.by_username('test-user-2'), ['Member'])
+        test_project.add_user(M.User.by_username('test-user-3'), ['Member'])
+        test_project.add_user(M.User.by_username('test-user-3'), ['Developer'])
+        test_project.add_user(M.User.by_username('test-user-4'), ['Admin'])
+        ThreadLocalORMSession.flush_all()
         r = self.app.get('/p/test/_members/')
+
         assert '<td>Test Admin</td>' in r
         assert '<td><a href="/u/test-admin/">test-admin</a></td>'
in r
         assert '<td>Admin</td>' in r
+        tr = r.html.findAll('tr')
+        assert "<td>Test Admin</td>" in str(tr[1])
+        assert "<td>Test User 4</td>" in str(tr[2])
+        assert "<td>Test User</td>" in str(tr[3])
+        assert "<td>Test User 3</td>" in str(tr[4])
+        assert "<td>Test User 0</td>" in str(tr[5])
+        assert "<td>Test User 1</td>" in str(tr[6])
+        assert "<td>Test User 2</td>" in str(tr[7])
+
 
     def test_members_anonymous(self):
         r = self.app.get('/p/test/_members/', extra_environ=dict(username='*anonymous'))


Mime
View raw message