bug fixed
This commit is contained in:
parent
aed4271c8d
commit
3c6da63216
1 changed files with 38 additions and 10 deletions
|
@ -627,17 +627,37 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update accesses.
|
// Update accesses.
|
||||||
accesses := make([]Access, 0, 10)
|
/*accesses := make([]Access, 0, 10)
|
||||||
if err = x.Find(&accesses, &Access{RepoName: u.LowerName + "/" + repo.LowerName}); err != nil {
|
if err = x.Find(&accesses, &Access{RepoName: u.LowerName + "/" + repo.LowerName}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
//fmt.Println("0")
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
defer sess.Close()
|
defer sess.Close()
|
||||||
if err = sess.Begin(); err != nil {
|
if err = sess.Begin(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
access := &Access{
|
||||||
|
RepoName: newUser.LowerName + "/" + repo.LowerName,
|
||||||
|
UserName: newUser.LowerName,
|
||||||
|
}
|
||||||
|
//fmt.Println("1")
|
||||||
|
sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName)
|
||||||
|
_, err = sess.And("user_name = ?", u.LowerName).Update(&Access{UserName: newUser.LowerName})
|
||||||
|
if err != nil {
|
||||||
|
sess.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
//fmt.Println("2")
|
||||||
|
_, err = sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName).Update(access)
|
||||||
|
if err != nil {
|
||||||
|
sess.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
for i := range accesses {
|
for i := range accesses {
|
||||||
accesses[i].RepoName = newUser.LowerName + "/" + repo.LowerName
|
accesses[i].RepoName = newUser.LowerName + "/" + repo.LowerName
|
||||||
if accesses[i].UserName == u.LowerName {
|
if accesses[i].UserName == u.LowerName {
|
||||||
|
@ -646,8 +666,9 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
|
||||||
if err = UpdateAccessWithSession(sess, &accesses[i]); err != nil {
|
if err = UpdateAccessWithSession(sess, &accesses[i]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
//fmt.Println("3")
|
||||||
// Update repository.
|
// Update repository.
|
||||||
repo.OwnerId = newUser.Id
|
repo.OwnerId = newUser.Id
|
||||||
if _, err := sess.Id(repo.Id).Update(repo); err != nil {
|
if _, err := sess.Id(repo.Id).Update(repo); err != nil {
|
||||||
|
@ -655,18 +676,22 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fmt.Println("4")
|
||||||
// Update user repository number.
|
// Update user repository number.
|
||||||
rawSql := "UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?"
|
rawSql := "UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?"
|
||||||
if _, err = sess.Exec(rawSql, newUser.Id); err != nil {
|
if _, err = sess.Exec(rawSql, newUser.Id); err != nil {
|
||||||
sess.Rollback()
|
sess.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
//fmt.Println("5")
|
||||||
rawSql = "UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?"
|
rawSql = "UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?"
|
||||||
if _, err = sess.Exec(rawSql, u.Id); err != nil {
|
if _, err = sess.Exec(rawSql, u.Id); err != nil {
|
||||||
sess.Rollback()
|
sess.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fmt.Println("6")
|
||||||
|
|
||||||
// Add watch of new owner to repository.
|
// Add watch of new owner to repository.
|
||||||
if !IsWatching(newUser.Id, repo.Id) {
|
if !IsWatching(newUser.Id, repo.Id) {
|
||||||
if err = WatchRepo(newUser.Id, repo.Id, true); err != nil {
|
if err = WatchRepo(newUser.Id, repo.Id, true); err != nil {
|
||||||
|
@ -675,17 +700,20 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fmt.Println("7")
|
||||||
if err = TransferRepoAction(u, newUser, repo); err != nil {
|
if err = TransferRepoAction(u, newUser, repo); err != nil {
|
||||||
sess.Rollback()
|
sess.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fmt.Println("8")
|
||||||
// Change repository directory name.
|
// Change repository directory name.
|
||||||
if err = os.Rename(RepoPath(u.Name, repo.Name), RepoPath(newUser.Name, repo.Name)); err != nil {
|
if err = os.Rename(RepoPath(u.Name, repo.Name), RepoPath(newUser.Name, repo.Name)); err != nil {
|
||||||
sess.Rollback()
|
sess.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fmt.Println("9")
|
||||||
return sess.Commit()
|
return sess.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue