Add robots to the entity search.

This commit is contained in:
yackob03 2013-11-20 18:23:59 -05:00
parent 026ed7ffb4
commit b407c1d9fb
8 changed files with 51 additions and 30 deletions

View file

@ -379,11 +379,19 @@ def get_matching_teams(team_prefix, organization):
return query.limit(10)
def get_matching_users(username_prefix, organization=None):
def get_matching_users(username_prefix, robot_namespace=None,
organization=None):
Org = User.alias()
users_no_orgs = (User.username ** (username_prefix + '%') &
(User.organization == False))
query = User.select(User.username, Org.username).where(users_no_orgs)
direct_user_query = (User.username ** (username_prefix + '%') &
(User.organization == False) & (User.robot == False))
if robot_namespace:
robot_prefix = format_robot_username(robot_namespace, username_prefix)
direct_user_query = (direct_user_query |
(User.username ** (robot_prefix + '%') &
(User.robot == True)))
query = User.select(User.username, Org.username, User.robot).where(direct_user_query)
if organization:
with_team = query.join(TeamMember, JOIN_LEFT_OUTER).join(Team,
@ -396,6 +404,7 @@ def get_matching_users(username_prefix, organization=None):
class MatchingUserResult(object):
def __init__(self, *args):
self.username = args[0]
self.is_robot = args[2]
if organization:
self.is_org_member = (args[1] == organization.username)
else: