aboutsummaryrefslogtreecommitdiffstats
path: root/models/user/search.go
diff options
context:
space:
mode:
authoryp05327 <576951401@qq.com>2024-10-05 02:45:06 +0900
committerGitHub <noreply@github.com>2024-10-04 17:45:06 +0000
commit5d6d025c9b8d2abca9ec2bfdc795d1f0c1c6592d (patch)
treeae29b3ba5c7d498fa37308afc680c2fe68b15a91 /models/user/search.go
parent7e68bc88238104d2ee8b5a877fc1ad437f1778a4 (diff)
downloadgitea-5d6d025c9b8d2abca9ec2bfdc795d1f0c1c6592d.tar.gz
gitea-5d6d025c9b8d2abca9ec2bfdc795d1f0c1c6592d.zip
Add support for searching users by email (#30908)
Fix #30898 we have an option `SearchByEmail`, so enable it, then we can search user by email. Also added a test for it.
Diffstat (limited to 'models/user/search.go')
-rw-r--r--models/user/search.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/models/user/search.go b/models/user/search.go
index 45b051187e..382b6fac2b 100644
--- a/models/user/search.go
+++ b/models/user/search.go
@@ -65,7 +65,19 @@ func (opts *SearchUserOptions) toSearchQueryBase(ctx context.Context) *xorm.Sess
builder.Like{"LOWER(full_name)", lowerKeyword},
)
if opts.SearchByEmail {
- keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword})
+ var emailCond builder.Cond
+ emailCond = builder.Like{"LOWER(email)", lowerKeyword}
+ if opts.Actor == nil {
+ emailCond = emailCond.And(builder.Eq{"keep_email_private": false})
+ } else if !opts.Actor.IsAdmin {
+ emailCond = emailCond.And(
+ builder.Or(
+ builder.Eq{"keep_email_private": false},
+ builder.Eq{"id": opts.Actor.ID},
+ ),
+ )
+ }
+ keywordCond = keywordCond.Or(emailCond)
}
cond = cond.And(keywordCond)