From e44be722513aaa1695b97b0b88898959abfbd888 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Thu, 8 Feb 2024 09:56:49 +0100 Subject: [PATCH] Add tx around user creation --- models/user/user_service.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/models/user/user_service.go b/models/user/user_service.go index 01df922806..44814ac2ff 100644 --- a/models/user/user_service.go +++ b/models/user/user_service.go @@ -9,6 +9,7 @@ import ( "net/url" "strings" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/forgefed" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -57,7 +58,13 @@ func CreateFederatedUserFromAP(ctx context.Context, person forgefed.ForgePerson, IsRestricted: util.OptionalBoolFalse, } - // TODO: Transaction around + // Begin transaction + ctx, committer, err := db.TxContext((ctx)) + if err != nil { + return nil, nil, err + } + defer committer.Close() + if err := CreateUser(ctx, &user, overwrite); err != nil { return nil, nil, err } @@ -72,5 +79,8 @@ func CreateFederatedUserFromAP(ctx context.Context, person forgefed.ForgePerson, return nil, nil, err } + // Commit transaction + committer.Commit() + return &user, &federatedUser, nil }