From 2f0a1eb0d57bbc87d52e59c1ce5072d8987d35f5 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 3 Sep 2022 13:51:10 +0100 Subject: [PATCH] Do not add links to Posters or Assignees with ID < 0 (#20577) (#21037) Backport #20577 There are several places in templates/repo/issue/view_content/comments.tmpl where links are made to Posters or Assignees who are Ghosts or have IDs <0. Fix #20559 Signed-off-by: Andrew Thornton Signed-off-by: Andrew Thornton --- templates/org/team/teams.tmpl | 4 +- templates/repo/diff/comments.tmpl | 8 +- templates/repo/issue/new_form.tmpl | 4 +- .../repo/issue/view_content/comments.tmpl | 179 ++++++------------ templates/shared/user/authorlink.tmpl | 3 + templates/shared/user/avatarlink.tmpl | 3 + templates/shared/user/namelink.tmpl | 3 + 7 files changed, 76 insertions(+), 128 deletions(-) create mode 100644 templates/shared/user/authorlink.tmpl create mode 100644 templates/shared/user/avatarlink.tmpl create mode 100644 templates/shared/user/namelink.tmpl diff --git a/templates/org/team/teams.tmpl b/templates/org/team/teams.tmpl index 49407ef194..ade5a7a0e5 100644 --- a/templates/org/team/teams.tmpl +++ b/templates/org/team/teams.tmpl @@ -32,9 +32,7 @@
{{range .Members}} - - {{avatar .}} - + {{template "shared/user/avatarlink" .}} {{end}}
diff --git a/templates/repo/diff/comments.tmpl b/templates/repo/diff/comments.tmpl index 6a581ba04a..6228c8d380 100644 --- a/templates/repo/diff/comments.tmpl +++ b/templates/repo/diff/comments.tmpl @@ -5,9 +5,7 @@ {{if .OriginalAuthor }} {{else}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} {{end}}
@@ -27,9 +25,7 @@ {{else}} - - {{.Poster.GetDisplayName}} - + {{template "shared/user/namelink" .Poster}} {{$.root.i18n.Tr "repo.issues.commented_at" (.HashTag|Escape) $createdStr | Safe}} {{end}} diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 9e6a69f71a..f9ae1c433c 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -8,9 +8,7 @@
- - {{avatar .SignedUser}} - + {{template "shared/user/avatarlink" .SignedUser}}
diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 359efeced4..1b64a91e27 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -17,7 +17,7 @@ {{if .OriginalAuthor }} {{else}} - + {{avatar .Poster}} {{end}} @@ -96,11 +96,9 @@ {{else if eq .Type 1}}
{{svg "octicon-dot-fill"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{if .Issue.IsPull }} {{$.i18n.Tr "repo.pulls.reopened_at" .EventTag $createdStr | Safe}} {{else}} @@ -111,11 +109,9 @@ {{else if eq .Type 2}}
{{svg "octicon-circle-slash"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{if .Issue.IsPull }} {{$.i18n.Tr "repo.pulls.closed_at" .EventTag $createdStr | Safe}} {{else}} @@ -126,11 +122,9 @@ {{else if eq .Type 28}}
{{svg "octicon-git-merge"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$link := printf "%s/commit/%s" $.Repository.HTMLURL ($.Issue.PullRequest.MergedCommitID|PathEscape)}} {{if eq $.Issue.PullRequest.Status 3}} {{$.i18n.Tr "repo.issues.manually_pull_merged_at" ($link|Escape) (ShortSha $.Issue.PullRequest.MergedCommitID) ($.BaseTarget|Escape) $createdStr | Str2html}} @@ -155,12 +149,10 @@ {{ $createdStr:= TimeSinceUnix .CreatedUnix $.i18n.Lang }}
{{svg "octicon-bookmark"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} {{if eq .RefAction 3}}{{end}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr $refTr (.EventTag|Escape) $createdStr (.RefCommentHTMLURL|Escape) $refFrom | Safe}} {{if eq .RefAction 3}}{{end}} @@ -172,11 +164,9 @@ {{else if eq .Type 4}}
{{svg "octicon-bookmark"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.commit_ref_at" .EventTag $createdStr | Safe}}
@@ -188,11 +178,9 @@ {{if or .AddedLabels .RemovedLabels}}
{{svg "octicon-tag"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{if and .AddedLabels (not .RemovedLabels)}} {{$.i18n.TrN (len .AddedLabels) "repo.issues.add_label" "repo.issues.add_labels" (RenderLabels .AddedLabels) $createdStr | Safe}} {{else if and (not .AddedLabels) .RemovedLabels}} @@ -206,11 +194,9 @@ {{else if eq .Type 8}}
{{svg "octicon-milestone"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{if gt .OldMilestoneID 0}}{{if gt .MilestoneID 0}}{{$.i18n.Tr "repo.issues.change_milestone_at" (.OldMilestone.Name|Escape) (.Milestone.Name|Escape) $createdStr | Safe}}{{else}}{{$.i18n.Tr "repo.issues.remove_milestone_at" (.OldMilestone.Name|Escape) $createdStr | Safe}}{{end}}{{else if gt .MilestoneID 0}}{{$.i18n.Tr "repo.issues.add_milestone_at" (.Milestone.Name|Escape) $createdStr | Safe}}{{end}}
@@ -219,11 +205,9 @@ {{svg "octicon-person"}} {{if gt .AssigneeID 0}} {{if .RemovedAssignee}} - - {{avatar .Assignee}} - + {{template "shared/user/avatarlink" .Assignee}} - {{.Assignee.GetDisplayName}} + {{.Assignee.GetDisplayName}} {{ if eq .Poster.ID .Assignee.ID }} {{$.i18n.Tr "repo.issues.remove_self_assignment" $createdStr | Safe}} {{ else }} @@ -231,11 +215,9 @@ {{ end }} {{else}} - - {{avatar .Assignee}} - + {{template "shared/user/avatarlink" .Assignee}} - {{.Assignee.GetDisplayName}} + {{template "shared/user/authorlink" .Assignee}} {{if eq .Poster.ID .AssigneeID}} {{$.i18n.Tr "repo.issues.self_assign_at" $createdStr | Safe}} {{else}} @@ -248,44 +230,36 @@ {{else if eq .Type 10}}
{{svg "octicon-pencil"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.change_title_at" (.OldTitle|RenderEmoji) (.NewTitle|RenderEmoji) $createdStr | Safe}}
{{else if eq .Type 11}}
{{svg "octicon-git-branch"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.delete_branch_at" (.OldRef|Escape) $createdStr | Safe}}
{{else if eq .Type 12}}
{{svg "octicon-clock"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.start_tracking_history" $createdStr | Safe}}
{{else if eq .Type 13}}
{{svg "octicon-clock"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.stop_tracking_history" $createdStr | Safe}} {{ template "repo/issue/view_content/comments_delete_time" Dict "ctx" $ "comment" . }} @@ -297,11 +271,9 @@ {{else if eq .Type 14}}
{{svg "octicon-clock"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.add_time_history" $createdStr | Safe}} {{ template "repo/issue/view_content/comments_delete_time" Dict "ctx" $ "comment" . }} @@ -313,33 +285,27 @@ {{else if eq .Type 15}}
{{svg "octicon-clock"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.cancel_tracking_history" $createdStr | Safe}}
{{else if eq .Type 16}}
{{svg "octicon-clock"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.due_date_added" .Content $createdStr | Safe}}
{{else if eq .Type 17}}
{{svg "octicon-clock"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$parsedDeadline := .Content | ParseDeadline}} {{$.i18n.Tr "repo.issues.due_date_modified" (index $parsedDeadline 0) (index $parsedDeadline 1) $createdStr | Safe}} @@ -347,22 +313,18 @@ {{else if eq .Type 18}}
{{svg "octicon-clock"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.due_date_remove" .Content $createdStr | Safe}}
{{else if eq .Type 19}}
{{svg "octicon-package-dependents"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.dependency.added_dependency" $createdStr | Safe}} {{if .DependentIssue}} @@ -383,11 +345,9 @@ {{else if eq .Type 20}}
{{svg "octicon-package-dependents"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.dependency.removed_dependency" $createdStr | Safe}} {{if .DependentIssue}} @@ -424,7 +384,7 @@ {{if $.Repository.OriginalURL}} ({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}} {{else}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{end}} {{if eq .Review.Type 1}} @@ -455,7 +415,7 @@ {{if $.Repository.OriginalURL}} ({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}} {{else}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{end}} {{$.i18n.Tr "repo.issues.review.left_comment" | Safe}} @@ -583,7 +543,7 @@ {{if $.Repository.OriginalURL}} ({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}} {{else}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{end}} {{$.i18n.Tr "repo.issues.commented_at" (.HashTag|Escape) $createdSubStr | Safe}} @@ -668,17 +628,15 @@ {{else if eq .Type 23}}
{{svg "octicon-lock"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} {{ if .Content }} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.lock_with_reason" .Content $createdStr | Safe}} {{ else }} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.lock_no_reason" $createdStr | Safe}} {{ end }} @@ -686,33 +644,28 @@ {{else if eq .Type 24}}
{{svg "octicon-key"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$.i18n.Tr "repo.issues.unlock_comment" $createdStr | Safe}}
{{else if eq .Type 25}}
{{svg "octicon-git-branch"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.Name}} + {{.Poster.Name}} {{$.i18n.Tr "repo.pulls.change_target_branch_at" (.OldRef|Escape) (.NewRef|Escape) $createdStr | Safe}}
{{else if eq .Type 26}}
{{svg "octicon-clock"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} + {{$.i18n.Tr "repo.issues.del_time_history" $createdStr | Safe}}
@@ -723,11 +676,9 @@ {{else if eq .Type 27}}
{{svg "octicon-eye"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{if (gt .AssigneeID 0)}} {{if .RemovedAssignee}} {{if eq .PosterID .AssigneeID}} @@ -751,7 +702,7 @@
{{svg "octicon-repo-push"}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{ if .IsForcePush }} {{$.i18n.Tr "repo.issues.force_push_codes" ($.Issue.PullRequest.HeadBranch|Escape) (ShortSha .OldCommit) (($.Issue.Repo.CommitLink .OldCommit)|Escape) (ShortSha .NewCommit) (($.Issue.Repo.CommitLink .NewCommit)|Escape) $createdStr | Safe}} {{else}} @@ -766,11 +717,9 @@ {{if not $.UnitProjectsGlobalDisabled}}
{{svg "octicon-project"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{if gt .OldProjectID 0}} {{if gt .ProjectID 0}} {{$.i18n.Tr "repo.issues.change_project_at" (.OldProject.Title|Escape) (.Project.Title|Escape) $createdStr | Safe}} @@ -791,7 +740,7 @@ {{svg "octicon-x" 16}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{$reviewerName := ""}} {{if eq .Review.OriginalAuthor ""}} {{$reviewerName = .Review.Reviewer.Name}} @@ -825,11 +774,9 @@ {{else if eq .Type 33}}
{{svg "octicon-git-branch"}} - - {{avatar .Poster}} - + {{template "shared/user/avatarlink" .Poster}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{if and .OldRef .NewRef}} {{$.i18n.Tr "repo.issues.change_ref_at" (.OldRef|Escape) (.NewRef|Escape) $createdStr | Safe}} {{else if .OldRef}} @@ -843,7 +790,7 @@
{{svg "octicon-git-merge" 16}} - {{.Poster.GetDisplayName}} + {{template "shared/user/authorlink" .Poster}} {{if eq .Type 34}}{{$.i18n.Tr "repo.pulls.auto_merge_newly_scheduled_comment" $createdStr | Safe}} {{else}}{{$.i18n.Tr "repo.pulls.auto_merge_canceled_schedule_comment" $createdStr | Safe}}{{end}} diff --git a/templates/shared/user/authorlink.tmpl b/templates/shared/user/authorlink.tmpl new file mode 100644 index 0000000000..81c2a4ed5e --- /dev/null +++ b/templates/shared/user/authorlink.tmpl @@ -0,0 +1,3 @@ + + {{.GetDisplayName}} + diff --git a/templates/shared/user/avatarlink.tmpl b/templates/shared/user/avatarlink.tmpl new file mode 100644 index 0000000000..40f5ee7129 --- /dev/null +++ b/templates/shared/user/avatarlink.tmpl @@ -0,0 +1,3 @@ + + {{avatar .}} + diff --git a/templates/shared/user/namelink.tmpl b/templates/shared/user/namelink.tmpl new file mode 100644 index 0000000000..25dff36a78 --- /dev/null +++ b/templates/shared/user/namelink.tmpl @@ -0,0 +1,3 @@ + + {{.GetDisplayName}} +