Browse Source

Enable admin to search by email (#2888)

tags/v1.4.0-rc1
Ethan Koenig Lunny Xiao 8 years ago
parent
commit
b14199bf9c
2 changed files with 16 additions and 10 deletions
  1. +13
    -8
      models/user.go
  2. +3
    -2
      routers/admin/users.go

+ 13
- 8
models/user.go View 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() {


+ 3
- 2
routers/admin/users.go View 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)
}



Loading…
Cancel
Save