mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	Enable admin to search by email (#2888)
This commit is contained in:
		@@ -1277,16 +1277,21 @@ type SearchUserOptions struct {
 | 
				
			|||||||
	Page          int
 | 
						Page          int
 | 
				
			||||||
	PageSize      int // Can be smaller than or equal to setting.UI.ExplorePagingNum
 | 
						PageSize      int // Can be smaller than or equal to setting.UI.ExplorePagingNum
 | 
				
			||||||
	IsActive      util.OptionalBool
 | 
						IsActive      util.OptionalBool
 | 
				
			||||||
 | 
						SearchByEmail bool // Search by email as well as username/full name
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (opts *SearchUserOptions) toConds() builder.Cond {
 | 
					func (opts *SearchUserOptions) toConds() builder.Cond {
 | 
				
			||||||
	var cond builder.Cond = builder.Eq{"type": opts.Type}
 | 
						var cond builder.Cond = builder.Eq{"type": opts.Type}
 | 
				
			||||||
	if len(opts.Keyword) > 0 {
 | 
						if len(opts.Keyword) > 0 {
 | 
				
			||||||
		lowerKeyword := strings.ToLower(opts.Keyword)
 | 
							lowerKeyword := strings.ToLower(opts.Keyword)
 | 
				
			||||||
		cond = cond.And(builder.Or(
 | 
							keywordCond := builder.Or(
 | 
				
			||||||
			builder.Like{"lower_name", lowerKeyword},
 | 
								builder.Like{"lower_name", lowerKeyword},
 | 
				
			||||||
			builder.Like{"LOWER(full_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() {
 | 
						if !opts.IsActive.IsNone() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,6 +33,7 @@ func Users(ctx *context.Context) {
 | 
				
			|||||||
	routers.RenderUserSearch(ctx, &models.SearchUserOptions{
 | 
						routers.RenderUserSearch(ctx, &models.SearchUserOptions{
 | 
				
			||||||
		Type:          models.UserTypeIndividual,
 | 
							Type:          models.UserTypeIndividual,
 | 
				
			||||||
		PageSize:      setting.UI.Admin.UserPagingNum,
 | 
							PageSize:      setting.UI.Admin.UserPagingNum,
 | 
				
			||||||
 | 
							SearchByEmail: true,
 | 
				
			||||||
	}, tplUsers)
 | 
						}, tplUsers)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user