refactor: username sub route (#39967)

Remove the workaround for chi router, do as much as possible in
middlewares

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
authored and GitHub committed 2026-10-24 16:27:56 +08:00
1 parent fc49368845
commit 1d8474ee1f
13 files changed
+103 -117

No files matched your search

+5 -1
View File
@@ -134,6 +134,7 @@ func testViewLimitedAndPrivateUserAndRename(t *testing.T) {
req = NewRequest(t, "GET", "/"+user31.Name)
MakeRequest(t, req, http.StatusNotFound)
MakeRequest(t, NewRequest(t, "GET", "/"+user31.Name).SetHeader("Accept", "application/rss+xml"), http.StatusNotFound)
MakeRequest(t, NewRequest(t, "GET", "/"+user31.Name+".keys"), http.StatusNotFound)
strangerSession.MakeRequest(t, NewRequest(t, "POST", "/"+user31.Name+"?action=follow"), http.StatusNotFound)
oldName = user31.Name
@@ -237,6 +238,7 @@ func testRenameReservedUsername(t *testing.T) {
func testExportUserGPGKeys(t *testing.T) {
testExportUserGPGKeys := func(t *testing.T, user, expected string) {
t.Helper()
session := loginUser(t, user)
t.Logf("Testing username %s export gpg keys", user)
req := NewRequest(t, "GET", "/"+user+".gpg")
@@ -324,7 +326,7 @@ func testGetUserRss(t *testing.T) {
user34 := "the_34-user.with.all.allowedChars"
req := NewRequestf(t, "GET", "/%s.rss", user34)
resp := MakeRequest(t, req, http.StatusOK)
if assert.Equal(t, "application/rss+xml;charset=utf-8", resp.Header().Get("Content-Type")) {
if assert.Equal(t, "application/rss+xml; charset=utf-8", resp.Header().Get("Content-Type")) {
rssDoc := NewHTMLParser(t, resp.Body).Find("channel")
title, _ := rssDoc.ChildrenFiltered("title").Html()
assert.Equal(t, "Feed of &#34;the_1-user.with.all.allowedChars&#34;", title)
@@ -339,6 +341,8 @@ func testGetUserRss(t *testing.T) {
req = NewRequestf(t, "GET", "/non-existent-user.rss")
session.MakeRequest(t, req, http.StatusNotFound)
MakeRequest(t, NewRequest(t, "GET", "/").SetHeader("Accept", "application/rss+xml"), http.StatusUnsupportedMediaType)
defer test.MockVariableValue(&setting.Other.EnableFeed, false)()
MakeRequest(t, NewRequestf(t, "GET", "/%s.rss", user34), http.StatusNotFound)
MakeRequest(t, NewRequestf(t, "GET", "/%s", user34).SetHeader("Accept", "application/rss+xml"), http.StatusNotFound)
+2 -2
View File
@@ -126,6 +126,6 @@ func testViewPageCurrentURL(t *testing.T) {
currentURL, _ = ctx.Data["CurrentURL"].(string)
})
defer web.RouteMockReset()
MakeRequest(t, NewRequest(t, "GET", "/any-page?k=v"), http.StatusNotFound)
assert.Equal(t, "/subpath/any-page?k=v", currentURL)
MakeRequest(t, NewRequest(t, "GET", "/user2?k=v"), http.StatusOK)
assert.Equal(t, "/subpath/user2?k=v", currentURL)
}