* fix missing collabrative repos * fix bug of collabrative * fix SQL quotes
This commit is contained in:
parent
9df0eafa25
commit
0938a2dca3
3 changed files with 44 additions and 39 deletions
|
@ -120,10 +120,12 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
|
||||||
opts.Page = 1
|
opts.Page = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var starJoin bool
|
||||||
if opts.Starred && opts.OwnerID > 0 {
|
if opts.Starred && opts.OwnerID > 0 {
|
||||||
cond = builder.Eq{
|
cond = builder.Eq{
|
||||||
"star.uid": opts.OwnerID,
|
"star.uid": opts.OwnerID,
|
||||||
}
|
}
|
||||||
|
starJoin = true
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Keyword = strings.ToLower(opts.Keyword)
|
opts.Keyword = strings.ToLower(opts.Keyword)
|
||||||
|
@ -133,34 +135,34 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
|
||||||
|
|
||||||
// Append conditions
|
// Append conditions
|
||||||
if !opts.Starred && opts.OwnerID > 0 {
|
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 {
|
||||||
if !opts.Private {
|
var ownerIds []int64
|
||||||
cond = cond.And(builder.Eq{"is_private": false})
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Searcher != nil {
|
ownerIds = append(ownerIds, opts.Searcher.ID)
|
||||||
var ownerIds []int64
|
err = opts.Searcher.GetOrganizations(true)
|
||||||
|
|
||||||
ownerIds = append(ownerIds, opts.Searcher.ID)
|
if err != nil {
|
||||||
err = opts.Searcher.GetOrganizations(true)
|
return nil, 0, fmt.Errorf("Organization: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
for _, org := range opts.Searcher.Orgs {
|
||||||
return nil, 0, fmt.Errorf("Organization: %v", err)
|
ownerIds = append(ownerIds, org.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, org := range opts.Searcher.Orgs {
|
searcherReposCond = searcherReposCond.Or(builder.In("owner_id", ownerIds))
|
||||||
ownerIds = append(ownerIds, org.ID)
|
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))
|
||||||
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)
|
cond = cond.And(searcherReposCond)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !opts.Private {
|
||||||
|
cond = cond.And(builder.Eq{"is_private": false})
|
||||||
|
}
|
||||||
|
|
||||||
if len(opts.OrderBy) == 0 {
|
if len(opts.OrderBy) == 0 {
|
||||||
opts.OrderBy = "name ASC"
|
opts.OrderBy = "name ASC"
|
||||||
}
|
}
|
||||||
|
@ -168,7 +170,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
defer sess.Close()
|
defer sess.Close()
|
||||||
|
|
||||||
if opts.Starred && opts.OwnerID > 0 {
|
if starJoin {
|
||||||
count, err = sess.
|
count, err = sess.
|
||||||
Join("INNER", "star", "star.repo_id = repository.id").
|
Join("INNER", "star", "star.repo_id = repository.id").
|
||||||
Where(cond).
|
Where(cond).
|
||||||
|
|
|
@ -112,11 +112,12 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
||||||
keyword := strings.Trim(ctx.Query("q"), " ")
|
keyword := strings.Trim(ctx.Query("q"), " ")
|
||||||
if len(keyword) == 0 {
|
if len(keyword) == 0 {
|
||||||
repos, count, err = opts.Ranger(&models.SearchRepoOptions{
|
repos, count, err = opts.Ranger(&models.SearchRepoOptions{
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: opts.PageSize,
|
PageSize: opts.PageSize,
|
||||||
Searcher: ctx.User,
|
Searcher: ctx.User,
|
||||||
OrderBy: orderBy,
|
OrderBy: orderBy,
|
||||||
Private: opts.Private,
|
Private: opts.Private,
|
||||||
|
Collaborate: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "opts.Ranger", err)
|
ctx.Handle(500, "opts.Ranger", err)
|
||||||
|
@ -125,12 +126,13 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
||||||
} else {
|
} else {
|
||||||
if isKeywordValid(keyword) {
|
if isKeywordValid(keyword) {
|
||||||
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
|
||||||
Keyword: keyword,
|
Keyword: keyword,
|
||||||
OrderBy: orderBy,
|
OrderBy: orderBy,
|
||||||
Private: opts.Private,
|
Private: opts.Private,
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: opts.PageSize,
|
PageSize: opts.PageSize,
|
||||||
Searcher: ctx.User,
|
Searcher: ctx.User,
|
||||||
|
Collaborate: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "SearchRepositoryByName", err)
|
ctx.Handle(500, "SearchRepositoryByName", err)
|
||||||
|
|
|
@ -205,13 +205,14 @@ func Profile(ctx *context.Context) {
|
||||||
ctx.Data["Total"] = total
|
ctx.Data["Total"] = total
|
||||||
} else {
|
} else {
|
||||||
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
|
||||||
Keyword: keyword,
|
Keyword: keyword,
|
||||||
OwnerID: ctxUser.ID,
|
OwnerID: ctxUser.ID,
|
||||||
OrderBy: orderBy,
|
OrderBy: orderBy,
|
||||||
Private: showPrivate,
|
Private: showPrivate,
|
||||||
Page: page,
|
Page: page,
|
||||||
IsProfile: true,
|
IsProfile: true,
|
||||||
PageSize: setting.UI.User.RepoPagingNum,
|
PageSize: setting.UI.User.RepoPagingNum,
|
||||||
|
Collaborate: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "SearchRepositoryByName", err)
|
ctx.Handle(500, "SearchRepositoryByName", err)
|
||||||
|
|
Reference in a new issue