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):