Skip to content

Commit 5e1bd8a

Browse files
n0toosesilverwind
andauthored
Show visibility status of email in own profile (#23900)
I've heard many reports of users getting scared when they see their own email address for their own profile, as they believe that the email field is also visible to other users. Currently, using Incognito mode or going over the Settings is the only "reasonable" way to verify this from the perspective of the user. A locked padlock should be enough to indicate that the email is not visible to anyone apart from the user and the admins. An unlocked padlock is used if the email address is only shown to authenticated users. Some additional string-related changes in the Settings were introduced as well to ensure consistency, and the comments in the relevant tests were improved so as to allow for easier modifications in the future. --- #### Screenshot (EDIT: Scroll down for more up-to-date screenshots) ***Please remove this section before merging.*** ![image](https://user-images.githubusercontent.com/30193966/229572425-909894aa-a7d5-4bf3-92d3-23b1921dcc90.png) This lock should only appear if the email address is explicitly hidden using the `Hide Email Address` setting. The change was originally tested on top of and designed for the Forgejo fork, but I don't expect any problems to arise from this and I don't think that a documentation-related change is strictly necessary. --------- Co-authored-by: silverwind <[email protected]>
1 parent 3037922 commit 5e1bd8a

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

options/locale/locale_en-US.ini

+6-4
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ unfollow = Unfollow
548548
heatmap.loading = Loading Heatmap…
549549
user_bio = Biography
550550
disabled_public_activity = This user has disabled the public visibility of the activity.
551+
email_visibility.limited = Your email address is visible to all authenticated users
552+
email_visibility.private = Your email address is only visible to you and administrators
551553

552554
form.name_reserved = The username '%s' is reserved.
553555
form.name_pattern_not_allowed = The pattern '%s' is not allowed in a username.
@@ -661,7 +663,7 @@ add_email_success = The new email address has been added.
661663
email_preference_set_success = Email preference has been set successfully.
662664
add_openid_success = The new OpenID address has been added.
663665
keep_email_private = Hide Email Address
664-
keep_email_private_popup = Your email address will be hidden from other users.
666+
keep_email_private_popup = Your email address will only be visible to you and the administrators
665667
openid_desc = OpenID lets you delegate authentication to an external provider.
666668
667669
manage_ssh_keys = Manage SSH Keys
@@ -842,9 +844,9 @@ email_notifications.andyourown = And Your Own Notifications
842844

843845
visibility = User visibility
844846
visibility.public = Public
845-
visibility.public_tooltip = Visible to all users
847+
visibility.public_tooltip = Visible to everyone
846848
visibility.limited = Limited
847-
visibility.limited_tooltip = Visible to logged in users only
849+
visibility.limited_tooltip = Visible to authenticated users only
848850
visibility.private = Private
849851
visibility.private_tooltip = Visible only to organization members
850852

@@ -2421,7 +2423,7 @@ settings.permission = Permissions
24212423
settings.repoadminchangeteam = Repository admin can add and remove access for teams
24222424
settings.visibility = Visibility
24232425
settings.visibility.public = Public
2424-
settings.visibility.limited = Limited (Visible to logged in users only)
2426+
settings.visibility.limited = Limited (Visible to authenticated users only)
24252427
settings.visibility.limited_shortname = Limited
24262428
settings.visibility.private = Private (Visible only to organization members)
24272429
settings.visibility.private_shortname = Private

templates/user/profile.tmpl

+19-1
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,29 @@
3030
{{if .Owner.Location}}
3131
<li>{{svg "octicon-location"}} {{.Owner.Location}}</li>
3232
{{end}}
33-
{{if .ShowUserEmail}}
33+
{{if (eq .SignedUserName .Owner.Name)}}
3434
<li>
3535
{{svg "octicon-mail"}}
3636
<a href="mailto:{{.Owner.Email}}" rel="nofollow">{{.Owner.Email}}</a>
37+
<a href="{{AppSubUrl}}/user/settings#keep-email-private">
38+
{{if .ShowUserEmail}}
39+
<i class="ui right" data-tooltip-content="{{.locale.Tr "user.email_visibility.limited"}}">
40+
{{svg "octicon-unlock"}}
41+
</i>
42+
{{else}}
43+
<i class="ui right" data-tooltip-content="{{.locale.Tr "user.email_visibility.private"}}">
44+
{{svg "octicon-lock"}}
45+
</i>
46+
{{end}}
47+
</a>
3748
</li>
49+
{{else}}
50+
{{if .ShowUserEmail}}
51+
<li>
52+
{{svg "octicon-mail"}}
53+
<a href="mailto:{{.Owner.Email}}" rel="nofollow">{{.Owner.Email}}</a>
54+
</li>
55+
{{end}}
3856
{{end}}
3957
{{if .Owner.Website}}
4058
<li>

tests/integration/setting_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,42 @@ func TestSettingShowUserEmailProfile(t *testing.T) {
5050

5151
setting.UI.ShowUserEmail = true
5252

53-
// user1 can see self
53+
// user1 can see own visible email
5454
session := loginUser(t, "user1")
5555
req := NewRequest(t, "GET", "/user1")
5656
resp := session.MakeRequest(t, req, http.StatusOK)
5757
htmlDoc := NewHTMLParser(t, resp.Body)
5858
assert.Contains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]")
5959

60-
// user1 can not see user2
60+
// user1 can not see user2's hidden email
6161
req = NewRequest(t, "GET", "/user2")
6262
resp = session.MakeRequest(t, req, http.StatusOK)
6363
htmlDoc = NewHTMLParser(t, resp.Body)
64-
// Should not contain even if the user visits their own profile page
64+
// Should only contain if the user visits their own profile page
6565
assert.NotContains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]")
6666

67-
// user2 can see user1
67+
// user2 can see user1's visible email
6868
session = loginUser(t, "user2")
6969
req = NewRequest(t, "GET", "/user1")
7070
resp = session.MakeRequest(t, req, http.StatusOK)
7171
htmlDoc = NewHTMLParser(t, resp.Body)
7272
assert.Contains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]")
7373

74-
// user2 can not see self
74+
// user2 can see own hidden email
7575
session = loginUser(t, "user2")
7676
req = NewRequest(t, "GET", "/user2")
7777
resp = session.MakeRequest(t, req, http.StatusOK)
7878
htmlDoc = NewHTMLParser(t, resp.Body)
79-
assert.NotContains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]")
79+
assert.Contains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]")
8080

8181
setting.UI.ShowUserEmail = false
8282

83-
// user1 can not see self
83+
// user1 can see own (now hidden) email
8484
session = loginUser(t, "user1")
8585
req = NewRequest(t, "GET", "/user1")
8686
resp = session.MakeRequest(t, req, http.StatusOK)
8787
htmlDoc = NewHTMLParser(t, resp.Body)
88-
assert.NotContains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]")
88+
assert.Contains(t, htmlDoc.doc.Find(".user.profile").Text(), "[email protected]")
8989

9090
setting.UI.ShowUserEmail = showUserEmail
9191
}

0 commit comments

Comments
 (0)