diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-10-11 13:54:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-11 19:54:44 +0800 |
commit | 8752d89be7958ea43dc29cc85de0b8f9dfc47c92 (patch) | |
tree | 52b955cadd5312ce0a19394597abfbcd487949bb | |
parent | 2d4c6321c39a10a020e12809fb3d855442629007 (diff) | |
download | gitea-8752d89be7958ea43dc29cc85de0b8f9dfc47c92.tar.gz gitea-8752d89be7958ea43dc29cc85de0b8f9dfc47c92.zip |
Redirect to new repository owner (#21398)
Fixes #17655
If you rename `user1` to `user2` and visit `/user1` you get redirected
to `/user2`. But if you visit `/user1/repo` you just get a 404 error.
With this PR the user is redirected to `/user2/repo`.
-rw-r--r-- | modules/context/repo.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go index 1742683d3c..1a0263a330 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -451,11 +451,20 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { owner, err = user_model.GetUserByName(ctx, userName) if err != nil { if user_model.IsErrUserNotExist(err) { + // go-get does not support redirects + // https://github.com/golang/go/issues/19760 if ctx.FormString("go-get") == "1" { EarlyResponseForGoGetMeta(ctx) return } - ctx.NotFound("GetUserByName", nil) + + if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil { + RedirectToUser(ctx, userName, redirectUserID) + } else if user_model.IsErrUserRedirectNotExist(err) { + ctx.NotFound("GetUserByName", nil) + } else { + ctx.ServerError("LookupUserRedirect", err) + } } else { ctx.ServerError("GetUserByName", err) } |