]> source.dussan.org Git - gitea.git/commitdiff
Enable admin to search by email (#2888)
authorEthan Koenig <ethantkoenig@gmail.com>
Sun, 26 Nov 2017 08:40:38 +0000 (00:40 -0800)
committerLunny Xiao <xiaolunwen@gmail.com>
Sun, 26 Nov 2017 08:40:38 +0000 (16:40 +0800)
models/user.go
routers/admin/users.go

index 4dd2ad8d897ea2127d32b45b6466ef75f88afb44..f3a74f5e088764c872776e903d8048f10d4f9674 100644 (file)
@@ -1271,22 +1271,27 @@ func GetUser(user *User) (bool, error) {
 
 // SearchUserOptions contains the options for searching
 type SearchUserOptions struct {
-       Keyword  string
-       Type     UserType
-       OrderBy  string
-       Page     int
-       PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum
-       IsActive util.OptionalBool
+       Keyword       string
+       Type          UserType
+       OrderBy       string
+       Page          int
+       PageSize      int // Can be smaller than or equal to setting.UI.ExplorePagingNum
+       IsActive      util.OptionalBool
+       SearchByEmail bool // Search by email as well as username/full name
 }
 
 func (opts *SearchUserOptions) toConds() builder.Cond {
        var cond builder.Cond = builder.Eq{"type": opts.Type}
        if len(opts.Keyword) > 0 {
                lowerKeyword := strings.ToLower(opts.Keyword)
-               cond = cond.And(builder.Or(
+               keywordCond := builder.Or(
                        builder.Like{"lower_name", lowerKeyword},
                        builder.Like{"LOWER(full_name)", lowerKeyword},
-               ))
+               )
+               if opts.SearchByEmail {
+                       keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword})
+               }
+               cond = cond.And(keywordCond)
        }
 
        if !opts.IsActive.IsNone() {
index c22accc2029d0a4ca7482ae0b8532bacc448fcdd..1081f3092f933bf34578958cecaf07220f47d249 100644 (file)
@@ -31,8 +31,9 @@ func Users(ctx *context.Context) {
        ctx.Data["PageIsAdminUsers"] = true
 
        routers.RenderUserSearch(ctx, &models.SearchUserOptions{
-               Type:     models.UserTypeIndividual,
-               PageSize: setting.UI.Admin.UserPagingNum,
+               Type:          models.UserTypeIndividual,
+               PageSize:      setting.UI.Admin.UserPagingNum,
+               SearchByEmail: true,
        }, tplUsers)
 }