summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-08-24 22:01:03 +0800
committerGitHub <noreply@github.com>2017-08-24 22:01:03 +0800
commitf61a1d210c4ed6f616b4bee25e8231b5bc67a640 (patch)
tree340147776c7485d154b4ed9e7c0c604e34fdaa53 /models
parentda230a287264d38156e950a3149e43f65599e65b (diff)
downloadgitea-f61a1d210c4ed6f616b4bee25e8231b5bc67a640.tar.gz
gitea-f61a1d210c4ed6f616b4bee25e8231b5bc67a640.zip
Fix missing collabrative repos (#2367)
* fix missing collabrative repos * fix bug of collabrative * fix SQL quotes
Diffstat (limited to 'models')
-rw-r--r--models/repo_list.go50
1 files changed, 26 insertions, 24 deletions
diff --git a/models/repo_list.go b/models/repo_list.go
index 905408ae6b..15e6144d06 100644
--- a/models/repo_list.go
+++ b/models/repo_list.go
@@ -120,10 +120,12 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
opts.Page = 1
}
+ var starJoin bool
if opts.Starred && opts.OwnerID > 0 {
cond = builder.Eq{
"star.uid": opts.OwnerID,
}
+ starJoin = true
}
opts.Keyword = strings.ToLower(opts.Keyword)
@@ -133,34 +135,34 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
// Append conditions
if !opts.Starred && opts.OwnerID > 0 {
- cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
+ var searcherReposCond builder.Cond = builder.Eq{"owner_id": opts.OwnerID}
+ if opts.Searcher != nil {
+ var ownerIds []int64
+
+ ownerIds = append(ownerIds, opts.Searcher.ID)
+ err = opts.Searcher.GetOrganizations(true)
+
+ if err != nil {
+ return nil, 0, fmt.Errorf("Organization: %v", err)
+ }
+
+ for _, org := range opts.Searcher.Orgs {
+ ownerIds = append(ownerIds, org.ID)
+ }
+
+ searcherReposCond = searcherReposCond.Or(builder.In("owner_id", ownerIds))
+ if opts.Collaborate {
+ searcherReposCond = searcherReposCond.Or(builder.Expr("id IN (SELECT repo_id FROM `access` WHERE access.user_id = ? AND owner_id != ?)",
+ opts.Searcher.ID, opts.Searcher.ID))
+ }
+ }
+ cond = cond.And(searcherReposCond)
}
+
if !opts.Private {
cond = cond.And(builder.Eq{"is_private": false})
}
- if opts.Searcher != nil {
- var ownerIds []int64
-
- ownerIds = append(ownerIds, opts.Searcher.ID)
- err = opts.Searcher.GetOrganizations(true)
-
- if err != nil {
- return nil, 0, fmt.Errorf("Organization: %v", err)
- }
-
- for _, org := range opts.Searcher.Orgs {
- ownerIds = append(ownerIds, org.ID)
- }
-
- searcherReposCond := builder.In("owner_id", ownerIds)
- if opts.Collaborate {
- searcherReposCond = searcherReposCond.Or(builder.Expr(`id IN (SELECT repo_id FROM "access" WHERE access.user_id = ? AND owner_id != ?)`,
- opts.Searcher.ID, opts.Searcher.ID))
- }
- cond = cond.And(searcherReposCond)
- }
-
if len(opts.OrderBy) == 0 {
opts.OrderBy = "name ASC"
}
@@ -168,7 +170,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
sess := x.NewSession()
defer sess.Close()
- if opts.Starred && opts.OwnerID > 0 {
+ if starJoin {
count, err = sess.
Join("INNER", "star", "star.repo_id = repository.id").
Where(cond).