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):
|
||||
""" 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
|
||||
|
|
Reference in a new issue