Skip to content

Show email if the authenticated user owns the profile page being requested for #4981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 19, 2019
Merged
17 changes: 14 additions & 3 deletions integrations/setting_test.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ func TestSettingShowUserEmailExplore(t *testing.T) {
htmlDoc := NewHTMLParser(t, resp.Body)
assert.Contains(t,
htmlDoc.doc.Find(".ui.user.list").Text(),
"user2@example.com",
"user4@example.com",
)

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

setting.UI.ShowUserEmail = showUserEmail
@@ -61,12 +61,23 @@ func TestSettingShowUserEmailProfile(t *testing.T) {
req = NewRequest(t, "GET", "/user2")
resp = session.MakeRequest(t, req, http.StatusOK)
htmlDoc = NewHTMLParser(t, resp.Body)
assert.NotContains(t,
// Should contain since this user owns the profile page
assert.Contains(t,
htmlDoc.doc.Find(".user.profile").Text(),
"[email protected]",
)

setting.UI.ShowUserEmail = showUserEmail

session = loginUser(t, "user4")
req = NewRequest(t, "GET", "/user2")
resp = session.MakeRequest(t, req, http.StatusOK)
htmlDoc = NewHTMLParser(t, resp.Body)
assert.NotContains(t,
htmlDoc.doc.Find(".user.profile").Text(),
"[email protected]",
)

}

func TestSettingLandingPage(t *testing.T) {
1 change: 1 addition & 0 deletions models/fixtures/user.yml
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
name: user2
full_name: " < U<se>r Tw<o > >< "
email: [email protected]
keep_email_private: true
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: ZogKvWdyEx
2 changes: 1 addition & 1 deletion routers/user/profile.go
Original file line number Diff line number Diff line change
@@ -237,7 +237,7 @@ func Profile(ctx *context.Context) {
}
}

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

ctx.HTML(200, tplProfile)
}
2 changes: 1 addition & 1 deletion templates/user/profile.tmpl
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
{{if .Owner.Location}}
<li><i class="octicon octicon-location"></i> {{.Owner.Location}}</li>
{{end}}
{{if and $.ShowUserEmail .Owner.Email .IsSigned (not .Owner.KeepEmailPrivate)}}
{{if .ShowUserEmail }}
<li>
<i class="octicon octicon-mail"></i>
<a href="mailto:{{.Owner.Email}}" rel="nofollow">{{.Owner.Email}}</a>