Skip to content

Commit 716ac12

Browse files
ethantkoeniglunny
authored andcommitted
Enable admin to search by email (#2888)
1 parent 061c501 commit 716ac12

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

models/user.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,22 +1271,27 @@ func GetUser(user *User) (bool, error) {
12711271

12721272
// SearchUserOptions contains the options for searching
12731273
type SearchUserOptions struct {
1274-
Keyword string
1275-
Type UserType
1276-
OrderBy string
1277-
Page int
1278-
PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum
1279-
IsActive util.OptionalBool
1274+
Keyword string
1275+
Type UserType
1276+
OrderBy string
1277+
Page int
1278+
PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum
1279+
IsActive util.OptionalBool
1280+
SearchByEmail bool // Search by email as well as username/full name
12801281
}
12811282

12821283
func (opts *SearchUserOptions) toConds() builder.Cond {
12831284
var cond builder.Cond = builder.Eq{"type": opts.Type}
12841285
if len(opts.Keyword) > 0 {
12851286
lowerKeyword := strings.ToLower(opts.Keyword)
1286-
cond = cond.And(builder.Or(
1287+
keywordCond := builder.Or(
12871288
builder.Like{"lower_name", lowerKeyword},
12881289
builder.Like{"LOWER(full_name)", lowerKeyword},
1289-
))
1290+
)
1291+
if opts.SearchByEmail {
1292+
keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword})
1293+
}
1294+
cond = cond.And(keywordCond)
12901295
}
12911296

12921297
if !opts.IsActive.IsNone() {

routers/admin/users.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ func Users(ctx *context.Context) {
3131
ctx.Data["PageIsAdminUsers"] = true
3232

3333
routers.RenderUserSearch(ctx, &models.SearchUserOptions{
34-
Type: models.UserTypeIndividual,
35-
PageSize: setting.UI.Admin.UserPagingNum,
34+
Type: models.UserTypeIndividual,
35+
PageSize: setting.UI.Admin.UserPagingNum,
36+
SearchByEmail: true,
3637
}, tplUsers)
3738
}
3839

0 commit comments

Comments
 (0)