allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [46/50] [abbrv] git commit: [#2716] Fix users_with_role() for subprojects.
Date Mon, 08 Apr 2013 15:19:47 GMT
[#2716] Fix users_with_role() for subprojects.

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>


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

Branch: refs/heads/db/6007
Commit: 0ce64c7b392a1af9601e38b78bcee0afc20ffa59
Parents: 46780f8
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Thu Apr 4 17:58:33 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Thu Apr 4 19:32:59 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/project.py            |   12 ++++++------
 Allura/allura/tests/model/test_project.py |    8 +++++++-
 2 files changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0ce64c7b/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index b0b45df..279a122 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -666,15 +666,15 @@ class Project(MappedClass, ActivityNode, ActivityObject):
         e.g., project.users_with_role('Admin', 'Developer') -> returns all
           users in `project` having the Admin role or the Developer role, or both
         """
-        roles = ProjectRole.query.find(dict(name={'$in': role_names}, project_id=self._id))
-        return [project_role.user for r in roles for project_role in r.users_with_role(self)]
+        users = set()
+        for role_name in role_names:
+            for user in g.credentials.users_with_named_role(self.root_project._id, role_name):
+                users.add(user)
+        return list(users)
 
     def admins(self):
         """Find all the users who have 'Admin' role for this project"""
-        admin_role = ProjectRole.query.get(name='Admin', project_id=self._id)
-        if not admin_role:
-            return []
-        return [r.user.username for r in admin_role.users_with_role(self)]
+        return self.users_with_role('Admin')
 
     def user_in_project(self, username):
         from .auth import User

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0ce64c7b/Allura/allura/tests/model/test_project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_project.py b/Allura/allura/tests/model/test_project.py
index 5277d34..b084a3d 100644
--- a/Allura/allura/tests/model/test_project.py
+++ b/Allura/allura/tests/model/test_project.py
@@ -84,4 +84,10 @@ def test_set_ordinal_to_admin_tool():
     assert c.project.sitemap()
     assert c.project.app_config('admin').options.ordinal == 100
 
-
+def test_users_and_roles():
+    p = c.project
+    sub = c.project.direct_subprojects.next()
+    u = M.User.by_username('test-admin')
+    assert p.users_with_role('Admin') == [u]
+    assert p.users_with_role('Admin') == sub.users_with_role('Admin')
+    assert p.users_with_role('Admin') == p.admins()


Mime
View raw message