Browse Source

Fix NameEmailSettingsPanel when WAGTAIL_EMAIL_MANAGEMENT_ENABLED = False

Ensure the panel title reflects the content inside (with or without email)
Fixes #10937
FatGuyy 1 year ago
parent
commit
09c125189d

+ 1 - 0
CHANGELOG.txt

@@ -41,6 +41,7 @@ Changelog
  * Fix: Allow locale selection when creating a page at the root level (Sage Abdullah)
  * Fix: Ensure the admin login template correctly displays all `non_fields_errors` for any custom form validation (Sébastien Corbin)
  * Fix: Ensure 'mark as active' label in workflow bulk action set active form can be translated (Rohit Sharma)
+ * Fix: Ensure the panel title for a user's settings correctly reflects the `WAGTAIL_EMAIL_MANAGEMENT_ENABLED` setting by not showing 'email' if disabled (Omkar Jadhav)
  * Docs: Document `WAGTAILADMIN_BASE_URL` on "Integrating Wagtail into a Django project" page (Shreshth Srivastava)
  * Docs: Replace incorrect screenshot for authors listing on tutorial (Shreshth Srivastava)
  * Docs: Add documentation for building non-model-based choosers using the _queryish_ library (Matt Westcott)

+ 1 - 0
CONTRIBUTORS.md

@@ -735,6 +735,7 @@
 * Neeraj Yetheendran
 * TopDevPros
 * Sandra Ashipala
+* Omkar Jadhav
 
 ## Translators
 

+ 1 - 0
docs/releases/5.2.md

@@ -56,6 +56,7 @@ depth: 1
  * Allow locale selection when creating a page at the root level (Sage Abdullah)
  * Ensure the admin login template correctly displays all `non_fields_errors` for any custom form validation (Sébastien Corbin)
  * Ensure 'mark as active' label in workflow bulk action set active form can be translated (Rohit Sharma)
+ * Ensure the panel title for a user's settings correctly reflects the `WAGTAIL_EMAIL_MANAGEMENT_ENABLED` setting by not showing 'email' if disabled (Omkar Jadhav)
 
 ### Documentation
 

+ 8 - 0
wagtail/admin/tests/test_account_management.py

@@ -273,6 +273,9 @@ class TestAccountSection(WagtailTestUtils, TestCase, TestAccountSectionUtilsMixi
         # Form media should be included on the page
         self.assertContains(response, "vendor/colorpicker.js")
 
+        # Check if the default title exists
+        self.assertContains(response, "Name and Email")
+
     def test_change_name_post(self):
         response = self.post_form(
             {
@@ -332,6 +335,11 @@ class TestAccountSection(WagtailTestUtils, TestCase, TestAccountSectionUtilsMixi
         self.assertTemplateUsed(response, "wagtailadmin/account/account.html")
         self.assertNotContains(response, "id_name_email-email")
 
+        # Check if the default title does not exist
+        self.assertNotContains(response, "Name and Email")
+        # When WAGTAIL_EMAIL_MANAGEMENT_ENABLED=False, Check if title is "Name"
+        self.assertContains(response, "Name")
+
     @override_settings(WAGTAIL_PASSWORD_MANAGEMENT_ENABLED=False)
     def test_account_view_with_password_management_disabled(self):
         # Get account page

+ 9 - 1
wagtail/admin/views/account.py

@@ -1,4 +1,5 @@
 from collections import OrderedDict
+from functools import cached_property
 
 from django.conf import settings
 from django.contrib import messages
@@ -138,10 +139,17 @@ class BaseSettingsPanel:
 
 class NameEmailSettingsPanel(BaseSettingsPanel):
     name = "name_email"
-    title = gettext_lazy("Name and Email")
     order = 100
     form_class = NameEmailForm
 
+    @cached_property
+    def title(self):
+        from wagtail.admin.views.account import email_management_enabled
+
+        if email_management_enabled():
+            return _("Name and Email")
+        return _("Name")
+
 
 class AvatarSettingsPanel(BaseSettingsPanel):
     name = "avatar"