mirror of
https://github.com/go-gitea/gitea
synced 2025-07-16 07:18:37 +00:00
Backport #34643 by wxiaoguang Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -1146,8 +1146,8 @@ func ValidateCommitsWithEmails(ctx context.Context, oldCommits []*git.Commit) ([
|
||||
}
|
||||
|
||||
for _, c := range oldCommits {
|
||||
user, ok := emailUserMap[c.Author.Email]
|
||||
if !ok {
|
||||
user := emailUserMap.GetByEmail(c.Author.Email) // FIXME: why ValidateCommitsWithEmails uses "Author", but ParseCommitsWithSignature uses "Committer"?
|
||||
if user == nil {
|
||||
user = &User{
|
||||
Name: c.Author.Name,
|
||||
Email: c.Author.Email,
|
||||
@@ -1161,7 +1161,15 @@ func ValidateCommitsWithEmails(ctx context.Context, oldCommits []*git.Commit) ([
|
||||
return newCommits, nil
|
||||
}
|
||||
|
||||
func GetUsersByEmails(ctx context.Context, emails []string) (map[string]*User, error) {
|
||||
type EmailUserMap struct {
|
||||
m map[string]*User
|
||||
}
|
||||
|
||||
func (eum *EmailUserMap) GetByEmail(email string) *User {
|
||||
return eum.m[strings.ToLower(email)]
|
||||
}
|
||||
|
||||
func GetUsersByEmails(ctx context.Context, emails []string) (*EmailUserMap, error) {
|
||||
if len(emails) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -1171,7 +1179,7 @@ func GetUsersByEmails(ctx context.Context, emails []string) (map[string]*User, e
|
||||
for _, email := range emails {
|
||||
if strings.HasSuffix(email, "@"+setting.Service.NoReplyAddress) {
|
||||
username := strings.TrimSuffix(email, "@"+setting.Service.NoReplyAddress)
|
||||
needCheckUserNames.Add(username)
|
||||
needCheckUserNames.Add(strings.ToLower(username))
|
||||
} else {
|
||||
needCheckEmails.Add(strings.ToLower(email))
|
||||
}
|
||||
@@ -1198,8 +1206,7 @@ func GetUsersByEmails(ctx context.Context, emails []string) (map[string]*User, e
|
||||
for _, email := range emailAddresses {
|
||||
user := users[email.UID]
|
||||
if user != nil {
|
||||
results[user.Email] = user
|
||||
results[user.GetPlaceholderEmail()] = user
|
||||
results[email.LowerEmail] = user
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1209,10 +1216,9 @@ func GetUsersByEmails(ctx context.Context, emails []string) (map[string]*User, e
|
||||
return nil, err
|
||||
}
|
||||
for _, user := range users {
|
||||
results[user.Email] = user
|
||||
results[user.GetPlaceholderEmail()] = user
|
||||
results[strings.ToLower(user.GetPlaceholderEmail())] = user
|
||||
}
|
||||
return results, nil
|
||||
return &EmailUserMap{results}, nil
|
||||
}
|
||||
|
||||
// GetUserByEmail returns the user object by given e-mail if exists.
|
||||
|
Reference in New Issue
Block a user