Fix the repo search to include repos that you get through a team and repos for which you have admin on the org.
This commit is contained in:
parent
52e82cfb10
commit
d524559bce
3 changed files with 51 additions and 28 deletions
|
@ -405,34 +405,59 @@ def get_visible_repositories(username=None, include_public=True, limit=None,
|
|||
if not username and not include_public:
|
||||
return []
|
||||
|
||||
query = Repository.select().distinct()
|
||||
|
||||
if namespace:
|
||||
query = query.where(Repository.namespace == namespace)
|
||||
|
||||
query = query.join(Visibility)
|
||||
or_clauses = []
|
||||
if include_public:
|
||||
or_clauses.append((Visibility.name == 'public'))
|
||||
|
||||
query = (Repository
|
||||
.select(Repository, Visibility)
|
||||
.distinct()
|
||||
.join(Visibility)
|
||||
.switch(Repository)
|
||||
.join(RepositoryPermission, JOIN_LEFT_OUTER))
|
||||
|
||||
where_clause = None
|
||||
admin_query = None
|
||||
if username:
|
||||
with_perms = query.switch(Repository).join(RepositoryPermission,
|
||||
JOIN_LEFT_OUTER)
|
||||
query = with_perms.join(User)
|
||||
or_clauses.append(User.username == username)
|
||||
UserThroughTeam = User.alias()
|
||||
Org = User.alias()
|
||||
AdminTeam = Team.alias()
|
||||
AdminTeamMember = TeamMember.alias()
|
||||
AdminUser = User.alias()
|
||||
|
||||
if sort:
|
||||
with_images = query.switch(Repository).join(Image, JOIN_LEFT_OUTER)
|
||||
query = with_images.order_by(Image.created.desc())
|
||||
query = (query
|
||||
.join(User, JOIN_LEFT_OUTER)
|
||||
.switch(RepositoryPermission)
|
||||
.join(Team, JOIN_LEFT_OUTER)
|
||||
.join(TeamMember, JOIN_LEFT_OUTER)
|
||||
.join(UserThroughTeam, JOIN_LEFT_OUTER, on=(UserThroughTeam.id ==
|
||||
TeamMember.user))
|
||||
.switch(Repository)
|
||||
.join(Org, JOIN_LEFT_OUTER, on=(Org.username == Repository.namespace))
|
||||
.join(AdminTeam, JOIN_LEFT_OUTER, on=(Org.id ==
|
||||
AdminTeam.organization))
|
||||
.join(TeamRole, JOIN_LEFT_OUTER)
|
||||
.switch(AdminTeam)
|
||||
.join(AdminTeamMember, JOIN_LEFT_OUTER, on=(AdminTeam.id ==
|
||||
AdminTeamMember.team))
|
||||
.join(AdminUser, JOIN_LEFT_OUTER, on=(AdminTeamMember.user ==
|
||||
AdminUser.id)))
|
||||
|
||||
if (or_clauses):
|
||||
query = query.where(reduce(operator.or_, or_clauses))
|
||||
where_clause = ((User.username == username) |
|
||||
(UserThroughTeam.username == username) |
|
||||
((AdminUser.username == username) &
|
||||
(TeamRole.name == 'admin')))
|
||||
|
||||
if namespace:
|
||||
where_clause = where_clause & (Repository.namespace == namespace)
|
||||
|
||||
if include_public:
|
||||
new_clause = (Visibility.name == 'public')
|
||||
if where_clause:
|
||||
where_clause = where_clause | new_clause
|
||||
else:
|
||||
where_clause = new_clause
|
||||
|
||||
if limit:
|
||||
query = query.limit(limit)
|
||||
query.limit(limit)
|
||||
|
||||
return query
|
||||
return query.where(where_clause)
|
||||
|
||||
|
||||
def get_matching_repositories(repo_term, username=None):
|
||||
|
|
|
@ -584,13 +584,11 @@ def match_repos_api():
|
|||
@app.route('/api/repository/', methods=['GET'])
|
||||
def list_repos_api():
|
||||
def repo_view(repo_obj):
|
||||
is_public = model.repository_is_public(repo_obj.namespace, repo_obj.name)
|
||||
|
||||
return {
|
||||
'namespace': repo_obj.namespace,
|
||||
'name': repo_obj.name,
|
||||
'description': repo_obj.description,
|
||||
'is_public': is_public
|
||||
'is_public': repo_obj.visibility.name == 'public',
|
||||
}
|
||||
|
||||
limit = request.args.get('limit', None)
|
||||
|
@ -614,7 +612,8 @@ def list_repos_api():
|
|||
|
||||
repo_query = model.get_visible_repositories(username, limit=limit,
|
||||
include_public=include_public,
|
||||
sort=sort, namespace=namespace_filter)
|
||||
sort=sort,
|
||||
namespace=namespace_filter)
|
||||
repos = [repo_view(repo) for repo in repo_query]
|
||||
response = {
|
||||
'repositories': repos
|
||||
|
|
|
@ -145,8 +145,7 @@ function RepoListCtrl($scope, Restangular, UserService) {
|
|||
|
||||
// Load the list of repositories.
|
||||
var params = {
|
||||
'limit': 10,
|
||||
'public': true,
|
||||
'public': false,
|
||||
'sort': true,
|
||||
'namespace': namespace
|
||||
};
|
||||
|
@ -236,7 +235,7 @@ function LandingCtrl($scope, $timeout, $location, Restangular, UserService, KeyS
|
|||
// Load the list of repositories.
|
||||
var params = {
|
||||
'limit': 4,
|
||||
'public': true,
|
||||
'public': false,
|
||||
'sort': true,
|
||||
'namespace': namespace
|
||||
};
|
||||
|
|
Reference in a new issue