Fix search to return better results by searching for robots and namespaces in different queries.
This commit is contained in:
parent
3707feaf5d
commit
396cba64e6
3 changed files with 46 additions and 29 deletions
|
@ -679,14 +679,19 @@ def get_user_or_org_by_customer_id(customer_id):
|
|||
except User.DoesNotExist:
|
||||
return None
|
||||
|
||||
def get_matching_entities(entity_prefix):
|
||||
matching_user_orgs = ((User.username ** (entity_prefix + '%')) & (User.robot == False))
|
||||
matching_robots = ((User.username ** ('%+%' + entity_prefix + '%')) & (User.robot == True))
|
||||
def get_matching_user_namespaces(namespace_prefix, username, limit=10):
|
||||
query = (Repository
|
||||
.select()
|
||||
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
|
||||
.switch(Repository)
|
||||
.join(Visibility)
|
||||
.switch(Repository)
|
||||
.join(RepositoryPermission, JOIN_LEFT_OUTER)
|
||||
.where(Namespace.username ** (namespace_prefix + '%'))
|
||||
.group_by(Repository.namespace_user, Repository)
|
||||
.limit(limit))
|
||||
|
||||
query = (User.select()
|
||||
.where(matching_user_orgs | matching_robots))
|
||||
|
||||
return query
|
||||
return [r.namespace_user for r in _filter_to_repos_for_user(query, username)]
|
||||
|
||||
def get_matching_user_teams(team_prefix, user, limit=10):
|
||||
query = (Team.select()
|
||||
|
@ -699,6 +704,23 @@ def get_matching_user_teams(team_prefix, user, limit=10):
|
|||
|
||||
return query
|
||||
|
||||
|
||||
def get_matching_robots(name_prefix, username, limit=10):
|
||||
admined_orgs = (get_user_organizations(username)
|
||||
.switch(Team)
|
||||
.join(TeamRole)
|
||||
.where(TeamRole.name == 'admin'))
|
||||
|
||||
prefix_checks = False
|
||||
|
||||
for org in admined_orgs:
|
||||
prefix_checks = prefix_checks | (User.username ** (org.username + '+' + name_prefix + '%'))
|
||||
|
||||
prefix_checks = prefix_checks | (User.username ** (username + '+' + name_prefix + '%'))
|
||||
|
||||
return User.select().where(prefix_checks).limit(limit)
|
||||
|
||||
|
||||
def get_matching_admined_teams(team_prefix, user, limit=10):
|
||||
admined_orgs = (get_user_organizations(user.username)
|
||||
.switch(Team)
|
||||
|
|
Reference in a new issue