diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 04b2b9f92e..6f7844962b 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 5c37f4f1c4..87a92eb60d 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 b089870c74..01a6a91704 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 04fe36ffa0..a51f52afb9 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 692fb9820a..687f01bc29 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 3176684d82..24a383252b 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 7e8588e60c..1288886a61 100644 --- a/templates/repo/diff/comments.tmpl +++ b/templates/repo/diff/comments.tmpl @@ -7,7 +7,7 @@
{{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 73b59e3cb8..99a68bc76e 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 cb58fbef63..de9ffdb930 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -17,7 +17,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 3273319098..b69509d799 100644 --- a/templates/user/dashboard/issues.tmpl +++ b/templates/user/dashboard/issues.tmpl @@ -61,6 +61,7 @@
{{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}}