diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-03-02 23:30:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-02 16:30:14 +0100 |
commit | dd712b77f7ccc0e3c3f1872c96dc120c20af0b08 (patch) | |
tree | 6b96634aa6fed42ee7d5ab2862a3f48b8ddafd64 | |
parent | a14b6f3aae196b2506e07f1dcfcd38d338b91e68 (diff) | |
download | gitea-dd712b77f7ccc0e3c3f1872c96dc120c20af0b08.tar.gz gitea-dd712b77f7ccc0e3c3f1872c96dc120c20af0b08.zip |
Refactor admin user filter query parameters (#18965)
Only pass `status_filter` on admin page
Use a more general method to pass query parameters, remove hard-coded keys
-rw-r--r-- | models/user/search.go | 3 | ||||
-rw-r--r-- | modules/context/pagination.go | 9 | ||||
-rw-r--r-- | routers/web/admin/users.go | 9 | ||||
-rw-r--r-- | routers/web/explore/user.go | 4 |
4 files changed, 14 insertions, 11 deletions
diff --git a/models/user/search.go b/models/user/search.go index fac180529f..a81cee1c22 100644 --- a/models/user/search.go +++ b/models/user/search.go @@ -20,6 +20,7 @@ import ( // SearchUserOptions contains the options for searching type SearchUserOptions struct { db.ListOptions + Keyword string Type UserType UID int64 @@ -33,6 +34,8 @@ type SearchUserOptions struct { IsRestricted util.OptionalBool IsTwoFactorEnabled util.OptionalBool IsProhibitLogin util.OptionalBool + + ExtraParamStrings map[string]string } func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session { diff --git a/modules/context/pagination.go b/modules/context/pagination.go index 140b676786..107cbf6186 100644 --- a/modules/context/pagination.go +++ b/modules/context/pagination.go @@ -55,12 +55,3 @@ func (p *Pagination) SetDefaultParams(ctx *Context) { p.AddParam(ctx, "tab", "TabName") p.AddParam(ctx, "t", "queryType") } - -// SetUserFilterParams sets common pagination params for user filtering, e.g. the admin userlist -func (p *Pagination) SetUserFilterParams(ctx *Context) { - p.AddParamString("status_filter[is_active]", ctx.FormString("status_filter[is_active]")) - p.AddParamString("status_filter[is_admin]", ctx.FormString("status_filter[is_admin]")) - p.AddParamString("status_filter[is_restricted]", ctx.FormString("status_filter[is_restricted]")) - p.AddParamString("status_filter[is_2fa_enabled]", ctx.FormString("status_filter[is_2fa_enabled]")) - p.AddParamString("status_filter[is_prohibit_login]", ctx.FormString("status_filter[is_prohibit_login]")) -} diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index 4358db89ba..1f304297c0 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -41,10 +41,16 @@ func Users(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminUsers"] = true + extraParamStrings := map[string]string{} statusFilterKeys := []string{"is_active", "is_admin", "is_restricted", "is_2fa_enabled", "is_prohibit_login"} statusFilterMap := map[string]string{} for _, filterKey := range statusFilterKeys { - statusFilterMap[filterKey] = ctx.FormString("status_filter[" + filterKey + "]") + paramKey := "status_filter[" + filterKey + "]" + paramVal := ctx.FormString(paramKey) + statusFilterMap[filterKey] = paramVal + if paramVal != "" { + extraParamStrings[paramKey] = paramVal + } } sortType := ctx.FormString("sort") @@ -68,6 +74,7 @@ func Users(ctx *context.Context) { IsRestricted: util.OptionalBoolParse(statusFilterMap["is_restricted"]), IsTwoFactorEnabled: util.OptionalBoolParse(statusFilterMap["is_2fa_enabled"]), IsProhibitLogin: util.OptionalBoolParse(statusFilterMap["is_prohibit_login"]), + ExtraParamStrings: extraParamStrings, }, tplUsers) } diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index c3aa89e8e6..98788f5433 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -82,7 +82,9 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5) pager.SetDefaultParams(ctx) - pager.SetUserFilterParams(ctx) + for paramKey, paramVal := range opts.ExtraParamStrings { + pager.AddParamString(paramKey, paramVal) + } ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplName) |