Fix filtering of repositories in search

This commit is contained in:
Joseph Schorr 2017-03-23 11:35:17 -04:00
parent 77d2b9b290
commit 7d66f30d52

View file

@ -360,7 +360,8 @@ def get_app_repository(namespace_name, repository_name):
def get_app_search(lookup, search_fields=None, username=None, limit=50):
if search_fields is None:
search_fields = set([SEARCH_FIELDS.description.name])
search_fields = set([SEARCH_FIELDS.name.name])
return get_filtered_matching_repositories(lookup, filter_username=username,
search_fields=search_fields,
repo_kind='application', offset=0, limit=limit)
@ -382,7 +383,8 @@ def get_filtered_matching_repositories(lookup_value, filter_username=None, repo_
# Add a filter to the iterator, if necessary.
if filter_username is not None:
iterator = _filter_repositories_visible_to_username(unfiltered_query, filter_username, limit)
iterator = _filter_repositories_visible_to_username(unfiltered_query, filter_username, limit,
repo_kind)
else:
iterator = unfiltered_query
@ -393,7 +395,7 @@ def get_filtered_matching_repositories(lookup_value, filter_username=None, repo_
return list(take(limit, iterator))
def _filter_repositories_visible_to_username(unfiltered_query, filter_username, limit):
def _filter_repositories_visible_to_username(unfiltered_query, filter_username, limit, repo_kind):
encountered = set()
chunk_count = limit * 2
unfiltered_page = 0
@ -423,8 +425,7 @@ def _filter_repositories_visible_to_username(unfiltered_query, filter_username,
.join(RepositoryPermission)
.where(Repository.id << list(new_unfiltered_ids)))
filtered = _basequery.filter_to_repos_for_user(query, filter_username)
filtered = _basequery.filter_to_repos_for_user(query, filter_username, repo_kind=repo_kind)
for filtered_repo in filtered:
yield filtered_repo