Fix a bug where users in a different org would not show up in the entity search.
This commit is contained in:
		
							parent
							
								
									af697efba3
								
							
						
					
					
						commit
						e23bee99ec
					
				
					 1 changed files with 10 additions and 8 deletions
				
			
		|  | @ -386,7 +386,6 @@ def get_matching_teams(team_prefix, organization): | |||
| 
 | ||||
| def get_matching_users(username_prefix, robot_namespace=None, | ||||
|                        organization=None): | ||||
|   Org = User.alias() | ||||
|   direct_user_query = (User.username ** (username_prefix + '%') &  | ||||
|                        (User.organization == False) & (User.robot == False)) | ||||
| 
 | ||||
|  | @ -396,22 +395,25 @@ def get_matching_users(username_prefix, robot_namespace=None, | |||
|                          (User.username ** (robot_prefix + '%') &  | ||||
|                           (User.robot == True))) | ||||
| 
 | ||||
|   query = User.select(User.username, Org.username, User.robot).where(direct_user_query) | ||||
|   query = (User | ||||
|     .select(User.username, Team.id, User.robot) | ||||
|     .where(direct_user_query)) | ||||
| 
 | ||||
|   if organization: | ||||
|     with_team = query.join(TeamMember, JOIN_LEFT_OUTER).join(Team, | ||||
|                                                              JOIN_LEFT_OUTER) | ||||
|     with_org = with_team.join(Org, JOIN_LEFT_OUTER, | ||||
|                               on=(Org.id == Team.organization)) | ||||
|     query = with_org.where((Org.id == organization) | (Org.id >> None)) | ||||
|     query = (query | ||||
|       .join(TeamMember, JOIN_LEFT_OUTER) | ||||
|       .join(Team, JOIN_LEFT_OUTER, on=((Team.id == TeamMember.team) & | ||||
|                                        (Team.organization == organization)))) | ||||
| 
 | ||||
| 
 | ||||
|   class MatchingUserResult(object): | ||||
|     def __init__(self, *args): | ||||
|       logger.debug("tuple: %s" % str(args)) | ||||
| 
 | ||||
|       self.username = args[0] | ||||
|       self.is_robot = args[2] | ||||
|       if organization: | ||||
|         self.is_org_member = (args[1] == organization.username) | ||||
|         self.is_org_member = (args[1] != None) | ||||
|       else: | ||||
|         self.is_org_member = None | ||||
| 
 | ||||
|  |  | |||
		Reference in a new issue