Make sure also include teams from organizations that the user admins

This commit is contained in:
Joseph Schorr 2015-04-07 13:45:49 -04:00
parent a34d56045f
commit 1b56567268
2 changed files with 45 additions and 1 deletions

View file

@ -142,9 +142,16 @@ class ConductSearch(ApiResource):
if get_authenticated_user():
username = get_authenticated_user().username
# Find the matching teams.
# Find the matching teams where the user is a member.
encountered_teams = set()
matching_teams = model.get_matching_user_teams(prefix, get_authenticated_user())
for team in matching_teams:
if team.id in encountered_teams:
continue
encountered_teams.add(team.id)
results.append({
'kind': 'team',
'name': team.name,
@ -154,6 +161,24 @@ class ConductSearch(ApiResource):
'href': '/organization/' + team.organization.username + '/teams/' + team.name
})
# Find matching teams in orgs admined by the user.
matching_teams = model.get_matching_admined_teams(prefix, get_authenticated_user())
for team in matching_teams:
if team.id in encountered_teams:
continue
encountered_teams.add(team.id)
results.append({
'kind': 'team',
'name': team.name,
'organization': entity_view(team.organization),
'avatar': avatar.get_data_for_team(team),
'score': 2,
'href': '/organization/' + team.organization.username + '/teams/' + team.name
})
# Find the matching repositories.
matching_repos = model.get_matching_repositories(prefix, username)
matching_repo_counts = {t[0]: t[1] for t in model.get_repository_pull_counts(matching_repos)}