Skip to content

Commit 9f7eb16

Browse files
committed
Show full name if DefaultShowFullName setting activated
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)
1 parent cbf8538 commit 9f7eb16

File tree

16 files changed

+84
-49
lines changed

16 files changed

+84
-49
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ SHOW_USER_EMAIL = true
9797
DEFAULT_THEME = gitea
9898
; All available themes. Allow users select personalized themes regardless of the value of `DEFAULT_THEME`.
9999
THEMES = gitea,arc-green
100+
; Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used.
101+
DEFAULT_SHOW_FULL_NAME = false
100102

101103
[ui.admin]
102104
; Number of users that are displayed on one page

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
8585
- `DEFAULT_THEME`: **gitea**: \[gitea, arc-green\]: Set the default theme for the Gitea install.
8686
- `THEMES`: **gitea,arc-green**: All available themes. Allow users select personalized themes
8787
regardless of the value of `DEFAULT_THEME`.
88+
- `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.
8889

8990
### UI - Admin (`ui.admin`)
9091

models/action.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ func (a *Action) ShortActUserName() string {
143143
return base.EllipsisString(a.GetActUserName(), 20)
144144
}
145145

146+
// GetDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME
147+
func (a *Action) GetDisplayName() string {
148+
if setting.UI.DefaultShowFullName {
149+
return a.GetActFullName()
150+
}
151+
return a.ShortActUserName()
152+
}
153+
154+
// GetDisplayNameTitle gets the action's display name used for the title (tooltip) based on DEFAULT_SHOW_FULL_NAME
155+
func (a *Action) GetDisplayNameTitle() string {
156+
if setting.UI.DefaultShowFullName {
157+
return a.ShortActUserName()
158+
}
159+
return a.GetActFullName()
160+
}
161+
146162
// GetActAvatar the action's user's avatar link
147163
func (a *Action) GetActAvatar() string {
148164
a.loadActUser()

models/user.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,16 @@ func (u *User) DisplayName() string {
657657
return u.Name
658658
}
659659

660+
// GetDisplayName returns full name if it's not empty and DEFAULT_SHOW_FULL_NAME is set,
661+
// returns username otherwise.
662+
func (u *User) GetDisplayName() string {
663+
trimmed := strings.TrimSpace(u.FullName)
664+
if len(trimmed) > 0 && setting.UI.DefaultShowFullName {
665+
return trimmed
666+
}
667+
return u.Name
668+
}
669+
660670
func gitSafeName(name string) string {
661671
return strings.TrimSpace(strings.NewReplacer("\n", "", "<", "", ">", "").Replace(name))
662672
}

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ var (
175175
ThemeColorMetaTag string
176176
MaxDisplayFileSize int64
177177
ShowUserEmail bool
178+
DefaultShowFullName bool
178179
DefaultTheme string
179180
Themes []string
180181

@@ -903,6 +904,7 @@ func NewContext() {
903904
ShowFooterTemplateLoadTime = Cfg.Section("other").Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool(true)
904905

905906
UI.ShowUserEmail = Cfg.Section("ui").Key("SHOW_USER_EMAIL").MustBool(true)
907+
UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
906908

907909
HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))
908910

modules/templates/helper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ func NewFuncMap() []template.FuncMap {
6161
"DisableGravatar": func() bool {
6262
return setting.DisableGravatar
6363
},
64+
"DefaultShowFullName": func() bool {
65+
return setting.UI.DefaultShowFullName
66+
},
6467
"ShowFooterTemplateLoadTime": func() bool {
6568
return setting.ShowFooterTemplateLoadTime
6669
},

templates/repo/diff/comments.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</a>
88
<div class="content">
99
<div class="ui top attached header">
10-
<span class="text grey"><a {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.Name}}</a> {{$.root.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}}</span>
10+
<span class="text grey"><a {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.GetDisplayName}}</a> {{$.root.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}}</span>
1111
<div class="ui right actions">
1212
{{if and .Review}}
1313
{{if eq .Review.Type 0}}

templates/repo/issue/list.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<div class="menu">
7373
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}">{{.i18n.Tr "repo.issues.filter_assginee_no_select"}}</a>
7474
{{range .Assignees}}
75-
<a class="{{if eq $.AssigneeID .ID}}active selected{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{.ID}}"><img src="{{.RelAvatarLink}}"> {{.Name}}</a>
75+
<a class="{{if eq $.AssigneeID .ID}}active selected{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{.ID}}"><img src="{{.RelAvatarLink}}"> {{.GetDisplayName}}</a>
7676
{{end}}
7777
</div>
7878
</div>
@@ -183,7 +183,7 @@
183183
</div>
184184
{{range .Assignees}}
185185
<div class="item issue-action" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/assignee">
186-
<img src="{{.RelAvatarLink}}"> {{.Name}}
186+
<img src="{{.RelAvatarLink}}"> {{.GetDisplayName}}
187187
</div>
188188
{{end}}
189189
</div>
@@ -228,9 +228,9 @@
228228
{{ $timeStr := TimeSinceUnix .GetLastEventTimestamp $.Lang }}
229229

230230
{{if gt .Poster.ID 0}}
231-
{{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink .Poster.Name | Safe}}
231+
{{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink (.Poster.GetDisplayName | Escape) | Safe}}
232232
{{else}}
233-
{{$.i18n.Tr .GetLastEventLabelFake $timeStr .Poster.Name | Safe}}
233+
{{$.i18n.Tr .GetLastEventLabelFake $timeStr (.Poster.GetDisplayName | Escape) | Safe}}
234234
{{end}}
235235

236236
{{$tasks := .GetTasks}}

templates/repo/issue/milestone_issues.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<div class="menu">
7575
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}">{{.i18n.Tr "repo.issues.filter_assginee_no_select"}}</a>
7676
{{range .Assignees}}
77-
<a class="{{if eq $.AssigneeID .ID}}active selected{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{$.SelectLabels}}&assignee={{.ID}}"><img src="{{.RelAvatarLink}}"> {{.Name}}</a>
77+
<a class="{{if eq $.AssigneeID .ID}}active selected{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{$.SelectLabels}}&assignee={{.ID}}"><img src="{{.RelAvatarLink}}"> {{.GetDisplayName}}</a>
7878
{{end}}
7979
</div>
8080
</div>
@@ -166,7 +166,7 @@
166166
</div>
167167
{{range .Assignees}}
168168
<div class="item issue-action" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/assignee">
169-
<img src="{{.RelAvatarLink}}"> {{.Name}}
169+
<img src="{{.RelAvatarLink}}"> {{.GetDisplayName}}
170170
</div>
171171
{{end}}
172172
</div>
@@ -204,9 +204,9 @@
204204

205205
<p class="desc">
206206
{{if gt .Poster.ID 0}}
207-
{{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink .Poster.Name | Safe}}
207+
{{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink (.Poster.GetDisplayName|Escape) | Safe}}
208208
{{else}}
209-
{{$.i18n.Tr .GetLastEventLabelFake $timeStr .Poster.Name | Safe}}
209+
{{$.i18n.Tr .GetLastEventLabelFake $timeStr (.Poster.GetDisplayName|Escape) | Safe}}
210210
{{end}}
211211
{{$tasks := .GetTasks}}
212212
{{if gt $tasks 0}}

templates/repo/issue/new_form.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
<a class="item" href="#" data-id="{{.ID}}" data-id-selector="#assignee_{{.ID}}">
113113
<span class="octicon"></span>
114114
<span class="text">
115-
<img class="ui avatar image" src="{{.RelAvatarLink}}"> {{.Name}}
115+
<img class="ui avatar image" src="{{.RelAvatarLink}}"> {{.GetDisplayName}}
116116
</span>
117117
</a>
118118
{{end}}
@@ -124,7 +124,7 @@
124124
</span>
125125
{{range .Assignees}}
126126
<a style="padding: 5px;color:rgba(0, 0, 0, 0.87);" class="hide item" id="assignee_{{.ID}}" href="{{$.RepoLink}}/issues?assignee={{.ID}}">
127-
<img class="ui avatar image" src="{{.RelAvatarLink}}" style="vertical-align: middle;">&nbsp;{{.Name}}
127+
<img class="ui avatar image" src="{{.RelAvatarLink}}" style="vertical-align: middle;">&nbsp;{{.GetDisplayName}}
128128
</a>
129129
{{end}}
130130
</div>

templates/repo/issue/view_content.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</a>
1818
<div class="content">
1919
<div class="ui top attached header">
20-
<span class="text grey"><a {{if gt .Issue.Poster.ID 0}}href="{{.Issue.Poster.HomeLink}}"{{end}}>{{.Issue.Poster.Name}}</a> {{.i18n.Tr "repo.issues.commented_at" .Issue.HashTag $createdStr | Safe}}</span>
20+
<span class="text grey"><a {{if gt .Issue.Poster.ID 0}}href="{{.Issue.Poster.HomeLink}}"{{end}}>{{.Issue.Poster.GetDisplayName}}</a> {{.i18n.Tr "repo.issues.commented_at" .Issue.HashTag $createdStr | Safe}}</span>
2121
{{if not $.Repository.IsArchived}}
2222
<div class="ui right actions">
2323
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) }}

0 commit comments

Comments
 (0)