Merge pull request #3364 from quay/appr-search-fix

Extend appr search to return private repositories
This commit is contained in:
Joseph Schorr 2019-02-15 11:24:08 -05:00 committed by GitHub
commit c4f7b28dc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,30 +11,48 @@ def list_packages_query(models_ref, namespace=None, media_type=None, search_quer
username=None):
""" List and filter repository by search query. """
Tag = models_ref.Tag
fields = [model.repository.SEARCH_FIELDS.name.name]
if search_query is not None:
repositories = model.repository.get_app_search(search_query,
username=username,
search_fields=fields,
limit=50)
if username and not search_query:
repositories = model.repository.get_visible_repositories(username,
kind_filter='application',
include_public=True,
namespace=namespace,
limit=50)
if not repositories:
return []
repo_query = (Repository
.select(Repository, Namespace.username)
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
.where(Repository.id << [repo.id for repo in repositories]))
else:
repo_query = (Repository
.select(Repository, Namespace.username)
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
.where(Repository.visibility == model.repository.get_public_repo_visibility(),
Repository.kind == Repository.kind.get_id('application')))
.where(Repository.id << [repo.rid for repo in repositories]))
if namespace:
repo_query = (repo_query
.where(Namespace.username == namespace))
if namespace:
repo_query = (repo_query
.where(Namespace.username == namespace))
else:
if search_query is not None:
fields = [model.repository.SEARCH_FIELDS.name.name]
repositories = model.repository.get_app_search(search_query,
username=username,
search_fields=fields,
limit=50)
if not repositories:
return []
repo_query = (Repository
.select(Repository, Namespace.username)
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
.where(Repository.id << [repo.id for repo in repositories]))
else:
repo_query = (Repository
.select(Repository, Namespace.username)
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
.where(Repository.visibility == model.repository.get_public_repo_visibility(),
Repository.kind == Repository.kind.get_id('application')))
if namespace:
repo_query = (repo_query
.where(Namespace.username == namespace))
tag_query = (Tag
.select()
@ -46,5 +64,4 @@ def list_packages_query(models_ref, namespace=None, media_type=None, search_quer
tag_query = tag_model.tag_is_alive(tag_query, Tag)
query = prefetch(repo_query, tag_query)
return query