diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-11-26 00:40:38 -0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-11-26 16:40:38 +0800 |
commit | 716ac1214f14309bf82d664ff8bea90f4b7a40ee (patch) | |
tree | 1b8131488a28097a4e596ed47c07baca621fd850 /models/user.go | |
parent | 061c501d544002c48fee8b41b5640c0ea1583008 (diff) | |
download | gitea-716ac1214f14309bf82d664ff8bea90f4b7a40ee.tar.gz gitea-716ac1214f14309bf82d664ff8bea90f4b7a40ee.zip |
Enable admin to search by email (#2888)
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/models/user.go b/models/user.go index 4dd2ad8d89..f3a74f5e08 100644 --- a/models/user.go +++ b/models/user.go @@ -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() { |