From 4508380cf7937aef0bf6f99fe3eefb6c530e38e3 Mon Sep 17 00:00:00 2001 From: Wim Date: Wed, 8 May 2019 10:41:35 +0200 Subject: [PATCH] Show full name if DefaultShowFullName setting activated (#6710) Adds a new key DEFAULT_SHOW_FULL_NAME (default false) to the [ui] section. If enabled the full name will be shown (unless it's empty, then the default username will be used) --- custom/conf/app.ini.sample | 2 + .../doc/advanced/config-cheat-sheet.en-us.md | 1 + models/action.go | 16 ++++++ models/user.go | 10 ++++ modules/setting/setting.go | 2 + modules/templates/helper.go | 3 ++ templates/repo/diff/comments.tmpl | 2 +- templates/repo/issue/list.tmpl | 8 +-- templates/repo/issue/milestone_issues.tmpl | 8 +-- templates/repo/issue/new_form.tmpl | 4 +- templates/repo/issue/view_content.tmpl | 2 +- .../repo/issue/view_content/comments.tmpl | 52 +++++++++---------- .../repo/issue/view_content/sidebar.tmpl | 6 +-- templates/repo/issue/view_title.tmpl | 8 +-- templates/user/dashboard/feeds.tmpl | 2 +- templates/user/dashboard/issues.tmpl | 7 +-- 16 files changed, 84 insertions(+), 49 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 04b2b9f92e0..6f7844962b4 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -97,6 +97,8 @@ SHOW_USER_EMAIL = true DEFAULT_THEME = gitea ; All available themes. Allow users select personalized themes regardless of the value of `DEFAULT_THEME`. THEMES = gitea,arc-green +; Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. +DEFAULT_SHOW_FULL_NAME = false [ui.admin] ; Number of users that are displayed on one page diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 5c37f4f1c44..87a92eb60d3 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -85,6 +85,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `DEFAULT_THEME`: **gitea**: \[gitea, arc-green\]: Set the default theme for the Gitea install. - `THEMES`: **gitea,arc-green**: All available themes. Allow users select personalized themes regardless of the value of `DEFAULT_THEME`. +- `DEFAULT_SHOW_FULL_NAME`: false: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. ### UI - Admin (`ui.admin`) diff --git a/models/action.go b/models/action.go index b089870c741..01a6a91704e 100644 --- a/models/action.go +++ b/models/action.go @@ -144,6 +144,22 @@ func (a *Action) ShortActUserName() string { return base.EllipsisString(a.GetActUserName(), 20) } +// GetDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME +func (a *Action) GetDisplayName() string { + if setting.UI.DefaultShowFullName { + return a.GetActFullName() + } + return a.ShortActUserName() +} + +// GetDisplayNameTitle gets the action's display name used for the title (tooltip) based on DEFAULT_SHOW_FULL_NAME +func (a *Action) GetDisplayNameTitle() string { + if setting.UI.DefaultShowFullName { + return a.ShortActUserName() + } + return a.GetActFullName() +} + // GetActAvatar the action's user's avatar link func (a *Action) GetActAvatar() string { a.loadActUser() diff --git a/models/user.go b/models/user.go index 04fe36ffa06..a51f52afb9a 100644 --- a/models/user.go +++ b/models/user.go @@ -661,6 +661,16 @@ func (u *User) DisplayName() string { return u.Name } +// GetDisplayName returns full name if it's not empty and DEFAULT_SHOW_FULL_NAME is set, +// returns username otherwise. +func (u *User) GetDisplayName() string { + trimmed := strings.TrimSpace(u.FullName) + if len(trimmed) > 0 && setting.UI.DefaultShowFullName { + return trimmed + } + return u.Name +} + func gitSafeName(name string) string { return strings.TrimSpace(strings.NewReplacer("\n", "", "<", "", ">", "").Replace(name)) } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 692fb9820a9..687f01bc296 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -176,6 +176,7 @@ var ( ThemeColorMetaTag string MaxDisplayFileSize int64 ShowUserEmail bool + DefaultShowFullName bool DefaultTheme string Themes []string @@ -918,6 +919,7 @@ func NewContext() { ShowFooterTemplateLoadTime = Cfg.Section("other").Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool(true) UI.ShowUserEmail = Cfg.Section("ui").Key("SHOW_USER_EMAIL").MustBool(true) + UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false) HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt")) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 3176684d821..24a383252b6 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -63,6 +63,9 @@ func NewFuncMap() []template.FuncMap { "DisableGravatar": func() bool { return setting.DisableGravatar }, + "DefaultShowFullName": func() bool { + return setting.UI.DefaultShowFullName + }, "ShowFooterTemplateLoadTime": func() bool { return setting.ShowFooterTemplateLoadTime }, diff --git a/templates/repo/diff/comments.tmpl b/templates/repo/diff/comments.tmpl index 7e8588e60c8..1288886a61d 100644 --- a/templates/repo/diff/comments.tmpl +++ b/templates/repo/diff/comments.tmpl @@ -7,7 +7,7 @@
- {{.Poster.Name}} {{$.root.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}} + {{.Poster.GetDisplayName}} {{$.root.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}}
{{if and .Review}} {{if eq .Review.Type 0}} diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 86395415033..448ab1a757f 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -72,7 +72,7 @@
@@ -183,7 +183,7 @@
{{range .Assignees}}
- {{.Name}} + {{.GetDisplayName}}
{{end}}
@@ -228,9 +228,9 @@ {{ $timeStr := TimeSinceUnix .GetLastEventTimestamp $.Lang }} {{if gt .Poster.ID 0}} - {{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink .Poster.Name | Safe}} + {{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink (.Poster.GetDisplayName | Escape) | Safe}} {{else}} - {{$.i18n.Tr .GetLastEventLabelFake $timeStr .Poster.Name | Safe}} + {{$.i18n.Tr .GetLastEventLabelFake $timeStr (.Poster.GetDisplayName | Escape) | Safe}} {{end}} {{$tasks := .GetTasks}} diff --git a/templates/repo/issue/milestone_issues.tmpl b/templates/repo/issue/milestone_issues.tmpl index 44df0dd6253..738ac4b8161 100644 --- a/templates/repo/issue/milestone_issues.tmpl +++ b/templates/repo/issue/milestone_issues.tmpl @@ -74,7 +74,7 @@ @@ -166,7 +166,7 @@ {{range .Assignees}}
- {{.Name}} + {{.GetDisplayName}}
{{end}} @@ -204,9 +204,9 @@

{{if gt .Poster.ID 0}} - {{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink .Poster.Name | Safe}} + {{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink (.Poster.GetDisplayName|Escape) | Safe}} {{else}} - {{$.i18n.Tr .GetLastEventLabelFake $timeStr .Poster.Name | Safe}} + {{$.i18n.Tr .GetLastEventLabelFake $timeStr (.Poster.GetDisplayName|Escape) | Safe}} {{end}} {{$tasks := .GetTasks}} {{if gt $tasks 0}} diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 73b59e3cb83..99a68bc76ea 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -112,7 +112,7 @@ - {{.Name}} + {{.GetDisplayName}} {{end}} @@ -124,7 +124,7 @@ {{range .Assignees}} -  {{.Name}} +  {{.GetDisplayName}} {{end}} diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index cb58fbef63c..de9ffdb9306 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -17,7 +17,7 @@

- {{.Issue.Poster.Name}} {{.i18n.Tr "repo.issues.commented_at" .Issue.HashTag $createdStr | Safe}} + {{.Issue.Poster.GetDisplayName}} {{.i18n.Tr "repo.issues.commented_at" .Issue.HashTag $createdStr | Safe}} {{if not $.Repository.IsArchived}}
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) }} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index ac7e9a23326..6f562dc6b0f 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -14,7 +14,7 @@
- {{.Poster.Name}} {{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}} {{if not $.Repository.IsArchived}}
{{if gt .ShowTag 0}} @@ -78,7 +78,7 @@ - {{.Poster.Name}} {{$.i18n.Tr "repo.issues.reopened_at" .EventTag $createdStr | Safe}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.reopened_at" .EventTag $createdStr | Safe}}
{{else if eq .Type 2}}
@@ -86,7 +86,7 @@ - {{.Poster.Name}} {{$.i18n.Tr "repo.issues.closed_at" .EventTag $createdStr | Safe}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.closed_at" .EventTag $createdStr | Safe}}
{{else if eq .Type 4}}
@@ -94,7 +94,7 @@ - {{.Poster.Name}} {{$.i18n.Tr "repo.issues.commit_ref_at" .EventTag $createdStr | Safe}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.commit_ref_at" .EventTag $createdStr | Safe}}
@@ -108,7 +108,7 @@ - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{if .Content}}{{$.i18n.Tr "repo.issues.add_label_at" .Label.ForegroundColor .Label.Color (.Label.Name|Escape) $createdStr | Safe}}{{else}}{{$.i18n.Tr "repo.issues.remove_label_at" .Label.ForegroundColor .Label.Color (.Label.Name|Escape) $createdStr | Safe}}{{end}}
{{end}} @@ -118,7 +118,7 @@ - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{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}}
{{else if eq .Type 9}} @@ -130,11 +130,11 @@ - {{.Assignee.Name}} + {{.Assignee.GetDisplayName}} {{ if eq .Poster.ID .Assignee.ID }} {{$.i18n.Tr "repo.issues.remove_self_assignment" $createdStr | Safe}} {{ else }} - {{$.i18n.Tr "repo.issues.remove_assignee_at" .Poster.Name $createdStr | Safe}} + {{$.i18n.Tr "repo.issues.remove_assignee_at" (.Poster.GetDisplayName|Escape) $createdStr | Safe}} {{ end }} {{else}} @@ -142,11 +142,11 @@ - {{.Assignee.Name}} + {{.Assignee.GetDisplayName}} {{if eq .Poster.ID .AssigneeID}} {{$.i18n.Tr "repo.issues.self_assign_at" $createdStr | Safe}} {{else}} - {{$.i18n.Tr "repo.issues.add_assignee_at" .Poster.Name $createdStr | Safe}} + {{$.i18n.Tr "repo.issues.add_assignee_at" (.Poster.GetDisplayName|Escape) $createdStr | Safe}} {{end}} {{end}} @@ -158,7 +158,7 @@ - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.change_title_at" (.OldTitle|Escape) (.NewTitle|Escape) $createdStr | Safe}}
@@ -168,7 +168,7 @@ - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.delete_branch_at" (.CommitSHA|Escape) $createdStr | Safe}}
@@ -178,7 +178,7 @@ - {{.Poster.Name}} {{$.i18n.Tr "repo.issues.start_tracking_history" $createdStr | Safe}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.start_tracking_history" $createdStr | Safe}}
{{else if eq .Type 13}}
@@ -186,7 +186,7 @@ - {{.Poster.Name}} {{$.i18n.Tr "repo.issues.stop_tracking_history" $createdStr | Safe}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.stop_tracking_history" $createdStr | Safe}}
@@ -199,7 +199,7 @@ - {{.Poster.Name}} {{$.i18n.Tr "repo.issues.add_time_history" $createdStr | Safe}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.add_time_history" $createdStr | Safe}}
{{.Content}} @@ -211,7 +211,7 @@ - {{.Poster.Name}} {{$.i18n.Tr "repo.issues.cancel_tracking_history" $createdStr | Safe}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.cancel_tracking_history" $createdStr | Safe}}
{{else if eq .Type 16}}
@@ -219,7 +219,7 @@ - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.due_date_added" .Content $createdStr | Safe}}
@@ -229,7 +229,7 @@ - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.due_date_modified" (.Content | ParseDeadline) $createdStr | Safe}}
@@ -239,7 +239,7 @@ - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.due_date_remove" .Content $createdStr | Safe}}
@@ -250,7 +250,7 @@ - {{$.i18n.Tr "repo.issues.dependency.added_dependency" .Poster.HomeLink .Poster.Name $createdStr | Safe}} + {{$.i18n.Tr "repo.issues.dependency.added_dependency" .Poster.HomeLink (.Poster.GetDisplayName|Escape) $createdStr | Safe}}
@@ -264,7 +264,7 @@ - {{$.i18n.Tr "repo.issues.dependency.removed_dependency" .Poster.HomeLink .Poster.Name $createdStr | Safe}} + {{$.i18n.Tr "repo.issues.dependency.removed_dependency" .Poster.HomeLink (.Poster.GetDisplayName|Escape) $createdStr | Safe}}
@@ -277,7 +277,7 @@ - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{if eq .Review.Type 1}} {{$.i18n.Tr "repo.issues.review.approve" $createdStr | Safe}} {{else if eq .Review.Type 2}} @@ -335,7 +335,7 @@
- {{.Poster.Name}} + {{.Poster.GetDisplayName}} @@ -368,11 +368,11 @@ {{ if .Content }} - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.lock_with_reason" .Content $createdStr | Safe}} {{ else }} - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.lock_no_reason" $createdStr | Safe}} {{ end }} @@ -385,7 +385,7 @@ - {{.Poster.Name}} + {{.Poster.GetDisplayName}} {{$.i18n.Tr "repo.issues.unlock_comment" $createdStr | Safe}}
diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 1f5481530a7..4db5628faab 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -89,7 +89,7 @@ {{end}} {{end}}">
- {{.Name}} + {{.GetDisplayName}} {{end}} @@ -100,7 +100,7 @@
{{range .Issue.Assignees}} {{end}}
@@ -113,7 +113,7 @@
{{range .Participants}} - + {{end}}
diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index 641a7bf3db2..78c892fa4d5 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -27,19 +27,19 @@ {{if .Issue.IsPull}} {{if .Issue.PullRequest.HasMerged}} {{ $mergedStr:= TimeSinceUnix .Issue.PullRequest.MergedUnix $.Lang }} - {{.Issue.PullRequest.Merger.Name}} + {{.Issue.PullRequest.Merger.GetDisplayName}} {{$.i18n.Tr "repo.pulls.merged_title_desc" .NumCommits .HeadTarget .BaseTarget $mergedStr | Str2html}} {{else}} - {{.Issue.Poster.Name}} + {{.Issue.Poster.GetDisplayName}} {{$.i18n.Tr "repo.pulls.title_desc" .NumCommits .HeadTarget .BaseTarget | Str2html}} {{end}} {{else}} {{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.Lang }} {{if gt .Issue.Poster.ID 0}} - {{$.i18n.Tr "repo.issues.opened_by" $createdStr .Issue.Poster.HomeLink .Issue.Poster.Name | Safe}} + {{$.i18n.Tr "repo.issues.opened_by" $createdStr .Issue.Poster.HomeLink (.Issue.Poster.GetDisplayName|Escape) | Safe}} {{else}} - {{$.i18n.Tr "repo.issues.opened_by_fake" $createdStr .Issue.Poster.Name | Safe}} + {{$.i18n.Tr "repo.issues.opened_by_fake" $createdStr (.Issue.Poster.GetDisplayName|Escape) | Safe}} {{end}} ยท {{$.i18n.Tr "repo.issues.num_comments" .Issue.NumComments}} diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index ffc0db3317b..9c404c9fde2 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -8,7 +8,7 @@

{{if gt .ActUser.ID 0}} - {{.ShortActUserName}} + {{.GetDisplayName}} {{else}} {{.ShortActUserName}} {{end}} diff --git a/templates/user/dashboard/issues.tmpl b/templates/user/dashboard/issues.tmpl index 32733190984..b69509d7992 100644 --- a/templates/user/dashboard/issues.tmpl +++ b/templates/user/dashboard/issues.tmpl @@ -61,6 +61,7 @@

{{range .Issues}} + {{ $timeStr:= TimeSinceUnix .CreatedUnix $.Lang }}
  • {{if not $.RepoID}}{{.Repo.FullName}}{{end}}#{{.Index}}
    @@ -93,12 +94,12 @@

    {{if gt .Poster.ID 0}} - {{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink .Poster.Name | Safe}} + {{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink (.Poster.GetDisplayName|Escape) | Safe}} {{else}} - {{$.i18n.Tr .GetLastEventLabelFake $timeStr .Poster.Name | Safe}} + {{$.i18n.Tr .GetLastEventLabelFake $timeStr (.Poster.GetDisplayName|Escape) | Safe}} {{end}} {{if .Assignee}} - + {{end}}