summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorMorlinest <morlinest@gmail.com>2017-10-17 17:20:22 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2017-10-17 23:20:22 +0800
commitccd3577970b64078eb156a736b1583833f80b4a3 (patch)
tree4abdd588adfc3f24992953ba2ad6fe0dcf614a6e /routers
parentaf4a094e5d1be13c0fe863c1cd6e56c62b1a9b79 (diff)
downloadgitea-ccd3577970b64078eb156a736b1583833f80b4a3.tar.gz
gitea-ccd3577970b64078eb156a736b1583833f80b4a3.zip
Fix repository search function (#2689)
* Fix and remove FIXME * Respect membership visibility * Fix/rewrite searchRepositoryByName function * Add unit tests * Add integration tests * Remove Searcher completely * Remove trailing space
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/repo.go29
-rw-r--r--routers/home.go1
2 files changed, 14 insertions, 16 deletions
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 20393102fc..30e1186c0a 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -34,17 +34,14 @@ func Search(ctx *context.APIContext) {
OwnerID: ctx.QueryInt64("uid"),
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
}
- if ctx.User != nil && ctx.User.ID == opts.OwnerID {
- opts.Searcher = ctx.User
- }
- // Check visibility.
- if ctx.IsSigned && opts.OwnerID > 0 {
- if ctx.User.ID == opts.OwnerID {
- opts.Private = true
- opts.Collaborate = true
+ if opts.OwnerID > 0 {
+ var repoOwner *models.User
+ if ctx.User != nil && ctx.User.ID == opts.OwnerID {
+ repoOwner = ctx.User
} else {
- u, err := models.GetUserByID(opts.OwnerID)
+ var err error
+ repoOwner, err = models.GetUserByID(opts.OwnerID)
if err != nil {
ctx.JSON(500, api.SearchError{
OK: false,
@@ -52,13 +49,15 @@ func Search(ctx *context.APIContext) {
})
return
}
- if u.IsOrganization() && u.IsOwnedBy(ctx.User.ID) {
- opts.Private = true
- }
+ }
- if !u.IsOrganization() {
- opts.Collaborate = true
- }
+ if !repoOwner.IsOrganization() {
+ opts.Collaborate = true
+ }
+
+ // Check visibility.
+ if ctx.IsSigned && (ctx.User.ID == repoOwner.ID || (repoOwner.IsOrganization() && repoOwner.IsOwnedBy(ctx.User.ID))) {
+ opts.Private = true
}
}
diff --git a/routers/home.go b/routers/home.go
index afcb3d35e5..cf957c1215 100644
--- a/routers/home.go
+++ b/routers/home.go
@@ -120,7 +120,6 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
Private: opts.Private,
Keyword: keyword,
OwnerID: opts.OwnerID,
- Searcher: ctx.User,
Collaborate: true,
AllPublic: true,
})