mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-05 04:40:19 +01:00
Backport #36058 by @lunny Fix #20390 We should use `ReplacePrimaryEmailAddress` instead of `AdminAddOrSetPrimaryEmailAddress` when modify user's email from admin panel. And also we need a database transaction to keep deletion and insertion succeed at the same time. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
b276849cd8
commit
45cdc5d8fd
@ -409,7 +409,7 @@ func EditUserPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if form.Email != "" {
|
||||
if err := user_service.AdminAddOrSetPrimaryEmailAddress(ctx, u, form.Email); err != nil {
|
||||
if err := user_service.ReplacePrimaryEmailAddress(ctx, u, form.Email); err != nil {
|
||||
switch {
|
||||
case user_model.IsErrEmailCharIsNotSupported(err), user_model.IsErrEmailInvalid(err):
|
||||
ctx.Data["Err_Email"] = true
|
||||
|
||||
@ -77,6 +77,7 @@ func ReplacePrimaryEmailAddress(ctx context.Context, u *user_model.User, emailSt
|
||||
return err
|
||||
}
|
||||
|
||||
return db.WithTx(ctx, func(ctx context.Context) error {
|
||||
if !u.IsOrganization() {
|
||||
// Check if address exists already
|
||||
email, err := user_model.GetEmailAddressByEmail(ctx, emailStr)
|
||||
@ -100,13 +101,12 @@ func ReplacePrimaryEmailAddress(ctx context.Context, u *user_model.User, emailSt
|
||||
}
|
||||
|
||||
// Insert new primary address
|
||||
email = &user_model.EmailAddress{
|
||||
if _, err := user_model.InsertEmailAddress(ctx, &user_model.EmailAddress{
|
||||
UID: u.ID,
|
||||
Email: emailStr,
|
||||
IsActivated: true,
|
||||
IsPrimary: true,
|
||||
}
|
||||
if _, err := user_model.InsertEmailAddress(ctx, email); err != nil {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -114,6 +114,7 @@ func ReplacePrimaryEmailAddress(ctx context.Context, u *user_model.User, emailSt
|
||||
u.Email = emailStr
|
||||
|
||||
return user_model.UpdateUserCols(ctx, u, "email")
|
||||
})
|
||||
}
|
||||
|
||||
func AddEmailAddresses(ctx context.Context, u *user_model.User, emails []string) error {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user