From dbb331fde0bb1b1358f0b28bc2d0b360aceb6737 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 28 Oct 2024 17:50:26 +0100 Subject: [PATCH] Delete from email_address table --- models/user/email_address.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/models/user/email_address.go b/models/user/email_address.go index b3078e4c6c..e8c81a730c 100644 --- a/models/user/email_address.go +++ b/models/user/email_address.go @@ -214,8 +214,24 @@ func DeletePrimaryEmailAddressOfUser(ctx context.Context, uid int64) error { return fmt.Errorf("%s is not a organization", user.Name) } + ctx, committer, err := db.TxContext(ctx) + if err != nil { + return err + } + defer committer.Close() + + _, err = db.GetEngine(ctx).Exec("DELETE FROM email_address WHERE uid = ? AND is_primary = true", uid) + if err != nil { + return err + } + user.Email = "" - return UpdateUserCols(ctx, user, "email") + err = UpdateUserCols(ctx, user, "email") + if err != nil { + return err + } + + return committer.Commit() } // GetEmailAddresses returns all email addresses belongs to given user.