summaryrefslogtreecommitdiffstats
path: root/models/asymkey
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-11-13 04:18:50 +0800
committerGitHub <noreply@github.com>2022-11-12 21:18:50 +0100
commit34283a74e85278fed2c9b70d6f8749dc6a4001ca (patch)
treef8fa43399cb723d55efc34dacf7947faf0ed5acf /models/asymkey
parenta0a425a13ba587829a831aaecd8469d39d372111 (diff)
downloadgitea-34283a74e85278fed2c9b70d6f8749dc6a4001ca.tar.gz
gitea-34283a74e85278fed2c9b70d6f8749dc6a4001ca.zip
Allow detect whether it's in a database transaction for a context.Context (#21756)
Fix #19513 This PR introduce a new db method `InTransaction(context.Context)`, and also builtin check on `db.TxContext` and `db.WithTx`. There is also a new method `db.AutoTx` has been introduced but could be used by other PRs. `WithTx` will always open a new transaction, if a transaction exist in context, return an error. `AutoTx` will try to open a new transaction if no transaction exist in context. That means it will always enter a transaction if there is no error. Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models/asymkey')
-rw-r--r--models/asymkey/gpg_key.go2
-rw-r--r--models/asymkey/gpg_key_add.go2
-rw-r--r--models/asymkey/gpg_key_verify.go2
-rw-r--r--models/asymkey/ssh_key.go4
-rw-r--r--models/asymkey/ssh_key_deploy.go2
-rw-r--r--models/asymkey/ssh_key_principals.go2
-rw-r--r--models/asymkey/ssh_key_verify.go2
7 files changed, 8 insertions, 8 deletions
diff --git a/models/asymkey/gpg_key.go b/models/asymkey/gpg_key.go
index 83774533aa..30f5ecc949 100644
--- a/models/asymkey/gpg_key.go
+++ b/models/asymkey/gpg_key.go
@@ -234,7 +234,7 @@ func DeleteGPGKey(doer *user_model.User, id int64) (err error) {
return ErrGPGKeyAccessDenied{doer.ID, key.ID}
}
- ctx, committer, err := db.TxContext()
+ ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil {
return err
}
diff --git a/models/asymkey/gpg_key_add.go b/models/asymkey/gpg_key_add.go
index d01f2deb03..e7be19073a 100644
--- a/models/asymkey/gpg_key_add.go
+++ b/models/asymkey/gpg_key_add.go
@@ -73,7 +73,7 @@ func AddGPGKey(ownerID int64, content, token, signature string) ([]*GPGKey, erro
return nil, err
}
- ctx, committer, err := db.TxContext()
+ ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil {
return nil, err
}
diff --git a/models/asymkey/gpg_key_verify.go b/models/asymkey/gpg_key_verify.go
index 152765cc3a..4e9d04f576 100644
--- a/models/asymkey/gpg_key_verify.go
+++ b/models/asymkey/gpg_key_verify.go
@@ -31,7 +31,7 @@ import (
// VerifyGPGKey marks a GPG key as verified
func VerifyGPGKey(ownerID int64, keyID, token, signature string) (string, error) {
- ctx, committer, err := db.TxContext()
+ ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil {
return "", err
}
diff --git a/models/asymkey/ssh_key.go b/models/asymkey/ssh_key.go
index 7ed4ad6b3f..811f563c8d 100644
--- a/models/asymkey/ssh_key.go
+++ b/models/asymkey/ssh_key.go
@@ -100,7 +100,7 @@ func AddPublicKey(ownerID int64, name, content string, authSourceID int64) (*Pub
return nil, err
}
- ctx, committer, err := db.TxContext()
+ ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil {
return nil, err
}
@@ -321,7 +321,7 @@ func PublicKeyIsExternallyManaged(id int64) (bool, error) {
// deleteKeysMarkedForDeletion returns true if ssh keys needs update
func deleteKeysMarkedForDeletion(keys []string) (bool, error) {
// Start session
- ctx, committer, err := db.TxContext()
+ ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil {
return false, err
}
diff --git a/models/asymkey/ssh_key_deploy.go b/models/asymkey/ssh_key_deploy.go
index d5c981da47..601e5c32e5 100644
--- a/models/asymkey/ssh_key_deploy.go
+++ b/models/asymkey/ssh_key_deploy.go
@@ -126,7 +126,7 @@ func AddDeployKey(repoID int64, name, content string, readOnly bool) (*DeployKey
accessMode = perm.AccessModeWrite
}
- ctx, committer, err := db.TxContext()
+ ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil {
return nil, err
}
diff --git a/models/asymkey/ssh_key_principals.go b/models/asymkey/ssh_key_principals.go
index e0d407af35..7a769fd84d 100644
--- a/models/asymkey/ssh_key_principals.go
+++ b/models/asymkey/ssh_key_principals.go
@@ -26,7 +26,7 @@ import (
// AddPrincipalKey adds new principal to database and authorized_principals file.
func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*PublicKey, error) {
- ctx, committer, err := db.TxContext()
+ ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil {
return nil, err
}
diff --git a/models/asymkey/ssh_key_verify.go b/models/asymkey/ssh_key_verify.go
index 710cb3af00..6931df9e88 100644
--- a/models/asymkey/ssh_key_verify.go
+++ b/models/asymkey/ssh_key_verify.go
@@ -15,7 +15,7 @@ import (
// VerifySSHKey marks a SSH key as verified
func VerifySSHKey(ownerID int64, fingerprint, token, signature string) (string, error) {
- ctx, committer, err := db.TxContext()
+ ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil {
return "", err
}