From 149d62a648d5b852e43125834ed9b1cb6b49bdc0 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 15 Mar 2016 14:23:12 -0400 Subject: [PATCH] #13 fix admin can't search private repos - update glide info --- README.md | 2 +- glide.lock | 25 ++++++++++---- glide.yaml | 3 ++ gogs.go | 2 +- routers/admin/orgs.go | 10 ++++-- routers/admin/repos.go | 10 ++++-- routers/admin/users.go | 10 ++++-- routers/home.go | 76 ++++++++++++++++++++++++++++-------------- templates/.VERSION | 2 +- 9 files changed, 99 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 95302cea5..940312549 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) -##### Current version: 0.9.9 +##### Current version: 0.9.10 | Web | UI | Preview | |:-------------:|:-------:|:-------:| diff --git a/glide.lock b/glide.lock index d065409ca..e7c7c5c91 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 81254bce31966708f508a845836851efb77d96d8c522e745e67d0daeffd76cc5 -updated: 2016-03-12T14:42:55.945562115-05:00 +hash: f2fa73b9a379e1fa12f2b48fb0b9942a545b4518a2d71cbd956ee81093347773 +updated: 2016-03-15T13:58:01.074601588-04:00 imports: - name: github.com/bradfitz/gomemcache version: fb1f79c6b65acda83063cbc69f6bba1522558bfc @@ -46,8 +46,10 @@ imports: version: 788ec59749df076b98e208909b44fdef02779deb - name: github.com/issue9/identicon version: f8c0d2ce04db79c663b1da33d3a9f62be753ee88 +- name: github.com/kardianos/minwinsvc + version: cad6b2b879b0970e4245a20ebf1a81a756e2bb70 - name: github.com/klauspost/compress - version: 2d3d403f37d2e70b722590bc286076a17422e1f2 + version: 006acde2c5d283d2f8b8aa03d8f0cd2891c680cf subpackages: - gzip - flate @@ -59,10 +61,14 @@ imports: version: 165a3529e799da61ab10faed1fabff3662d6193f subpackages: - oid +- name: github.com/mattn/go-sqlite3 + version: 76e335f60bbcee20755df9864f0153af1a80ad2d - name: github.com/mcuadros/go-version version: d52711f8d6bea8dc01efafdb68ad95a4e2606630 - name: github.com/microcosm-cc/bluemonday version: 4ac6f27528d0a3f2a59e0b0a6f6b3ff0bb89fe20 +- name: github.com/msteinert/pam + version: 02ccfbfaf0cc627aa3aec8ef7ed5cfeec5b43f63 - name: github.com/nfnt/resize version: 4d93a29130b1b6aba503e2aa8b50f516213ea80e - name: github.com/russross/blackfriday @@ -86,18 +92,23 @@ imports: - name: github.com/Unknwon/paginater version: 7748a72e01415173a27d79866b984328e7b0c12b - name: golang.org/x/crypto - version: de93d05161db39bcbd84d3da2e54c4a18f37f0b1 + version: 6025851c7c2bf210daf74d22300c699b16541847 subpackages: - ssh - curve25519 - name: golang.org/x/net - version: e7da8edaa52631091740908acaf2c2d4c9b3ce90 + version: 35b06af0720201bc2f326773a80767387544f8c4 subpackages: - html - html/charset - html/atom +- name: golang.org/x/sys + version: 9d4e42a20653790449273b3c85e67d6d8bae6e2e + subpackages: + - windows/svc + - windows - name: golang.org/x/text - version: a71fd10341b064c10f4a81ceac72bcf70f26ea34 + version: c20b6f20120f3c96689c10ffa47eee07776b9fe1 subpackages: - transform - encoding @@ -121,7 +132,7 @@ imports: - name: gopkg.in/bufio.v1 version: 567b2bfa514e796916c4747494d6ff5132a1dfce - name: gopkg.in/gomail.v2 - version: 5ceb8e65415e45e1262fb385212b8193b55c0f99 + version: afff51fd8cbc246672451a1b0b67e8f4a507bad8 - name: gopkg.in/ini.v1 version: 776aa739ce9373377cd16f526cdf06cb4c89b40f - name: gopkg.in/ldap.v2 diff --git a/glide.yaml b/glide.yaml index b0caa244e..807f14707 100644 --- a/glide.yaml +++ b/glide.yaml @@ -28,9 +28,12 @@ import: - package: github.com/gogits/git-module - package: github.com/gogits/go-gogs-client - package: github.com/issue9/identicon +- package: github.com/kardianos/minwinsvc - package: github.com/lib/pq +- package: github.com/mattn/go-sqlite3 - package: github.com/mcuadros/go-version - package: github.com/microcosm-cc/bluemonday +- package: github.com/msteinert/pam - package: github.com/nfnt/resize - package: github.com/russross/blackfriday - package: github.com/satori/go.uuid diff --git a/gogs.go b/gogs.go index 27d821f72..1906c176a 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.9.9.0313" +const APP_VER = "0.9.10.0315" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/routers/admin/orgs.go b/routers/admin/orgs.go index 395243a5f..28e9d79f0 100644 --- a/routers/admin/orgs.go +++ b/routers/admin/orgs.go @@ -21,6 +21,12 @@ func Organizations(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminOrganizations"] = true - routers.RenderUserSearch(ctx, models.USER_TYPE_ORGANIZATION, models.CountOrganizations, models.Organizations, - setting.AdminOrgPagingNum, "id ASC", ORGS) + routers.RenderUserSearch(ctx, &routers.UserSearchOptions{ + Type: models.USER_TYPE_ORGANIZATION, + Counter: models.CountOrganizations, + Ranger: models.Organizations, + PageSize: setting.AdminOrgPagingNum, + OrderBy: "id ASC", + TplName: ORGS, + }) } diff --git a/routers/admin/repos.go b/routers/admin/repos.go index e78941ab4..8b5caa8d7 100644 --- a/routers/admin/repos.go +++ b/routers/admin/repos.go @@ -22,8 +22,14 @@ func Repos(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminRepositories"] = true - routers.RenderRepoSearch(ctx, models.CountRepositories, models.Repositories, - setting.AdminRepoPagingNum, "id ASC", REPOS) + routers.RenderRepoSearch(ctx, &routers.RepoSearchOptions{ + Counter: models.CountRepositories, + Ranger: models.Repositories, + Private: true, + PageSize: setting.AdminRepoPagingNum, + OrderBy: "id ASC", + TplName: REPOS, + }) } func DeleteRepo(ctx *context.Context) { diff --git a/routers/admin/users.go b/routers/admin/users.go index 00028a2fd..76fbcd168 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -30,8 +30,14 @@ func Users(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminUsers"] = true - routers.RenderUserSearch(ctx, models.USER_TYPE_INDIVIDUAL, models.CountUsers, models.Users, - setting.AdminUserPagingNum, "id ASC", USERS) + routers.RenderUserSearch(ctx, &routers.UserSearchOptions{ + Type: models.USER_TYPE_INDIVIDUAL, + Counter: models.CountUsers, + Ranger: models.Users, + PageSize: setting.AdminUserPagingNum, + OrderBy: "id ASC", + TplName: USERS, + }) } func NewUser(ctx *context.Context) { diff --git a/routers/home.go b/routers/home.go index 0836dd506..16967521d 100644 --- a/routers/home.go +++ b/routers/home.go @@ -44,9 +44,16 @@ func Home(ctx *context.Context) { ctx.HTML(200, HOME) } -func RenderRepoSearch(ctx *context.Context, - counter func() int64, ranger func(int, int) ([]*models.Repository, error), - pagingNum int, orderBy string, tplName base.TplName) { +type RepoSearchOptions struct { + Counter func() int64 + Ranger func(int, int) ([]*models.Repository, error) + Private bool + PageSize int + OrderBy string + TplName base.TplName +} + +func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { page := ctx.QueryInt("page") if page <= 1 { page = 1 @@ -60,18 +67,19 @@ func RenderRepoSearch(ctx *context.Context, keyword := ctx.Query("q") if len(keyword) == 0 { - repos, err = ranger(page, pagingNum) + repos, err = opts.Ranger(page, opts.PageSize) if err != nil { - ctx.Handle(500, "ranger", err) + ctx.Handle(500, "opts.Ranger", err) return } - count = counter() + count = opts.Counter() } else { repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ Keyword: keyword, - OrderBy: orderBy, + OrderBy: opts.OrderBy, + Private: opts.Private, Page: page, - PageSize: pagingNum, + PageSize: opts.PageSize, }) if err != nil { ctx.Handle(500, "SearchRepositoryByName", err) @@ -80,7 +88,7 @@ func RenderRepoSearch(ctx *context.Context, } ctx.Data["Keyword"] = keyword ctx.Data["Total"] = count - ctx.Data["Page"] = paginater.New(int(count), pagingNum, page, 5) + ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) for _, repo := range repos { if err = repo.GetOwner(); err != nil { @@ -90,7 +98,7 @@ func RenderRepoSearch(ctx *context.Context, } ctx.Data["Repos"] = repos - ctx.HTML(200, tplName) + ctx.HTML(200, opts.TplName) } func ExploreRepos(ctx *context.Context) { @@ -98,13 +106,25 @@ func ExploreRepos(ctx *context.Context) { ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExploreRepositories"] = true - RenderRepoSearch(ctx, models.CountPublicRepositories, models.GetRecentUpdatedRepositories, - setting.ExplorePagingNum, "updated_unix DESC", EXPLORE_REPOS) + RenderRepoSearch(ctx, &RepoSearchOptions{ + Counter: models.CountPublicRepositories, + Ranger: models.GetRecentUpdatedRepositories, + PageSize: setting.ExplorePagingNum, + OrderBy: "updated_unix DESC", + TplName: EXPLORE_REPOS, + }) +} + +type UserSearchOptions struct { + Type models.UserType + Counter func() int64 + Ranger func(int, int) ([]*models.User, error) + PageSize int + OrderBy string + TplName base.TplName } -func RenderUserSearch(ctx *context.Context, userType models.UserType, - counter func() int64, ranger func(int, int) ([]*models.User, error), - pagingNum int, orderBy string, tplName base.TplName) { +func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { page := ctx.QueryInt("page") if page <= 1 { page = 1 @@ -118,19 +138,19 @@ func RenderUserSearch(ctx *context.Context, userType models.UserType, keyword := ctx.Query("q") if len(keyword) == 0 { - users, err = ranger(page, pagingNum) + users, err = opts.Ranger(page, opts.PageSize) if err != nil { - ctx.Handle(500, "ranger", err) + ctx.Handle(500, "opts.Ranger", err) return } - count = counter() + count = opts.Counter() } else { users, count, err = models.SearchUserByName(&models.SearchUserOptions{ Keyword: keyword, - Type: userType, - OrderBy: orderBy, + Type: opts.Type, + OrderBy: opts.OrderBy, Page: page, - PageSize: pagingNum, + PageSize: opts.PageSize, }) if err != nil { ctx.Handle(500, "SearchUserByName", err) @@ -139,10 +159,10 @@ func RenderUserSearch(ctx *context.Context, userType models.UserType, } ctx.Data["Keyword"] = keyword ctx.Data["Total"] = count - ctx.Data["Page"] = paginater.New(int(count), pagingNum, page, 5) + ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) ctx.Data["Users"] = users - ctx.HTML(200, tplName) + ctx.HTML(200, opts.TplName) } func ExploreUsers(ctx *context.Context) { @@ -150,8 +170,14 @@ func ExploreUsers(ctx *context.Context) { ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExploreUsers"] = true - RenderUserSearch(ctx, models.USER_TYPE_INDIVIDUAL, models.CountUsers, models.Users, - setting.ExplorePagingNum, "updated_unix DESC", EXPLORE_USERS) + RenderUserSearch(ctx, &UserSearchOptions{ + Type: models.USER_TYPE_INDIVIDUAL, + Counter: models.CountUsers, + Ranger: models.Users, + PageSize: setting.ExplorePagingNum, + OrderBy: "updated_unix DESC", + TplName: EXPLORE_USERS, + }) } func NotFound(ctx *context.Context) { diff --git a/templates/.VERSION b/templates/.VERSION index 9989d2631..466fc8e07 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.9.9.0313 \ No newline at end of file +0.9.10.0315 \ No newline at end of file