Browse Source

update name

pull/283/merge
Unknown 11 years ago
parent
commit
13b032f829
  1. 12
      models/repo.go
  2. 2
      routers/repo/setting.go

12
models/repo.go

@ -620,7 +620,7 @@ 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(user *User, newOwner string, repo *Repository) (err error) { func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
newUser, err := GetUserByName(newOwner) newUser, err := GetUserByName(newOwner)
if err != nil { if err != nil {
return err return err
@ -628,7 +628,7 @@ func TransferOwnership(user *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: user.LowerName + "/" + repo.LowerName}); err != nil { if err = x.Find(&accesses, &Access{RepoName: u.LowerName + "/" + repo.LowerName}); err != nil {
return err return err
} }
@ -640,7 +640,7 @@ func TransferOwnership(user *User, newOwner string, repo *Repository) (err error
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 == user.LowerName { if accesses[i].UserName == u.LowerName {
accesses[i].UserName = newUser.LowerName accesses[i].UserName = newUser.LowerName
} }
if err = UpdateAccessWithSession(sess, &accesses[i]); err != nil { if err = UpdateAccessWithSession(sess, &accesses[i]); err != nil {
@ -662,7 +662,7 @@ func TransferOwnership(user *User, newOwner string, repo *Repository) (err error
return err return err
} }
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, user.Id); err != nil { if _, err = sess.Exec(rawSql, u.Id); err != nil {
sess.Rollback() sess.Rollback()
return err return err
} }
@ -675,13 +675,13 @@ func TransferOwnership(user *User, newOwner string, repo *Repository) (err error
} }
} }
if err = TransferRepoAction(user, newUser, repo); err != nil { if err = TransferRepoAction(u, newUser, repo); err != nil {
sess.Rollback() sess.Rollback()
return err return err
} }
// Change repository directory name. // Change repository directory name.
if err = os.Rename(RepoPath(user.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
} }

2
routers/repo/setting.go

@ -109,7 +109,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) {
} else if !isExist { } else if !isExist {
ctx.RenderWithErr("Please make sure you entered owner name is correct.", SETTING, nil) ctx.RenderWithErr("Please make sure you entered owner name is correct.", SETTING, nil)
return return
} else if err = models.TransferOwnership(ctx.User, newOwner, ctx.Repo.Repository); err != nil { } else if err = models.TransferOwnership(ctx.Repo.Owner, newOwner, ctx.Repo.Repository); err != nil {
ctx.Handle(500, "setting.SettingPost(transfer repository)", err) ctx.Handle(500, "setting.SettingPost(transfer repository)", err)
return return
} }

Loading…
Cancel
Save