Change appr search to return private repos when logged in
This commit is contained in:
parent
ea9707b969
commit
f8b19e798f
1 changed files with 34 additions and 17 deletions
|
@ -11,30 +11,48 @@ def list_packages_query(models_ref, namespace=None, media_type=None, search_quer
|
||||||
username=None):
|
username=None):
|
||||||
""" List and filter repository by search query. """
|
""" List and filter repository by search query. """
|
||||||
Tag = models_ref.Tag
|
Tag = models_ref.Tag
|
||||||
fields = [model.repository.SEARCH_FIELDS.name.name]
|
|
||||||
|
|
||||||
if search_query is not None:
|
if username and not search_query:
|
||||||
repositories = model.repository.get_app_search(search_query,
|
repositories = model.repository.get_visible_repositories(username,
|
||||||
username=username,
|
kind_filter='application',
|
||||||
search_fields=fields,
|
include_public=True,
|
||||||
limit=50)
|
namespace=namespace,
|
||||||
|
limit=50)
|
||||||
if not repositories:
|
if not repositories:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
repo_query = (Repository
|
repo_query = (Repository
|
||||||
.select(Repository, Namespace.username)
|
.select(Repository, Namespace.username)
|
||||||
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
|
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
|
||||||
.where(Repository.id << [repo.id for repo in repositories]))
|
.where(Repository.id << [repo.rid 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:
|
if namespace:
|
||||||
repo_query = (repo_query
|
repo_query = (repo_query
|
||||||
.where(Namespace.username == namespace))
|
.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
|
tag_query = (Tag
|
||||||
.select()
|
.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)
|
tag_query = tag_model.tag_is_alive(tag_query, Tag)
|
||||||
query = prefetch(repo_query, tag_query)
|
query = prefetch(repo_query, tag_query)
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
Reference in a new issue