From 74fedb27b4d87ea02896ef3dc2cac4ce81774a33 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 15:42:03 +0200 Subject: [PATCH 01/13] User/Org RSS render description as per web too --- build.go | 1 - routers/web/feed/profile.go | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/build.go b/build.go index d2e724a7f70c5..234579b514998 100644 --- a/build.go +++ b/build.go @@ -1,7 +1,6 @@ // Copyright 2020 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT - //go:build vendor package main diff --git a/routers/web/feed/profile.go b/routers/web/feed/profile.go index b9dda2fc10ac4..ce86727e24820 100644 --- a/routers/web/feed/profile.go +++ b/routers/web/feed/profile.go @@ -8,6 +8,8 @@ import ( activities_model "code.gitea.io/gitea/models/activities" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/markup/markdown" "github.com/gorilla/feeds" ) @@ -39,10 +41,22 @@ func showUserFeed(ctx *context.Context, formatType string) { return } + ctxUserDescription, err := markdown.RenderString(&markup.RenderContext{ + Ctx: ctx, + URLPrefix: ctx.ContextUser.HTMLURL(), + Metas: map[string]string{ + "user": ctx.ContextUser.GetDisplayName(), + }, + }, ctx.ContextUser.Description) + if err != nil { + ctx.ServerError("RenderString", err) + return + } + feed := &feeds.Feed{ Title: ctx.Tr("home.feed_of", ctx.ContextUser.DisplayName()), Link: &feeds.Link{Href: ctx.ContextUser.HTMLURL()}, - Description: ctx.ContextUser.Description, + Description: ctxUserDescription, Created: time.Now(), } From 6a9e90cac4176febeb9d8e9ed9f7f97fb42be174 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 16:17:45 +0200 Subject: [PATCH 02/13] Use WORKAROUND for https://github.com/go-chi/chi/issues/781 close #22301 --- routers/web/web.go | 48 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/routers/web/web.go b/routers/web/web.go index 4bd2f76c571f1..fb59e317754d6 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -8,6 +8,7 @@ import ( "net/http" "os" "path" + "strings" "code.gitea.io/gitea/models/perm" "code.gitea.io/gitea/models/unit" @@ -672,16 +673,43 @@ func RegisterRoutes(m *web.Route) { }) http.ServeFile(ctx.Resp, ctx.Req, path.Join(setting.StaticRootPath, "public/img/favicon.png")) }) - m.Group("/{username}", func() { - m.Get(".png", user.AvatarByUserName) - m.Get(".keys", user.ShowSSHKeys) - m.Get(".gpg", user.ShowGPGKeys) - m.Get(".rss", feedEnabled, feed.ShowUserFeedRSS) - m.Get(".atom", feedEnabled, feed.ShowUserFeedAtom) - m.Get("", user.Profile) - }, func(ctx *context.Context) { - ctx.Data["EnableFeed"] = setting.EnableFeed - }, context_service.UserAssignmentWeb()) + m.Get("/{username}", func(ctx *context.Context) { + // WORKAROUND to support usernames with "." in it + // https://github.com/go-chi/chi/issues/781 + username := ctx.Params("username") + switch { + case strings.HasSuffix(username, ".png"): + ctx.SetParams("username", strings.TrimSuffix(username, ".png")) + context_service.UserAssignmentWeb()(ctx) + user.AvatarByUserName(ctx) + case strings.HasSuffix(username, ".keys"): + ctx.SetParams("username", strings.TrimSuffix(username, ".keys")) + context_service.UserAssignmentWeb()(ctx) + user.ShowSSHKeys(ctx) + case strings.HasSuffix(username, ".gpg"): + ctx.SetParams("username", strings.TrimSuffix(username, ".gpg")) + context_service.UserAssignmentWeb()(ctx) + user.ShowGPGKeys(ctx) + case strings.HasSuffix(username, ".rss"): + feedEnabled(ctx) + if !ctx.Written() { + ctx.SetParams("username", strings.TrimSuffix(username, ".rss")) + context_service.UserAssignmentWeb()(ctx) + feed.ShowUserFeedRSS(ctx) + } + case strings.HasSuffix(username, ".atom"): + feedEnabled(ctx) + if !ctx.Written() { + ctx.SetParams("username", strings.TrimSuffix(username, ".atom")) + context_service.UserAssignmentWeb()(ctx) + feed.ShowUserFeedAtom(ctx) + } + default: + context_service.UserAssignmentWeb()(ctx) + ctx.Data["EnableFeed"] = setting.EnableFeed + user.Profile(ctx) + } + }) m.Get("/attachments/{uuid}", repo.GetAttachment) }, ignSignIn) From a85694fcfc7a96bb8a462f475e4e106a2393a4ea Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 19:08:04 +0200 Subject: [PATCH 03/13] add test --- models/fixtures/action.yml | 9 +++++++++ models/fixtures/user.yml | 37 ++++++++++++++++++++++++++++++++++ tests/integration/user_test.go | 7 +++++++ 3 files changed, 53 insertions(+) diff --git a/models/fixtures/action.yml b/models/fixtures/action.yml index a75092feb0ecc..af9ce93ba5c5d 100644 --- a/models/fixtures/action.yml +++ b/models/fixtures/action.yml @@ -64,3 +64,12 @@ repo_id: 1700 # dangling intentional is_private: false created_unix: 1603011541 + +- id: 9 + user_id: 34 + op_type: 12 # close issue + act_user_id: 34 + repo_id: 1 # public + is_private: false + created_unix: 1680454039 + content: '4|' # issueId 5 diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index ce54defacdc67..5fc7cf27fe9d2 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -1220,3 +1220,40 @@ repo_admin_change_team_access: false theme: "" keep_activity_private: false + +- + id: 34 + lower_name: the_34-user.with.all.allowedchars + name: the_34-user.with.all.allowedChars + full_name: the_1-user.with.all.allowedChars + email: user34@example.com + keep_email_private: false + email_notifications_preference: enabled + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy + must_change_password: false + login_source: 0 + login_name: the_34-user.with.all.allowedchars + type: 0 + salt: ZogKvWdyEx + max_repo_creation: -1 + is_active: true + is_admin: false + is_restricted: false + allow_git_hook: false + allow_import_local: false + allow_create_organization: false + prohibit_login: false + avatar: avatar34 + avatar_email: user34@example.com + use_custom_avatar: true + num_followers: 0 + num_following: 0 + num_stars: 0 + num_repos: 0 + num_teams: 0 + num_members: 0 + visibility: 0 + repo_admin_change_team_access: false + theme: "" + keep_activity_private: false diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go index febfe576cf9b0..238d98973e056 100644 --- a/tests/integration/user_test.go +++ b/tests/integration/user_test.go @@ -241,6 +241,13 @@ func testExportUserGPGKeys(t *testing.T, user, expected string) { assert.Equal(t, expected, resp.Body.String()) } +func TestGetPng(t *testing.T) { + user34 := "the_34-user.with.all.allowedChars" + req := NewRequestf(t, "GET", "/%s.png", user34) + resp := MakeRequest(t, req, http.StatusSeeOther) + assert.EqualValues(t, "/avatars/avatar34", resp.Header().Get("location")) +} + func TestListStopWatches(t *testing.T) { defer tests.PrepareTestEnv(t)() From a486a46dfb06d8d3a310ba67bbf804123297b123 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 19:12:41 +0200 Subject: [PATCH 04/13] adjust tests to new added user --- models/user/user_test.go | 4 ++-- tests/integration/api_nodeinfo_test.go | 2 +- tests/integration/setting_test.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/models/user/user_test.go b/models/user/user_test.go index fc8f6b8d515ce..8e78fee6b31d1 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -99,13 +99,13 @@ func TestSearchUsers(t *testing.T) { } testUserSuccess(&user_model.SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}}, - []int64{1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32}) + []int64{1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32, 34}) testUserSuccess(&user_model.SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolFalse}, []int64{9}) testUserSuccess(&user_model.SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue}, - []int64{1, 2, 4, 5, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32}) + []int64{1, 2, 4, 5, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32, 34}) testUserSuccess(&user_model.SearchUserOptions{Keyword: "user1", OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue}, []int64{1, 10, 11, 12, 13, 14, 15, 16, 18}) diff --git a/tests/integration/api_nodeinfo_test.go b/tests/integration/api_nodeinfo_test.go index 29fff8ba72618..bc2f11a7f2987 100644 --- a/tests/integration/api_nodeinfo_test.go +++ b/tests/integration/api_nodeinfo_test.go @@ -33,7 +33,7 @@ func TestNodeinfo(t *testing.T) { DecodeJSON(t, resp, &nodeinfo) assert.True(t, nodeinfo.OpenRegistrations) assert.Equal(t, "gitea", nodeinfo.Software.Name) - assert.Equal(t, 24, nodeinfo.Usage.Users.Total) + assert.Equal(t, 25, nodeinfo.Usage.Users.Total) assert.Equal(t, 18, nodeinfo.Usage.LocalPosts) assert.Equal(t, 2, nodeinfo.Usage.LocalComments) }) diff --git a/tests/integration/setting_test.go b/tests/integration/setting_test.go index 54819c5b7d788..777faf8cc0513 100644 --- a/tests/integration/setting_test.go +++ b/tests/integration/setting_test.go @@ -25,7 +25,7 @@ func TestSettingShowUserEmailExplore(t *testing.T) { htmlDoc := NewHTMLParser(t, resp.Body) assert.Contains(t, htmlDoc.doc.Find(".ui.user.list").Text(), - "user4@example.com", + "user34@example.com", ) setting.UI.ShowUserEmail = false @@ -35,7 +35,7 @@ func TestSettingShowUserEmailExplore(t *testing.T) { htmlDoc = NewHTMLParser(t, resp.Body) assert.NotContains(t, htmlDoc.doc.Find(".ui.user.list").Text(), - "user4@example.com", + "user34@example.com", ) setting.UI.ShowUserEmail = showUserEmail From 4ae66956cd9cc72a6a6261fdd4707fe494076f52 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 21:16:38 +0200 Subject: [PATCH 05/13] add warning --- models/user/user.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/user/user.go b/models/user/user.go index 82c2d3b6cdc10..29245f8119b0a 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -537,6 +537,7 @@ var ( "gitea-actions", } + // DON'T ADD ANY NEW STUFF, WE SOLVE THIS WITH ALTERNATE PATHS! reservedUserPatterns = []string{"*.keys", "*.gpg", "*.rss", "*.atom"} ) From 0129cb1ba41c1073cdabd7bc9864f4a878427361 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 21:27:47 +0200 Subject: [PATCH 06/13] drop "/{username}.png" in fafour of "/user/avatar/{username}" --- routers/web/web.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/routers/web/web.go b/routers/web/web.go index fb59e317754d6..55ceb180141fb 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -536,6 +536,7 @@ func RegisterRoutes(m *web.Route) { m.Get("/activate", auth.Activate) m.Post("/activate", auth.ActivatePost) m.Any("/activate_email", auth.ActivateEmail) + m.Get("/avatar/{username}", user.AvatarByUserName) m.Get("/avatar/{username}/{size}", user.AvatarByUserName) m.Get("/recover_account", auth.ResetPasswd) m.Post("/recover_account", auth.ResetPasswdPost) @@ -678,10 +679,6 @@ func RegisterRoutes(m *web.Route) { // https://github.com/go-chi/chi/issues/781 username := ctx.Params("username") switch { - case strings.HasSuffix(username, ".png"): - ctx.SetParams("username", strings.TrimSuffix(username, ".png")) - context_service.UserAssignmentWeb()(ctx) - user.AvatarByUserName(ctx) case strings.HasSuffix(username, ".keys"): ctx.SetParams("username", strings.TrimSuffix(username, ".keys")) context_service.UserAssignmentWeb()(ctx) From f51515996d226c9dc0c6c63ab5186865aab1b0ec Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 22:07:08 +0200 Subject: [PATCH 07/13] adjust tests --- models/fixtures/user.yml | 1 + tests/integration/user_avatar_test.go | 11 +++++++++++ tests/integration/user_test.go | 14 ++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 5fc7cf27fe9d2..bfd4b6704bf27 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -1226,6 +1226,7 @@ lower_name: the_34-user.with.all.allowedchars name: the_34-user.with.all.allowedChars full_name: the_1-user.with.all.allowedChars + description: 'some [commonmark](https://commonmark.org/)!' email: user34@example.com keep_email_private: false email_notifications_preference: enabled diff --git a/tests/integration/user_avatar_test.go b/tests/integration/user_avatar_test.go index 7aeba6a334cf7..7bfd2dcff599b 100644 --- a/tests/integration/user_avatar_test.go +++ b/tests/integration/user_avatar_test.go @@ -5,6 +5,7 @@ package integration import ( "bytes" + "fmt" "image/png" "io" "mime/multipart" @@ -77,6 +78,16 @@ func TestUserAvatar(t *testing.T) { req = NewRequest(t, "GET", user2.AvatarLinkWithSize(db.DefaultContext, 0)) _ = session.MakeRequest(t, req, http.StatusOK) + testGetAvatarRedirect(t, user2) + // Can't test if the response matches because the image is re-generated on upload but checking that this at least doesn't give a 404 should be enough. }) } + +func testGetAvatarRedirect(t *testing.T, user *user_model.User) { + t.Run(fmt.Sprintf("getAvatarRedirect_%s", user.Name), func(t *testing.T) { + req := NewRequestf(t, "GET", "/user/avatar/%s", user.Name) + resp := MakeRequest(t, req, http.StatusSeeOther) + assert.EqualValues(t, fmt.Sprintf("/avatars/%s", user.Avatar), resp.Header().Get("location")) + }) +} diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go index 238d98973e056..a002bffd885ce 100644 --- a/tests/integration/user_test.go +++ b/tests/integration/user_test.go @@ -241,11 +241,17 @@ func testExportUserGPGKeys(t *testing.T, user, expected string) { assert.Equal(t, expected, resp.Body.String()) } -func TestGetPng(t *testing.T) { +func TestGetUserRss(t *testing.T) { user34 := "the_34-user.with.all.allowedChars" - req := NewRequestf(t, "GET", "/%s.png", user34) - resp := MakeRequest(t, req, http.StatusSeeOther) - assert.EqualValues(t, "/avatars/avatar34", resp.Header().Get("location")) + req := NewRequestf(t, "GET", "/%s.rss", user34) + resp := MakeRequest(t, req, http.StatusOK) + if assert.EqualValues(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.EqualValues(t, "Feed of "the_1-user.with.all.allowedChars"", title) + description, _ := rssDoc.ChildrenFiltered("description").Html() + assert.EqualValues(t, "<p>some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>", description) + } } func TestListStopWatches(t *testing.T) { From 4cc8623445250179338ee8d20bbbfa70c2f03764 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 22:12:09 +0200 Subject: [PATCH 08/13] Update models/user/user.go --- models/user/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/user/user.go b/models/user/user.go index 29245f8119b0a..a798d99b49a00 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -537,7 +537,7 @@ var ( "gitea-actions", } - // DON'T ADD ANY NEW STUFF, WE SOLVE THIS WITH ALTERNATE PATHS! + // DON'T ADD ANY NEW STUFF, WE SOLVE THIS WITH `/user/{obj}` PATHS! reservedUserPatterns = []string{"*.keys", "*.gpg", "*.rss", "*.atom"} ) From 9d8cd975cf84f1f17e3f46890d53deb924102c8f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 22:13:08 +0200 Subject: [PATCH 09/13] fix --- tests/integration/user_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go index a002bffd885ce..fa8e6e85c7a3a 100644 --- a/tests/integration/user_test.go +++ b/tests/integration/user_test.go @@ -250,7 +250,7 @@ func TestGetUserRss(t *testing.T) { title, _ := rssDoc.ChildrenFiltered("title").Html() assert.EqualValues(t, "Feed of "the_1-user.with.all.allowedChars"", title) description, _ := rssDoc.ChildrenFiltered("description").Html() - assert.EqualValues(t, "<p>some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>", description) + assert.EqualValues(t, "<p>some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>\n", description) } } From 96b1b301a53cfcff8f79d19273b578328e6be00f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 22:28:11 +0200 Subject: [PATCH 10/13] check if context_service.UserAssignmentWeb()() did ctx.Written() --- routers/web/web.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/routers/web/web.go b/routers/web/web.go index 55ceb180141fb..6036268b53772 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -678,27 +678,29 @@ func RegisterRoutes(m *web.Route) { // WORKAROUND to support usernames with "." in it // https://github.com/go-chi/chi/issues/781 username := ctx.Params("username") + reloadParam := func(suffix string) (success bool) { + ctx.SetParams("username", strings.TrimSuffix(username, suffix)) + context_service.UserAssignmentWeb()(ctx) + return !ctx.Written() + } switch { case strings.HasSuffix(username, ".keys"): - ctx.SetParams("username", strings.TrimSuffix(username, ".keys")) - context_service.UserAssignmentWeb()(ctx) - user.ShowSSHKeys(ctx) + if reloadParam(".keys") { + user.ShowSSHKeys(ctx) + } case strings.HasSuffix(username, ".gpg"): - ctx.SetParams("username", strings.TrimSuffix(username, ".gpg")) - context_service.UserAssignmentWeb()(ctx) - user.ShowGPGKeys(ctx) + if reloadParam(".gpg") { + user.ShowGPGKeys(ctx) + } case strings.HasSuffix(username, ".rss"): feedEnabled(ctx) - if !ctx.Written() { - ctx.SetParams("username", strings.TrimSuffix(username, ".rss")) + if !ctx.Written() && reloadParam(".rss") { context_service.UserAssignmentWeb()(ctx) feed.ShowUserFeedRSS(ctx) } case strings.HasSuffix(username, ".atom"): feedEnabled(ctx) - if !ctx.Written() { - ctx.SetParams("username", strings.TrimSuffix(username, ".atom")) - context_service.UserAssignmentWeb()(ctx) + if !ctx.Written() && reloadParam(".atom") { feed.ShowUserFeedAtom(ctx) } default: From 1a7842448783536963d6dbedd0efca9cb1890a37 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 2 Apr 2023 22:30:27 +0200 Subject: [PATCH 11/13] followup --- routers/web/web.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/routers/web/web.go b/routers/web/web.go index 6036268b53772..6d331292faa60 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -705,8 +705,10 @@ func RegisterRoutes(m *web.Route) { } default: context_service.UserAssignmentWeb()(ctx) - ctx.Data["EnableFeed"] = setting.EnableFeed - user.Profile(ctx) + if !ctx.Written() { + ctx.Data["EnableFeed"] = setting.EnableFeed + user.Profile(ctx) + } } }) m.Get("/attachments/{uuid}", repo.GetAttachment) From 6b5f2dc19cc5a51ded99e77bd64a77677180abdc Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 3 Apr 2023 01:02:23 +0200 Subject: [PATCH 12/13] Update models/user/user.go Co-authored-by: silverwind --- models/user/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/user/user.go b/models/user/user.go index a798d99b49a00..b3c24958449aa 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -537,7 +537,7 @@ var ( "gitea-actions", } - // DON'T ADD ANY NEW STUFF, WE SOLVE THIS WITH `/user/{obj}` PATHS! + // DON'T ADD ANY NEW STUFF, WE SOLVE THIS WITH `/user/{obj}` PATHS! reservedUserPatterns = []string{"*.keys", "*.gpg", "*.rss", "*.atom"} ) From 8418d40283a32bf1258143f5f30b54ad10230878 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 4 Apr 2023 06:18:53 +0200 Subject: [PATCH 13/13] move username.png drop into #23908 --- models/user/user.go | 1 - routers/web/web.go | 5 ++++- tests/integration/user_avatar_test.go | 11 ----------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/models/user/user.go b/models/user/user.go index b3c24958449aa..82c2d3b6cdc10 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -537,7 +537,6 @@ var ( "gitea-actions", } - // DON'T ADD ANY NEW STUFF, WE SOLVE THIS WITH `/user/{obj}` PATHS! reservedUserPatterns = []string{"*.keys", "*.gpg", "*.rss", "*.atom"} ) diff --git a/routers/web/web.go b/routers/web/web.go index 30e0938828e39..c9852f738177b 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -537,7 +537,6 @@ func RegisterRoutes(m *web.Route) { m.Get("/activate", auth.Activate) m.Post("/activate", auth.ActivatePost) m.Any("/activate_email", auth.ActivateEmail) - m.Get("/avatar/{username}", user.AvatarByUserName) m.Get("/avatar/{username}/{size}", user.AvatarByUserName) m.Get("/recover_account", auth.ResetPasswd) m.Post("/recover_account", auth.ResetPasswdPost) @@ -685,6 +684,10 @@ func RegisterRoutes(m *web.Route) { return !ctx.Written() } switch { + case strings.HasSuffix(username, ".png"): + if reloadParam(".png") { + user.AvatarByUserName(ctx) + } case strings.HasSuffix(username, ".keys"): if reloadParam(".keys") { user.ShowSSHKeys(ctx) diff --git a/tests/integration/user_avatar_test.go b/tests/integration/user_avatar_test.go index 7bfd2dcff599b..7aeba6a334cf7 100644 --- a/tests/integration/user_avatar_test.go +++ b/tests/integration/user_avatar_test.go @@ -5,7 +5,6 @@ package integration import ( "bytes" - "fmt" "image/png" "io" "mime/multipart" @@ -78,16 +77,6 @@ func TestUserAvatar(t *testing.T) { req = NewRequest(t, "GET", user2.AvatarLinkWithSize(db.DefaultContext, 0)) _ = session.MakeRequest(t, req, http.StatusOK) - testGetAvatarRedirect(t, user2) - // Can't test if the response matches because the image is re-generated on upload but checking that this at least doesn't give a 404 should be enough. }) } - -func testGetAvatarRedirect(t *testing.T, user *user_model.User) { - t.Run(fmt.Sprintf("getAvatarRedirect_%s", user.Name), func(t *testing.T) { - req := NewRequestf(t, "GET", "/user/avatar/%s", user.Name) - resp := MakeRequest(t, req, http.StatusSeeOther) - assert.EqualValues(t, fmt.Sprintf("/avatars/%s", user.Avatar), resp.Header().Get("location")) - }) -}