Skip to content

Commit 934dd41

Browse files
michaelkuhnlunny
authored andcommitted
Make SHOW_USER_EMAIL also apply to profiles (#2258)
The e-mail address is currently only hidden from the explore page.
1 parent 7907786 commit 934dd41

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

integrations/setting_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"net/http"
9+
"testing"
10+
11+
"code.gitea.io/gitea/modules/setting"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func TestSettingShowUserEmailExplore(t *testing.T) {
17+
prepareTestEnv(t)
18+
19+
showUserEmail := setting.UI.ShowUserEmail
20+
setting.UI.ShowUserEmail = true
21+
22+
session := loginUser(t, "user2")
23+
req := NewRequest(t, "GET", "/explore/users")
24+
resp := session.MakeRequest(t, req, http.StatusOK)
25+
htmlDoc := NewHTMLParser(t, resp.Body)
26+
assert.Contains(t,
27+
htmlDoc.doc.Find(".ui.user.list").Text(),
28+
29+
)
30+
31+
setting.UI.ShowUserEmail = false
32+
33+
req = NewRequest(t, "GET", "/explore/users")
34+
resp = session.MakeRequest(t, req, http.StatusOK)
35+
htmlDoc = NewHTMLParser(t, resp.Body)
36+
assert.NotContains(t,
37+
htmlDoc.doc.Find(".ui.user.list").Text(),
38+
39+
)
40+
41+
setting.UI.ShowUserEmail = showUserEmail
42+
}
43+
44+
func TestSettingShowUserEmailProfile(t *testing.T) {
45+
prepareTestEnv(t)
46+
47+
showUserEmail := setting.UI.ShowUserEmail
48+
setting.UI.ShowUserEmail = true
49+
50+
session := loginUser(t, "user2")
51+
req := NewRequest(t, "GET", "/user2")
52+
resp := session.MakeRequest(t, req, http.StatusOK)
53+
htmlDoc := NewHTMLParser(t, resp.Body)
54+
assert.Contains(t,
55+
htmlDoc.doc.Find(".user.profile").Text(),
56+
57+
)
58+
59+
setting.UI.ShowUserEmail = false
60+
61+
req = NewRequest(t, "GET", "/user2")
62+
resp = session.MakeRequest(t, req, http.StatusOK)
63+
htmlDoc = NewHTMLParser(t, resp.Body)
64+
assert.NotContains(t,
65+
htmlDoc.doc.Find(".user.profile").Text(),
66+
67+
)
68+
69+
setting.UI.ShowUserEmail = showUserEmail
70+
}

routers/user/profile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ func Profile(ctx *context.Context) {
219219
}
220220
}
221221

222+
ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail
223+
222224
ctx.HTML(200, tplProfile)
223225
}
224226

templates/user/profile.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{{if .Owner.Location}}
2323
<li><i class="octicon octicon-location"></i> {{.Owner.Location}}</li>
2424
{{end}}
25-
{{if or (and $.ShowUserEmail .Owner.Email .IsSigned) (and .Owner.Email .IsSigned (not .Owner.KeepEmailPrivate))}}
25+
{{if and $.ShowUserEmail .Owner.Email .IsSigned (not .Owner.KeepEmailPrivate)}}
2626
<li>
2727
<i class="octicon octicon-mail"></i>
2828
<a href="mailto:{{.Owner.Email}}" rel="nofollow">{{.Owner.Email}}</a>

0 commit comments

Comments
 (0)