incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [4/6] git commit: [#2242] Add method to retrieve project users by role name
Date Wed, 28 Nov 2012 01:27:57 GMT
[#2242] Add method to retrieve project users by role name


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

Branch: refs/heads/cj/4691
Commit: 1f96f38b093da561152325aa7ef3449731fe4005
Parents: 552a04b
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Mon Nov 26 21:17:57 2012 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Mon Nov 26 21:17:57 2012 +0000

----------------------------------------------------------------------
 Allura/allura/model/project.py |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1f96f38b/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index fc7eb00..b5c1567 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -599,6 +599,16 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             g.credentials.project_roles(project_id=self.root_project._id).named)
         return [ r.user for r in named_roles.roles_that_reach if r.user_id is not None ]
 
+    def users_with_role(self, *role_names):
+        """Return all users in this project that have at least one of the roles
+        specified.
+
+        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)]
+
     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)


Mime
View raw message