aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo_collaboration.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-21 23:41:00 +0800
committerGitHub <noreply@github.com>2021-11-21 23:41:00 +0800
commitd710af6669654f27f02b69d7ef1ba563e7d58a90 (patch)
tree9727f468a570106293dc90beb70035180bbb7e8e /models/repo_collaboration.go
parent0add627182388ac63fd04b94cdf912fb87fd0326 (diff)
downloadgitea-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/repo_collaboration.go')
-rw-r--r--models/repo_collaboration.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/models/repo_collaboration.go b/models/repo_collaboration.go
index dd362406cf..6502d7959c 100644
--- a/models/repo_collaboration.go
+++ b/models/repo_collaboration.go
@@ -53,17 +53,17 @@ func (repo *Repository) addCollaborator(e db.Engine, u *User) error {
// AddCollaborator adds new collaboration to a repository with default access mode.
func (repo *Repository) AddCollaborator(u *User) error {
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err := sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return err
}
+ defer committer.Close()
- if err := repo.addCollaborator(sess, u); err != nil {
+ if err := repo.addCollaborator(db.GetEngine(ctx), u); err != nil {
return err
}
- return sess.Commit()
+ return committer.Commit()
}
func (repo *Repository) getCollaborations(e db.Engine, listOptions db.ListOptions) ([]*Collaboration, error) {
@@ -176,17 +176,17 @@ func (repo *Repository) changeCollaborationAccessMode(e db.Engine, uid int64, mo
// ChangeCollaborationAccessMode sets new access mode for the collaboration.
func (repo *Repository) ChangeCollaborationAccessMode(uid int64, mode AccessMode) error {
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err := sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return err
}
+ defer committer.Close()
- if err := repo.changeCollaborationAccessMode(sess, uid, mode); err != nil {
+ if err := repo.changeCollaborationAccessMode(db.GetEngine(ctx), uid, mode); err != nil {
return err
}
- return sess.Commit()
+ return committer.Commit()
}
// DeleteCollaboration removes collaboration relation between the user and repository.
@@ -196,11 +196,13 @@ func (repo *Repository) DeleteCollaboration(uid int64) (err error) {
UserID: uid,
}
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err = sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return err
}
+ defer committer.Close()
+
+ sess := db.GetEngine(ctx)
if has, err := sess.Delete(collaboration); err != nil || has == 0 {
return err
@@ -221,7 +223,7 @@ func (repo *Repository) DeleteCollaboration(uid int64) (err error) {
return err
}
- return sess.Commit()
+ return committer.Commit()
}
func (repo *Repository) reconsiderIssueAssignees(e db.Engine, uid int64) error {