Skip to content

Commit

Permalink
Create and commit xorm session
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsvantesson committed Sep 30, 2019
1 parent d3eb84f commit e2080e8
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions models/repo_collaboration.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,21 @@ func (repo *Repository) addCollaborator(e Engine, u *User) error {

// AddCollaborator adds new collaboration to a repository with default access mode.
func (repo *Repository) AddCollaborator(u *User) error {
return repo.addCollaborator(x, u)
sess := x.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

if err = repo.addCollaborator(sess, u); err != nil {
return err
}

if err = sess.Commit(); err != nil {
return err
}

return nil
}

func (repo *Repository) getCollaborations(e Engine) ([]*Collaboration, error) {
Expand Down Expand Up @@ -132,7 +146,21 @@ func (repo *Repository) changeCollaborationAccessMode(e Engine, uid int64, mode

// ChangeCollaborationAccessMode sets new access mode for the collaboration.
func (repo *Repository) ChangeCollaborationAccessMode(uid int64, mode AccessMode) error {
return repo.changeCollaborationAccessMode(x, uid, mode)
sess := x.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

if err = repo.changeCollaborationAccessMode(sess, uid, mode); err != nil {
return err
}

if err = sess.Commit(); err != nil {
return err
}

return nil
}

// DeleteCollaboration removes collaboration relation between the user and repository.
Expand Down

0 comments on commit e2080e8

Please sign in to comment.