Browse Source

Make SHOW_USER_EMAIL also apply to profiles (#2258)

The e-mail address is currently only hidden from the explore page.
Michael Kuhn 2 years ago
parent
commit
934dd41fa6
3 changed files with 73 additions and 1 deletions
  1. 70 0
      integrations/setting_test.go
  2. 2 0
      routers/user/profile.go
  3. 1 1
      templates/user/profile.tmpl

+ 70 - 0
integrations/setting_test.go

@@ -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
+		"user2@example.com",
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
+		"user2@example.com",
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
+		"user2@example.com",
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
+		"user2@example.com",
67
+	)
68
+
69
+	setting.UI.ShowUserEmail = showUserEmail
70
+}

+ 2 - 0
routers/user/profile.go

@@ -219,6 +219,8 @@ func Profile(ctx *context.Context) {
219 219
 		}
220 220
 	}
221 221
 
222
+	ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail
223
+
222 224
 	ctx.HTML(200, tplProfile)
223 225
 }
224 226
 

+ 1 - 1
templates/user/profile.tmpl

@@ -22,7 +22,7 @@
22 22
 							{{if .Owner.Location}}
23 23
 								<li><i class="octicon octicon-location"></i> {{.Owner.Location}}</li>
24 24
 							{{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)}}
26 26
 								<li>
27 27
 									<i class="octicon octicon-mail"></i>
28 28
 									<a href="mailto:{{.Owner.Email}}" rel="nofollow">{{.Owner.Email}}</a>