From c3653e0eaa0f61fedf243d4bcf1adb2a478e100b Mon Sep 17 00:00:00 2001
From: 0ko <0ko@noreply.codeberg.org>
Date: Mon, 18 Nov 2024 17:06:38 +0500
Subject: [PATCH] ui: don't display email in profile settings when hidden
---
templates/user/settings/profile.tmpl | 10 ++++++----
tests/integration/setting_test.go | 21 +++++++++++++++++++++
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl
index 56b5666cae..a007380387 100644
--- a/templates/user/settings/profile.tmpl
+++ b/templates/user/settings/profile.tmpl
@@ -51,10 +51,12 @@
-
-
-
{{.SignedUser.Email}}
-
+ {{if not .SignedUser.KeepEmailPrivate}}
+
+
+
{{.SignedUser.Email}}
+
+ {{end}}
diff --git a/tests/integration/setting_test.go b/tests/integration/setting_test.go
index 29615b3ecf..4677770fed 100644
--- a/tests/integration/setting_test.go
+++ b/tests/integration/setting_test.go
@@ -1,4 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
+// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
@@ -156,3 +157,23 @@ func TestSettingSecurityAuthSource(t *testing.T) {
assert.Contains(t, resp.Body.String(), `gitlab-active`)
assert.Contains(t, resp.Body.String(), `gitlab-inactive`)
}
+
+func TestSettingShowUserEmailSettings(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ // user1: keep_email_private = false, user2: keep_email_private = true
+
+ // user1 can see own visible email
+ session := loginUser(t, "user1")
+ req := NewRequest(t, "GET", "/user/settings")
+ resp := session.MakeRequest(t, req, http.StatusOK)
+ htmlDoc := NewHTMLParser(t, resp.Body)
+ assert.Contains(t, htmlDoc.doc.Find("#signed-user-email").Text(), "user1@example.com")
+
+ // user2 cannot see own hidden email
+ session = loginUser(t, "user2")
+ req = NewRequest(t, "GET", "/user/settings")
+ resp = session.MakeRequest(t, req, http.StatusOK)
+ htmlDoc = NewHTMLParser(t, resp.Body)
+ assert.NotContains(t, htmlDoc.doc.Find("#signed-user-email").Text(), "user2@example.com")
+}