mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-17 16:25:55 +00:00
fix: respect UI DEFAULT_SHOW_FULL_NAME setting in email From: headers (#9307)
Changes email's `From` field to respect the server's `DEFAULT_SHOW_FULL_NAME` setting, bringing consistency between seeing an email from a user, opening the related issue, and seeing a different name in Forgejo's web UI. Manually tested by varying the `DEFAULT_SHOW_FULL_NAME` server property, enabling and disabling it:  Fixes #9149. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). - Performed manual testing with ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [ ] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9307 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
This commit is contained in:
parent
548cd0c059
commit
89e0323351
2 changed files with 24 additions and 11 deletions
|
@ -575,7 +575,7 @@ func fromDisplayName(u *user_model.User) string {
|
|||
if setting.MailService.FromDisplayNameFormatTemplate != nil {
|
||||
var ctx bytes.Buffer
|
||||
err := setting.MailService.FromDisplayNameFormatTemplate.Execute(&ctx, map[string]any{
|
||||
"DisplayName": u.DisplayName(),
|
||||
"DisplayName": u.GetDisplayName(),
|
||||
"AppName": setting.AppName,
|
||||
"Domain": setting.Domain,
|
||||
})
|
||||
|
|
|
@ -497,24 +497,35 @@ func TestFromDisplayName(t *testing.T) {
|
|||
defer test.MockVariableValue(&setting.MailService, &setting.Mailer{FromDisplayNameFormatTemplate: template})()
|
||||
|
||||
tests := []struct {
|
||||
userDisplayName string
|
||||
fromDisplayName string
|
||||
userDisplayName string
|
||||
fromDisplayName string
|
||||
defaultShowFullName bool
|
||||
}{{
|
||||
userDisplayName: "test",
|
||||
fromDisplayName: "test",
|
||||
userDisplayName: "test",
|
||||
fromDisplayName: "test",
|
||||
defaultShowFullName: true,
|
||||
}, {
|
||||
userDisplayName: "Hi Its <Mee>",
|
||||
fromDisplayName: "Hi Its <Mee>",
|
||||
userDisplayName: "Hi Its <Mee>",
|
||||
fromDisplayName: "Hi Its <Mee>",
|
||||
defaultShowFullName: true,
|
||||
}, {
|
||||
userDisplayName: "Æsir",
|
||||
fromDisplayName: "=?utf-8?q?=C3=86sir?=",
|
||||
userDisplayName: "Æsir",
|
||||
fromDisplayName: "=?utf-8?q?=C3=86sir?=",
|
||||
defaultShowFullName: true,
|
||||
}, {
|
||||
userDisplayName: "new😀user",
|
||||
fromDisplayName: "=?utf-8?q?new=F0=9F=98=80user?=",
|
||||
userDisplayName: "new😀user",
|
||||
fromDisplayName: "=?utf-8?q?new=F0=9F=98=80user?=",
|
||||
defaultShowFullName: true,
|
||||
}, {
|
||||
userDisplayName: "new😀user",
|
||||
fromDisplayName: "tmp",
|
||||
defaultShowFullName: false,
|
||||
}}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.userDisplayName, func(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.UI.DefaultShowFullName, tc.defaultShowFullName)()
|
||||
|
||||
user := &user_model.User{FullName: tc.userDisplayName, Name: "tmp"}
|
||||
got := fromDisplayName(user)
|
||||
assert.Equal(t, tc.fromDisplayName, got)
|
||||
|
@ -522,6 +533,8 @@ func TestFromDisplayName(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("template with all available vars", func(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.UI.DefaultShowFullName, true)()
|
||||
|
||||
template, err = texttmpl.New("mailFrom").Parse("{{ .DisplayName }} (by {{ .AppName }} on [{{ .Domain }}])")
|
||||
require.NoError(t, err)
|
||||
defer test.MockVariableValue(&setting.MailService, &setting.Mailer{FromDisplayNameFormatTemplate: template})()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue