From 58b7481a63a33bb578ddecdb2f76d87d638c47c4 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 16 Dec 2016 15:04:30 -0500 Subject: [PATCH] Make sure robot accounts always show up first in entity search Fixes https://www.pivotaltracker.com/story/show/136277321 Fixes #2241 --- data/model/user.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/model/user.py b/data/model/user.py index fb89d2e85..ffe5f2ec7 100644 --- a/data/model/user.py +++ b/data/model/user.py @@ -579,7 +579,7 @@ def get_matching_users(username_prefix, robot_namespace=None, organization=None, if robot_namespace: robot_prefix = format_robot_username(robot_namespace, username_prefix) robot_search = _basequery.prefix_search(User.username, robot_prefix) - direct_user_query = (direct_user_query | (robot_search & (User.robot == True))) + direct_user_query = ((robot_search & (User.robot == True)) | direct_user_query) query = (User .select(User.id, User.username, User.email, User.robot) @@ -591,7 +591,8 @@ def get_matching_users(username_prefix, robot_namespace=None, organization=None, .select(User.id, User.username, User.email, User.robot, fn.Sum(Team.id)) .join(TeamMember, JOIN_LEFT_OUTER) .join(Team, JOIN_LEFT_OUTER, on=((Team.id == TeamMember.team) & - (Team.organization == organization)))) + (Team.organization == organization))) + .order_by(User.robot.desc())) class MatchingUserResult(object): def __init__(self, *args):