|
|
@ -669,15 +669,23 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if _, err = sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName). |
|
|
|
curRepoLink := path.Join(u.LowerName, repo.LowerName) |
|
|
|
And("user_name = ?", u.LowerName).Update(&Access{UserName: newUser.LowerName}); err != nil { |
|
|
|
// Delete all access first if current owner is an organization.
|
|
|
|
|
|
|
|
if u.IsOrganization() { |
|
|
|
|
|
|
|
if _, err = sess.Where("repo_name=?", curRepoLink).Delete(new(Access)); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return fmt.Errorf("fail to delete current accesses: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if _, err = sess.Where("repo_name=?", curRepoLink).And("user_name=?", u.LowerName). |
|
|
|
|
|
|
|
Update(&Access{UserName: newUser.LowerName}); err != nil { |
|
|
|
sess.Rollback() |
|
|
|
sess.Rollback() |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if _, err = sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName).Update(&Access{ |
|
|
|
if _, err = sess.Where("repo_name=?", curRepoLink). |
|
|
|
RepoName: newUser.LowerName + "/" + repo.LowerName, |
|
|
|
Update(&Access{RepoName: path.Join(newUser.LowerName, repo.LowerName)}); err != nil { |
|
|
|
}); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
sess.Rollback() |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
@ -700,12 +708,12 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// New owner is organization.
|
|
|
|
|
|
|
|
if newUser.IsOrganization() { |
|
|
|
|
|
|
|
mode := WRITABLE |
|
|
|
mode := WRITABLE |
|
|
|
if repo.IsMirror { |
|
|
|
if repo.IsMirror { |
|
|
|
mode = READABLE |
|
|
|
mode = READABLE |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// New owner is organization.
|
|
|
|
|
|
|
|
if newUser.IsOrganization() { |
|
|
|
access := &Access{ |
|
|
|
access := &Access{ |
|
|
|
RepoName: path.Join(newUser.LowerName, repo.LowerName), |
|
|
|
RepoName: path.Join(newUser.LowerName, repo.LowerName), |
|
|
|
Mode: mode, |
|
|
|
Mode: mode, |
|
|
@ -737,6 +745,16 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { |
|
|
|
sess.Rollback() |
|
|
|
sess.Rollback() |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
access := &Access{ |
|
|
|
|
|
|
|
RepoName: path.Join(newUser.LowerName, repo.LowerName), |
|
|
|
|
|
|
|
UserName: newUser.LowerName, |
|
|
|
|
|
|
|
Mode: mode, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if _, err = sess.Insert(access); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Change repository directory name.
|
|
|
|
// Change repository directory name.
|
|
|
|