Repository: wagtail/wagtail

Issue:
NameEmailSettingsPanel should be titled "Name" when email management is disabled
<!--
Found a bug? Please fill out the sections below. 👍
-->

### Issue Summary

As NameEmailForm handles working without email, NameEmailSettingsPanel should be titled "Name" when email management is disabled


### Steps to Reproduce

1. `WAGTAIL_EMAIL_MANAGEMENT_ENABLED = False` in your settings
2. Go to your account



Discussion:
Can confirm this issue.

<img width="1113" alt="Screenshot 2023-09-26 at 5 22 17 am" src="https://github.com/wagtail/wagtail/assets/1396140/0b3ce297-033e-4d96-ac99-385ae226beb9">

With `WAGTAIL_EMAIL_MANAGEMENT_ENABLED = False`. Observe the email is no longer editable but the panel title still says 'Name and Email'.
<img width="1121" alt="Screenshot 2023-09-26 at 5 22 46 am" src="https://github.com/wagtail/wagtail/assets/1396140/32f7fc64-992c-486e-b033-8b34a41e700b">

## Potential fix

In [`wagtail/admin/views/account.py`](https://github.com/wagtail/wagtail/blob/main/wagtail/admin/views/account.py#L139) we could make the title dynamic as follows;

```py
class NameEmailSettingsPanel(BaseSettingsPanel):
    name = "name_email"
    # title = gettext_lazy("Name and Email")
    order = 100
    form_class = NameEmailForm

    @property
    def title(self):
        from wagtail.admin.views.account import email_management_enabled

        if email_management_enabled():
            return gettext_lazy("Name and Email")
        return gettext_lazy("name")
```

I will flag this as a good first issue, this is quite simple to validate manually but will need unit tests for a PR.
# Want to claim

I would like to work on this issue. I have reviewed the problem, including the issue summary and the proposed solution in the comment, and I believe I can address it effectively.

I will make the necessary code changes in the `wagtail/admin/views/account.py` file to dynamically set the panel title based on the `WAGTAIL_EMAIL_MANAGEMENT_ENABLED` setting.

I will also add unit tests to ensure that the issue is resolved correctly.


@FatGuyy go for it.  Just put up a PR when you're ready. 
Please remember to include unit tests. 
I am super new, it might take a bit of time and a bit of help(I'll ask in slack [new contributors]), but will get it done!
Some note about where to put unit tests.

See the file [`wagtail/admin/tests/test_account_management.py`](https://github.com/wagtail/wagtail/blob/main/wagtail/admin/tests/test_account_management.py).

## 1 - test the existing title (with the default setting) works

Maybe add a line to the `test_account_view` test - https://github.com/wagtail/wagtail/blob/main/wagtail/admin/tests/test_account_management.py#L247

Something that checks the response contains the expected title.


## 2 - test the setting enabled makes the title different

See https://github.com/wagtail/wagtail/blob/main/wagtail/admin/tests/test_account_management.py#L326

You can add something after the line `self.assertNotContains(response, "id_name_email-email")` that checks the right title exists and the wrong title does not exist in the response.





Resolving patch:
diff --git a/wagtail/admin/views/account.py b/wagtail/admin/views/account.py
--- a/wagtail/admin/views/account.py
+++ b/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 @@ def render(self):
 
 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"


Test patch:
diff --git a/wagtail/admin/tests/test_account_management.py b/wagtail/admin/tests/test_account_management.py
--- a/wagtail/admin/tests/test_account_management.py
+++ b/wagtail/admin/tests/test_account_management.py
@@ -273,6 +273,9 @@ def test_account_view(self):
         # 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 @@ def test_with_email_management_disabled(self):
         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