From 33b9bf20bc28f41c35c54f08d7c3340d193d92b6 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 28 Apr 2025 13:29:40 +0200 Subject: [PATCH] Consolidate tag release user display with issue comments Increase consistency of rendering the ghost user, by re-using the same template. Also add a tooltip to the shared template, to explain the ghost user. Closes: #5630 --- options/locale_next/locale_en-US.json | 1 + templates/repo/release/list.tmpl | 5 +++-- templates/shared/user/authorlink.tmpl | 8 +++++++- tests/integration/repo_tag_test.go | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/options/locale_next/locale_en-US.json b/options/locale_next/locale_en-US.json index a551db87dc..7b02c4e570 100644 --- a/options/locale_next/locale_en-US.json +++ b/options/locale_next/locale_en-US.json @@ -102,6 +102,7 @@ "admin.dashboard.cleanup_offline_runners": "Cleanup offline runners", "settings.visibility.description": "Profile visibility affects others' ability to access your non-private repositories. Learn more", "avatar.constraints_hint": "Custom avatar may not exceed %[1]s in size or be larger than %[2]dx%[3]d pixels", + "user.ghost.tooltip": "This user has been deleted, or cannot be matched.", "og.repo.summary_card.alt_description": "Summary card of repository %[1]s, described as: %[2]s", "meta.last_line": "Thank you for translating Forgejo! This line isn't seen by the users but it serves other purposes in the translation management. You can place a fun fact in the translation instead of translating it." } diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index b8f50b1f4d..2cc457ca76 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -42,9 +42,10 @@ {{svg (MigrationIcon $release.Repo.GetOriginalURLHostname) 20 "tw-mr-1"}}{{$release.OriginalAuthor}} {{else if $release.Publisher}} {{ctx.AvatarUtils.Avatar $release.Publisher 20 "tw-mr-1"}} - {{$release.Publisher.GetDisplayName}} + {{template "shared/user/authorlink" $release.Publisher}} {{else}} - Ghost + + {{template "shared/user/authorlink" (dict "ID" -1)}} {{end}} diff --git a/templates/shared/user/authorlink.tmpl b/templates/shared/user/authorlink.tmpl index abe1ab1ce2..5be8a1612f 100644 --- a/templates/shared/user/authorlink.tmpl +++ b/templates/shared/user/authorlink.tmpl @@ -1 +1,7 @@ -{{.GetDisplayName}}{{if .IsBot}}bot{{end}} +{{if eq .ID -1}} + Ghost +{{else}} + {{.GetDisplayName}} + {{if .IsBot}}bot{{end}} +{{end}} diff --git a/tests/integration/repo_tag_test.go b/tests/integration/repo_tag_test.go index 9be33ec8a8..40cce02dfe 100644 --- a/tests/integration/repo_tag_test.go +++ b/tests/integration/repo_tag_test.go @@ -54,6 +54,30 @@ func TestTagViewWithoutRelease(t *testing.T) { // Test that there is no "Stable" link htmlDoc.AssertElement(t, "h4.release-list-title > span.ui.green.label", false) + + // Test that the correct user is linked + ownerLinkHref, _ := htmlDoc.Find("a.author").Attr("href") + assert.Equal(t, "/user2", ownerLinkHref) + + t.Run("Ghost owner", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + ghost := user_model.NewGhostUser() + err = release.CreateNewTag(git.DefaultContext, ghost, repo, "master", "ghost-tag", "a spooky tag") + require.NoError(t, err) + + req := NewRequestf(t, "GET", "/%s/releases/tag/ghost-tag", repo.FullName()) + resp := MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + + // Test that the Ghost user does not link anywhere + ownerLink := htmlDoc.Find("a.author") + _, ok := ownerLink.Attr("href") + assert.Equal(t, 1, ownerLink.Length()) + assert.False(t, ok) + assert.Equal(t, "Ghost", ownerLink.Text()) + }) } func TestCreateNewTagProtected(t *testing.T) {