Skip to content

Make SHOW_USER_EMAIL also apply to profiles #2258

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 1 commit into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions integrations/setting_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package integrations

import (
"net/http"
"testing"

"code.gitea.io/gitea/modules/setting"

"github.com/stretchr/testify/assert"
)

func TestSettingShowUserEmailExplore(t *testing.T) {
prepareTestEnv(t)

showUserEmail := setting.UI.ShowUserEmail
setting.UI.ShowUserEmail = true

session := loginUser(t, "user2")
req := NewRequest(t, "GET", "/explore/users")
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
assert.Contains(t,
htmlDoc.doc.Find(".ui.user.list").Text(),
"[email protected]",
)

setting.UI.ShowUserEmail = false

req = NewRequest(t, "GET", "/explore/users")
resp = session.MakeRequest(t, req, http.StatusOK)
htmlDoc = NewHTMLParser(t, resp.Body)
assert.NotContains(t,
htmlDoc.doc.Find(".ui.user.list").Text(),
"[email protected]",
)

setting.UI.ShowUserEmail = showUserEmail
}

func TestSettingShowUserEmailProfile(t *testing.T) {
prepareTestEnv(t)

showUserEmail := setting.UI.ShowUserEmail
setting.UI.ShowUserEmail = true

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

setting.UI.ShowUserEmail = false

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]",
)

setting.UI.ShowUserEmail = showUserEmail
}
2 changes: 2 additions & 0 deletions routers/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ func Profile(ctx *context.Context) {
}
}

ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail

ctx.HTML(200, tplProfile)
}

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