summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames E. Blair <corvus@inaugust.com>2019-02-27 19:51:46 -0800
committerLunny Xiao <xiaolunwen@gmail.com>2019-02-28 11:51:46 +0800
commit48c101affe78396db89caada28f883ef5fac20a6 (patch)
tree517b4e1f1feb740b8ec92d4b0ad3d0631b3d93d8
parent525f03306f5b1a14c2856d62c4c6c85e78394a7b (diff)
downloadgitea-48c101affe78396db89caada28f883ef5fac20a6.tar.gz
gitea-48c101affe78396db89caada28f883ef5fac20a6.zip
Create a repo redirect when transferring ownership (#6210) (#6211)
When transferring ownership of a repo to a different user/org, create a repo redirect that points to the new location in the same way that is done when a repo is renamed. Signed-off-by: James E. Blair <jeblair@redhat.com>
-rw-r--r--modules/context/repo.go2
-rw-r--r--routers/repo/setting.go8
2 files changed, 9 insertions, 1 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 07873a3c6c..8f4377b041 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -204,7 +204,7 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
redirectPath := strings.Replace(
ctx.Req.URL.Path,
fmt.Sprintf("%s/%s", ownerName, previousRepoName),
- fmt.Sprintf("%s/%s", ownerName, repo.Name),
+ fmt.Sprintf("%s/%s", repo.MustOwnerName(), repo.Name),
1,
)
ctx.Redirect(redirectPath)
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index 809aab27aa..853c343115 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -321,6 +321,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
return
}
+ oldOwnerID := ctx.Repo.Owner.ID
if err = models.TransferOwnership(ctx.User, newOwner, repo); err != nil {
if models.IsErrRepoAlreadyExist(err) {
ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil)
@@ -329,6 +330,13 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
}
return
}
+
+ err = models.NewRepoRedirect(oldOwnerID, repo.ID, repo.Name, repo.Name)
+ if err != nil {
+ ctx.ServerError("NewRepoRedirect", err)
+ return
+ }
+
log.Trace("Repository transferred: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newOwner)
ctx.Flash.Success(ctx.Tr("repo.settings.transfer_succeed"))
ctx.Redirect(setting.AppSubURL + "/" + newOwner + "/" + repo.Name)