mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 08:59:31 -05:00
fix xorm NewSession uncorrected usages (#774)
This commit is contained in:
parent
25663b5816
commit
bb5a6b7a07
6 changed files with 23 additions and 33 deletions
|
@ -98,16 +98,12 @@ func TestRepository_RecalculateAccesses(t *testing.T) {
|
|||
repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
|
||||
assert.NoError(t, repo1.GetOwner())
|
||||
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
_, err := sess.Delete(&Collaboration{UserID: 2, RepoID: 3})
|
||||
_, err := x.Delete(&Collaboration{UserID: 2, RepoID: 3})
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, repo1.RecalculateAccesses())
|
||||
|
||||
sess = x.NewSession()
|
||||
access := &Access{UserID: 2, RepoID: 3}
|
||||
has, err := sess.Get(access)
|
||||
has, err := x.Get(access)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.Equal(t, AccessModeWrite, access.Mode)
|
||||
|
@ -119,15 +115,11 @@ func TestRepository_RecalculateAccesses2(t *testing.T) {
|
|||
repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository)
|
||||
assert.NoError(t, repo1.GetOwner())
|
||||
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
_, err := sess.Delete(&Collaboration{UserID: 4, RepoID: 4})
|
||||
_, err := x.Delete(&Collaboration{UserID: 4, RepoID: 4})
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, repo1.RecalculateAccesses())
|
||||
|
||||
sess = x.NewSession()
|
||||
has, err := sess.Get(&Access{UserID: 4, RepoID: 4})
|
||||
has, err := x.Get(&Access{UserID: 4, RepoID: 4})
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, has)
|
||||
}
|
||||
|
|
|
@ -345,13 +345,15 @@ func getOrgsByUserID(sess *xorm.Session, userID int64, showAll bool) ([]*User, e
|
|||
// GetOrgsByUserID returns a list of organizations that the given user ID
|
||||
// has joined.
|
||||
func GetOrgsByUserID(userID int64, showAll bool) ([]*User, error) {
|
||||
return getOrgsByUserID(x.NewSession(), userID, showAll)
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
return getOrgsByUserID(sess, userID, showAll)
|
||||
}
|
||||
|
||||
// GetOrgsByUserIDDesc returns a list of organizations that the given user ID
|
||||
// has joined, ordered descending by the given condition.
|
||||
func GetOrgsByUserIDDesc(userID int64, desc string, showAll bool) ([]*User, error) {
|
||||
return getOrgsByUserID(x.NewSession().Desc(desc), userID, showAll)
|
||||
return getOrgsByUserID(x.Desc(desc), userID, showAll)
|
||||
}
|
||||
|
||||
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
|
||||
|
@ -367,14 +369,14 @@ func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
|
|||
// GetOwnedOrgsByUserID returns a list of organizations are owned by given user ID.
|
||||
func GetOwnedOrgsByUserID(userID int64) ([]*User, error) {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
return getOwnedOrgsByUserID(sess, userID)
|
||||
}
|
||||
|
||||
// GetOwnedOrgsByUserIDDesc returns a list of organizations are owned by
|
||||
// given user ID, ordered descending by the given condition.
|
||||
func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
|
||||
sess := x.NewSession()
|
||||
return getOwnedOrgsByUserID(sess.Desc(desc), userID)
|
||||
return getOwnedOrgsByUserID(x.Desc(desc), userID)
|
||||
}
|
||||
|
||||
// GetOrgUsersByUserID returns all organization-user relations by user ID.
|
||||
|
|
|
@ -309,7 +309,7 @@ func UpdateTeam(t *Team, authChanged bool) (err error) {
|
|||
}
|
||||
|
||||
t.LowerName = strings.ToLower(t.Name)
|
||||
has, err := x.
|
||||
has, err := sess.
|
||||
Where("org_id=?", t.OrgID).
|
||||
And("lower_name=?", t.LowerName).
|
||||
And("id!=?", t.ID).
|
||||
|
|
|
@ -225,11 +225,9 @@ func TestChangeUsernameInPullRequests(t *testing.T) {
|
|||
assert.NoError(t, PrepareTestDatabase())
|
||||
const newUsername = "newusername"
|
||||
assert.NoError(t, ChangeUsernameInPullRequests("user1", newUsername))
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
prs := make([]*PullRequest, 0, 10)
|
||||
assert.NoError(t, sess.Where("head_user_name = ?", newUsername).Find(&prs))
|
||||
assert.NoError(t, x.Where("head_user_name = ?", newUsername).Find(&prs))
|
||||
assert.Len(t, prs, 2)
|
||||
for _, pr := range prs {
|
||||
assert.Equal(t, newUsername, pr.HeadUserName)
|
||||
|
|
|
@ -1515,16 +1515,16 @@ func DeleteRepository(uid, repoID int64) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err = sess.Commit(); err != nil {
|
||||
return fmt.Errorf("Commit: %v", err)
|
||||
}
|
||||
|
||||
if repo.NumForks > 0 {
|
||||
if _, err = x.Exec("UPDATE `repository` SET fork_id=0,is_fork=? WHERE fork_id=?", false, repo.ID); err != nil {
|
||||
if _, err = sess.Exec("UPDATE `repository` SET fork_id=0,is_fork=? WHERE fork_id=?", false, repo.ID); err != nil {
|
||||
log.Error(4, "reset 'fork_id' and 'is_fork': %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = sess.Commit(); err != nil {
|
||||
return fmt.Errorf("Commit: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -2217,30 +2217,29 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sessionRelease(sess)
|
||||
|
||||
// Copy LFS meta objects in new session
|
||||
sess = x.NewSession()
|
||||
defer sessionRelease(sess)
|
||||
if err = sess.Begin(); err != nil {
|
||||
sess2 := x.NewSession()
|
||||
defer sessionRelease(sess2)
|
||||
if err = sess2.Begin(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var lfsObjects []*LFSMetaObject
|
||||
|
||||
if err = sess.Where("repository_id=?", oldRepo.ID).Find(&lfsObjects); err != nil {
|
||||
if err = sess2.Where("repository_id=?", oldRepo.ID).Find(&lfsObjects); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, v := range lfsObjects {
|
||||
v.ID = 0
|
||||
v.RepositoryID = repo.ID
|
||||
if _, err = sess.Insert(v); err != nil {
|
||||
if _, err = sess2.Insert(v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return repo, sess.Commit()
|
||||
return repo, sess2.Commit()
|
||||
}
|
||||
|
||||
// GetForks returns all the forks of the repository
|
||||
|
|
|
@ -14,7 +14,6 @@ type Star struct {
|
|||
// StarRepo or unstar repository.
|
||||
func StarRepo(userID, repoID int64, star bool) error {
|
||||
sess := x.NewSession()
|
||||
|
||||
defer sess.Close()
|
||||
|
||||
if err := sess.Begin(); err != nil {
|
||||
|
|
Loading…
Reference in a new issue