You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/04/04 19:59:49 UTC
git commit: [#2716] Fix users_with_role() for subprojects.
Updated Branches:
refs/heads/tv/2716 [created] 45ae7f34c
[#2716] Fix users_with_role() for subprojects.
Signed-off-by: Tim Van Steenburgh <tv...@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/45ae7f34
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/45ae7f34
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/45ae7f34
Branch: refs/heads/tv/2716
Commit: 45ae7f34cc876c77376a24a8435af650e88fabae
Parents: 4c3419a
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Thu Apr 4 17:58:33 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Thu Apr 4 17:58:33 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/45ae7f34/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 39509ff..b611b1a 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -680,15 +680,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/45ae7f34/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()