|
|
@ -644,12 +644,20 @@ func RepoPath(userName, repoName string) string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TransferOwnership transfers all corresponding setting from old user to new one.
|
|
|
|
// TransferOwnership transfers all corresponding setting from old user to new one.
|
|
|
|
func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
|
|
|
|
func TransferOwnership(u *User, newOwner string, repo *Repository) error {
|
|
|
|
newUser, err := GetUserByName(newOwner)
|
|
|
|
newUser, err := GetUserByName(newOwner)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if new owner has repository with same name.
|
|
|
|
|
|
|
|
has, err := IsRepositoryExist(u, repo.Name)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
} else if has {
|
|
|
|
|
|
|
|
return ErrRepoAlreadyExist
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sess := x.NewSession()
|
|
|
|
sess := x.NewSession()
|
|
|
|
defer sess.Close()
|
|
|
|
defer sess.Close()
|
|
|
|
if err = sess.Begin(); err != nil {
|
|
|
|
if err = sess.Begin(); err != nil {
|
|
|
@ -717,12 +725,6 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if _, err = sess.Exec(
|
|
|
|
|
|
|
|
"UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil {
|
|
|
|
|
|
|
|
sess.Rollback()
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update owner team info and count.
|
|
|
|
// Update owner team info and count.
|
|
|
|
t.RepoIds += "$" + com.ToStr(repo.Id) + "|"
|
|
|
|
t.RepoIds += "$" + com.ToStr(repo.Id) + "|"
|
|
|
|
t.NumRepos++
|
|
|
|
t.NumRepos++
|
|
|
@ -933,9 +935,9 @@ func GetRepositoryByRef(ref string) (*Repository, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetRepositoryByName returns the repository by given name under user if exists.
|
|
|
|
// GetRepositoryByName returns the repository by given name under user if exists.
|
|
|
|
func GetRepositoryByName(userId int64, repoName string) (*Repository, error) {
|
|
|
|
func GetRepositoryByName(uid int64, repoName string) (*Repository, error) {
|
|
|
|
repo := &Repository{
|
|
|
|
repo := &Repository{
|
|
|
|
OwnerId: userId,
|
|
|
|
OwnerId: uid,
|
|
|
|
LowerName: strings.ToLower(repoName),
|
|
|
|
LowerName: strings.ToLower(repoName),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
has, err := x.Get(repo)
|
|
|
|
has, err := x.Get(repo)
|
|
|
|