Skip to content

Commit 094263d

Browse files
adelowotechknowlogick
authored andcommitted
Show email if the authenticated user owns the profile page being requested for (#4981)
* Show email if the authenticated user owns the profile page being requested for. Also removed `setting.UI.ShowUserEmail` as it's documentation says it only controls the email setting on the explore page * fix current user check... This prevents a panic as a user must be signed in before ctx.User is called * fix panic in tests * try to fix tests * Update year * Test CI fail * Revert change * User 3 is not allowed to authorize * Set user2 email to be private * Change to user4 in explore page as user2 now has private email option set
1 parent ff2be17 commit 094263d

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

integrations/setting_test.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestSettingShowUserEmailExplore(t *testing.T) {
2525
htmlDoc := NewHTMLParser(t, resp.Body)
2626
assert.Contains(t,
2727
htmlDoc.doc.Find(".ui.user.list").Text(),
28-
"user2@example.com",
28+
"user4@example.com",
2929
)
3030

3131
setting.UI.ShowUserEmail = false
@@ -35,7 +35,7 @@ func TestSettingShowUserEmailExplore(t *testing.T) {
3535
htmlDoc = NewHTMLParser(t, resp.Body)
3636
assert.NotContains(t,
3737
htmlDoc.doc.Find(".ui.user.list").Text(),
38-
"user2@example.com",
38+
"user4@example.com",
3939
)
4040

4141
setting.UI.ShowUserEmail = showUserEmail
@@ -61,12 +61,23 @@ func TestSettingShowUserEmailProfile(t *testing.T) {
6161
req = NewRequest(t, "GET", "/user2")
6262
resp = session.MakeRequest(t, req, http.StatusOK)
6363
htmlDoc = NewHTMLParser(t, resp.Body)
64-
assert.NotContains(t,
64+
// Should contain since this user owns the profile page
65+
assert.Contains(t,
6566
htmlDoc.doc.Find(".user.profile").Text(),
6667
"user2@example.com",
6768
)
6869

6970
setting.UI.ShowUserEmail = showUserEmail
71+
72+
session = loginUser(t, "user4")
73+
req = NewRequest(t, "GET", "/user2")
74+
resp = session.MakeRequest(t, req, http.StatusOK)
75+
htmlDoc = NewHTMLParser(t, resp.Body)
76+
assert.NotContains(t,
77+
htmlDoc.doc.Find(".user.profile").Text(),
78+
"user2@example.com",
79+
)
80+
7081
}
7182

7283
func TestSettingLandingPage(t *testing.T) {

models/fixtures/user.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
name: user2
2222
full_name: " < U<se>r Tw<o > >< "
2323
email: user2@example.com
24+
keep_email_private: true
2425
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
2526
type: 0 # individual
2627
salt: ZogKvWdyEx

routers/user/profile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func Profile(ctx *context.Context) {
237237
}
238238
}
239239

240-
ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail
240+
ctx.Data["ShowUserEmail"] = len(ctxUser.Email) > 0 && ctx.IsSigned && (!ctxUser.KeepEmailPrivate || ctxUser.ID == ctx.User.ID)
241241

242242
ctx.HTML(200, tplProfile)
243243
}

templates/user/profile.tmpl

+1-1
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 and $.ShowUserEmail .Owner.Email .IsSigned (not .Owner.KeepEmailPrivate)}}
25+
{{if .ShowUserEmail }}
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)