summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-10-25 01:36:19 +0800
committerLauris BH <lauris@nix.lv>2017-10-24 20:36:19 +0300
commit6eeadb2082193f8e3dc5269dfc6da2daef7eb6a1 (patch)
treed28d3be3451194e98a5c01097347e7eebdb6393f /routers
parent03900303a9500b33b33ff03fd6dd325147a1117e (diff)
downloadgitea-6eeadb2082193f8e3dc5269dfc6da2daef7eb6a1.tar.gz
gitea-6eeadb2082193f8e3dc5269dfc6da2daef7eb6a1.zip
Hide unactive on explore users and some refactors (#2741)
* hide unactive on explore users and some refactors * fix test for removed Organizations * fix test for removed Organizations * fix imports * fix logic bug * refactor the toConds * Rename TestOrganizations to TestSearchUsers and add tests for users * fix other tests * fix other tests * fix watchers tests * fix comments and remove unused code
Diffstat (limited to 'routers')
-rw-r--r--routers/admin/orgs.go7
-rw-r--r--routers/admin/users.go7
-rw-r--r--routers/api/v1/user/user.go2
-rw-r--r--routers/home.go67
4 files changed, 23 insertions, 60 deletions
diff --git a/routers/admin/orgs.go b/routers/admin/orgs.go
index eeb9002bc2..c556d3fcf5 100644
--- a/routers/admin/orgs.go
+++ b/routers/admin/orgs.go
@@ -22,11 +22,8 @@ func Organizations(ctx *context.Context) {
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminOrganizations"] = true
- routers.RenderUserSearch(ctx, &routers.UserSearchOptions{
+ routers.RenderUserSearch(ctx, &models.SearchUserOptions{
Type: models.UserTypeOrganization,
- Counter: models.CountOrganizations,
- Ranger: models.Organizations,
PageSize: setting.UI.Admin.OrgPagingNum,
- TplName: tplOrgs,
- })
+ }, tplOrgs)
}
diff --git a/routers/admin/users.go b/routers/admin/users.go
index d480029143..c22accc202 100644
--- a/routers/admin/users.go
+++ b/routers/admin/users.go
@@ -30,13 +30,10 @@ func Users(ctx *context.Context) {
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true
- routers.RenderUserSearch(ctx, &routers.UserSearchOptions{
+ routers.RenderUserSearch(ctx, &models.SearchUserOptions{
Type: models.UserTypeIndividual,
- Counter: models.CountUsers,
- Ranger: models.Users,
PageSize: setting.UI.Admin.UserPagingNum,
- TplName: tplUsers,
- })
+ }, tplUsers)
}
// NewUser render adding a new user page
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go
index 0ab6eaf44c..5a59fd7ca9 100644
--- a/routers/api/v1/user/user.go
+++ b/routers/api/v1/user/user.go
@@ -35,7 +35,7 @@ func Search(ctx *context.APIContext) {
opts.PageSize = 10
}
- users, _, err := models.SearchUserByName(opts)
+ users, _, err := models.SearchUsers(opts)
if err != nil {
ctx.JSON(500, map[string]interface{}{
"ok": false,
diff --git a/routers/home.go b/routers/home.go
index 768eb22077..d653d1e843 100644
--- a/routers/home.go
+++ b/routers/home.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/user"
"github.com/Unknwon/paginater"
@@ -147,20 +148,11 @@ func ExploreRepos(ctx *context.Context) {
})
}
-// UserSearchOptions options when render search user page
-type UserSearchOptions struct {
- Type models.UserType
- Counter func() int64
- Ranger func(*models.SearchUserOptions) ([]*models.User, error)
- PageSize int
- TplName base.TplName
-}
-
// RenderUserSearch render user search page
-func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
- page := ctx.QueryInt("page")
- if page <= 1 {
- page = 1
+func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplName base.TplName) {
+ opts.Page = ctx.QueryInt("page")
+ if opts.Page <= 1 {
+ opts.Page = 1
}
var (
@@ -189,40 +181,22 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
orderBy = "name ASC"
}
- keyword := strings.Trim(ctx.Query("q"), " ")
- if len(keyword) == 0 {
- users, err = opts.Ranger(&models.SearchUserOptions{
- OrderBy: orderBy,
- Page: page,
- PageSize: opts.PageSize,
- })
+ opts.Keyword = strings.Trim(ctx.Query("q"), " ")
+ opts.OrderBy = orderBy
+ if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) {
+ users, count, err = models.SearchUsers(opts)
if err != nil {
- ctx.Handle(500, "opts.Ranger", err)
+ ctx.Handle(500, "SearchUsers", err)
return
}
- count = opts.Counter()
- } else {
- if isKeywordValid(keyword) {
- users, count, err = models.SearchUserByName(&models.SearchUserOptions{
- Keyword: keyword,
- Type: opts.Type,
- OrderBy: orderBy,
- Page: page,
- PageSize: opts.PageSize,
- })
- if err != nil {
- ctx.Handle(500, "SearchUserByName", err)
- return
- }
- }
}
- ctx.Data["Keyword"] = keyword
+ ctx.Data["Keyword"] = opts.Keyword
ctx.Data["Total"] = count
- ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5)
+ ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, opts.Page, 5)
ctx.Data["Users"] = users
ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail
- ctx.HTML(200, opts.TplName)
+ ctx.HTML(200, tplName)
}
// ExploreUsers render explore users page
@@ -231,13 +205,11 @@ func ExploreUsers(ctx *context.Context) {
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreUsers"] = true
- RenderUserSearch(ctx, &UserSearchOptions{
+ RenderUserSearch(ctx, &models.SearchUserOptions{
Type: models.UserTypeIndividual,
- Counter: models.CountUsers,
- Ranger: models.Users,
PageSize: setting.UI.ExplorePagingNum,
- TplName: tplExploreUsers,
- })
+ IsActive: util.OptionalBoolTrue,
+ }, tplExploreUsers)
}
// ExploreOrganizations render explore organizations page
@@ -246,13 +218,10 @@ func ExploreOrganizations(ctx *context.Context) {
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreOrganizations"] = true
- RenderUserSearch(ctx, &UserSearchOptions{
+ RenderUserSearch(ctx, &models.SearchUserOptions{
Type: models.UserTypeOrganization,
- Counter: models.CountOrganizations,
- Ranger: models.Organizations,
PageSize: setting.UI.ExplorePagingNum,
- TplName: tplExploreOrganizations,
- })
+ }, tplExploreOrganizations)
}
// NotFound render 404 page