Make sure also include teams from organizations that the user admins
This commit is contained in:
parent
a34d56045f
commit
1b56567268
2 changed files with 45 additions and 1 deletions
|
@ -696,7 +696,26 @@ def get_matching_user_teams(team_prefix, user):
|
|||
.switch(Team)
|
||||
.join(TeamMember)
|
||||
.where(TeamMember.user == user, Team.name ** (team_prefix + '%'))
|
||||
.distinct(Team.id)
|
||||
.limit(10))
|
||||
|
||||
return query
|
||||
|
||||
|
||||
def get_matching_admined_teams(team_prefix, user):
|
||||
admined_orgs = (get_user_organizations(user.username)
|
||||
.switch(Team)
|
||||
.join(TeamRole)
|
||||
.where(TeamRole.name == 'admin'))
|
||||
|
||||
query = (Team.select()
|
||||
.join(User)
|
||||
.switch(Team)
|
||||
.join(TeamMember)
|
||||
.where(Team.name ** (team_prefix + '%'), Team.organization << (admined_orgs))
|
||||
.distinct(Team.id)
|
||||
.limit(10))
|
||||
|
||||
return query
|
||||
|
||||
|
||||
|
|
|
@ -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)}
|
||||
|
|
Reference in a new issue