Get the new context-sensitive new menu working

This commit is contained in:
Joseph Schorr 2015-04-07 18:33:43 -04:00
parent 40a6892a49
commit d09f2f6e22
13 changed files with 461 additions and 193 deletions

View file

@ -9,6 +9,7 @@ from auth import scopes
from app import avatar, get_app_url
from operator import itemgetter
from stringscore import liquidmetal
from util.names import parse_robot_username
import math
@ -130,8 +131,13 @@ class ConductSearch(ApiResource):
avatar_data = avatar.get_data_for_org(entity)
href = '/organization/' + entity.username
elif entity.robot:
parts = parse_robot_username(entity.username)
if parts[0] == username:
href = '/user/' + username + '?tab=robots&showRobot=' + entity.username
else:
href = '/organization/' + parts[0] + '?tab=robots&showRobot=' + entity.username
kind = 'robot'
href = '/user?tab=robots'
avatar_data = None
return {
@ -148,7 +154,7 @@ class ConductSearch(ApiResource):
# Find the matching teams where the user is a member.
encountered_teams = set()
matching_teams = model.get_matching_user_teams(query, get_authenticated_user())
matching_teams = model.get_matching_user_teams(query, get_authenticated_user(), limit=5)
for team in matching_teams:
if team.id in encountered_teams:
continue
@ -165,7 +171,7 @@ class ConductSearch(ApiResource):
})
# Find matching teams in orgs admined by the user.
matching_teams = model.get_matching_admined_teams(query, get_authenticated_user())
matching_teams = model.get_matching_admined_teams(query, get_authenticated_user(), limit=5)
for team in matching_teams:
if team.id in encountered_teams:
continue
@ -183,7 +189,7 @@ class ConductSearch(ApiResource):
# Find the matching repositories.
matching_repos = model.get_matching_repositories(query, username)
matching_repos = model.get_matching_repositories(query, username, limit=5)
matching_repo_counts = {t[0]: t[1] for t in model.get_repository_pull_counts(matching_repos)}
for repo in matching_repos:
@ -197,10 +203,23 @@ class ConductSearch(ApiResource):
'href': '/repository/' + repo.namespace_user.username + '/' + repo.name
})
# Find the matching users, robots and organizations.
matching_entities = model.get_matching_user_entities(query, get_authenticated_user())
matching_entities = model.get_matching_entities(query)
entity_count = 0
for entity in matching_entities:
# If the entity is a robot, filter it to only match those that are under the current
# user or can be administered by the organization.
if entity.robot:
orgname = parse_robot_username(entity.username)[0]
if not AdministerOrganizationPermission(orgname).can() and not orgname == username:
continue
results.append(entity_view(entity))
entity_count = entity_count + 1
if entity_count >= 5:
break
for result in results:
result['score'] = result['score'] * liquidmetal.score(result['name'], query)