diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-21 23:41:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-21 23:41:00 +0800 |
commit | d710af6669654f27f02b69d7ef1ba563e7d58a90 (patch) | |
tree | 9727f468a570106293dc90beb70035180bbb7e8e /models/ssh_key_principals.go | |
parent | 0add627182388ac63fd04b94cdf912fb87fd0326 (diff) | |
download | gitea-d710af6669654f27f02b69d7ef1ba563e7d58a90.tar.gz gitea-d710af6669654f27f02b69d7ef1ba563e7d58a90.zip |
Remove NewSession method from db.Engine interface (#17577)
* Remove NewSession method from db.Engine interface
* Fix bug
* Some improvements
* Fix bug
* Fix test
* Use XXXBean instead of XXXExample
Diffstat (limited to 'models/ssh_key_principals.go')
-rw-r--r-- | models/ssh_key_principals.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/models/ssh_key_principals.go b/models/ssh_key_principals.go index 50456b72db..55d8e40397 100644 --- a/models/ssh_key_principals.go +++ b/models/ssh_key_principals.go @@ -25,11 +25,12 @@ import ( // AddPrincipalKey adds new principal to database and authorized_principals file. func AddPrincipalKey(ownerID int64, content string, loginSourceID int64) (*PublicKey, error) { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err := sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return nil, err } + defer committer.Close() + sess := db.GetEngine(ctx) // Principals cannot be duplicated. has, err := sess. @@ -53,11 +54,11 @@ func AddPrincipalKey(ownerID int64, content string, loginSourceID int64) (*Publi return nil, fmt.Errorf("addKey: %v", err) } - if err = sess.Commit(); err != nil { + if err = committer.Commit(); err != nil { return nil, err } - sess.Close() + committer.Close() return key, RewriteAllPrincipalKeys() } |