1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-24 08:57:03 -05:00

Add tx around user creation

This commit is contained in:
Michael Jerger 2024-02-08 09:56:49 +01:00
parent edf7f61b83
commit e44be72251

View file

@ -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
}