forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix profile page email display, respect settings (go-gitea#23747)
Always respect the `setting.UI.ShowUserEmail` and `KeepEmailPrivate` setting. * It doesn't make sense to show user's own E-mail to themself. * Always hide the E-mail if KeepEmailPrivate=true, then the user could know how their profile page looks like for others. * Revert the `setting.UI.ShowUserEmail` change from go-gitea#4981 . This setting is used to control the E-mail display, not only for the user list page. ps: the incorrect `<div .../>` tag on the profile page has been fixed by go-gitea#23748 together, so this PR becomes simpler.
- Loading branch information
1 parent
7e294ad
commit 6706ac2
Showing
2 changed files
with
31 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,38 +45,49 @@ func TestSettingShowUserEmailProfile(t *testing.T) { | |
defer tests.PrepareTestEnv(t)() | ||
|
||
showUserEmail := setting.UI.ShowUserEmail | ||
|
||
// user1: keep_email_private = false, user2: keep_email_private = true | ||
|
||
setting.UI.ShowUserEmail = true | ||
|
||
session := loginUser(t, "user2") | ||
req := NewRequest(t, "GET", "/user2") | ||
// user1 can see self | ||
session := loginUser(t, "user1") | ||
req := NewRequest(t, "GET", "/user1") | ||
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 | ||
assert.Contains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]") | ||
|
||
// user1 can not see user2 | ||
req = NewRequest(t, "GET", "/user2") | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
// Should contain since this user owns the profile page | ||
assert.Contains(t, | ||
htmlDoc.doc.Find(".user.profile").Text(), | ||
"[email protected]", | ||
) | ||
// Should not contain even if the user visits their own profile page | ||
assert.NotContains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]") | ||
|
||
setting.UI.ShowUserEmail = showUserEmail | ||
// user2 can see user1 | ||
session = loginUser(t, "user2") | ||
req = NewRequest(t, "GET", "/user1") | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
assert.Contains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]") | ||
|
||
session = loginUser(t, "user4") | ||
// user2 can not see self | ||
session = loginUser(t, "user2") | ||
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]", | ||
) | ||
assert.NotContains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]") | ||
|
||
setting.UI.ShowUserEmail = false | ||
|
||
// user1 can not see self | ||
session = loginUser(t, "user1") | ||
req = NewRequest(t, "GET", "/user1") | ||
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 | ||
} | ||
|
||
func TestSettingLandingPage(t *testing.T) { | ||
|