Skip to content

Commit

Permalink
Update edit profile main email (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
CamLamb authored Sep 13, 2023
1 parent c3455e3 commit 2fad5a3
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 34 deletions.
13 changes: 2 additions & 11 deletions src/peoplefinder/forms/profile_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class ContactProfileEditForm(forms.ModelForm):
class Meta:
model = Person
fields = [
"email",
"contact_email",
"primary_phone_number",
"secondary_phone_number",
Expand All @@ -148,11 +147,8 @@ def __init__(self, *args, **kwargs):
self.request_user = kwargs.pop("request_user", None)
super().__init__(*args, **kwargs)

email_label = self.fields["email"].label
self.fields["email"].label = ""
self.fields["email"].disabled = True

contact_email_label = self.fields["contact_email"].label + " (optional)"
contact_email_label = self.fields["contact_email"].label
self.fields["contact_email"].required = True
self.fields["contact_email"].label = ""

primary_phone_number_label = self.fields["primary_phone_number"].label
Expand All @@ -166,11 +162,6 @@ def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Fieldset(
"email",
legend_size=Size.MEDIUM,
legend=email_label,
),
Fieldset(
"contact_email",
legend_size=Size.MEDIUM,
Expand Down
26 changes: 26 additions & 0 deletions src/peoplefinder/migrations/0110_person_contact_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.1.10 on 2023-09-05 13:06

from django.db import migrations, models


def populate_contact_email(apps, schema_editor):
"""
Set the contact email to the email address if it is blank.
"""
Person = apps.get_model("peoplefinder", "Person")
Person.objects.exclude(contact_email__isnull=False).update(
contact_email=models.F("email"),
)


class Migration(migrations.Migration):
dependencies = [
("peoplefinder", "0109_person_preferred_first_name"),
]

operations = [
migrations.RunPython(
populate_contact_email,
reverse_code=migrations.RunPython.noop,
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 4.1.10 on 2023-09-13 14:47

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("peoplefinder", "0110_person_contact_email"),
]

operations = [
migrations.AlterField(
model_name="person",
name="contact_email",
field=models.EmailField(
blank=True,
help_text="The work email you want people to contact you on.",
max_length=254,
null=True,
verbose_name="Email address",
),
),
migrations.AlterField(
model_name="person",
name="primary_phone_number",
field=models.CharField(
blank=True,
help_text="Enter the country's dialling code in place of the first 0. The UK's dialling code is +44.",
max_length=42,
null=True,
verbose_name="Phone number",
),
),
migrations.AlterField(
model_name="person",
name="secondary_phone_number",
field=models.CharField(
blank=True,
help_text="Enter the country's dialling code in place of the first 0. The UK's dialling code is +44.",
max_length=160,
null=True,
verbose_name="Alternative phone number",
),
),
]
23 changes: 12 additions & 11 deletions src/peoplefinder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,29 +577,30 @@ class RemoteWorking(models.TextChoices):
blank=True,
)
contact_email = models.EmailField(
"Preferred email address",
"Email address",
null=True,
blank=True,
help_text=(
"Complete if you want to show a different email address on your"
" profile for example a jobshare or Private Office mailbox. Do not"
" enter a personal email address, or work email address that is not"
" safe for official information."
),
help_text="The work email you want people to contact you on.",
)
primary_phone_number = models.CharField(
"Contact number",
"Phone number",
max_length=42,
null=True,
blank=True,
help_text="Include your country dialling code.",
help_text=(
"Enter the country's dialling code in place of the first 0. The"
" UK's dialling code is +44."
),
)
secondary_phone_number = models.CharField(
"Alternative contact number",
"Alternative phone number",
max_length=160,
null=True,
blank=True,
help_text="Include your country dialling code.",
help_text=(
"Enter the country's dialling code in place of the first 0. The"
" UK's dialling code is +44."
),
)
town_city_or_region = models.CharField(
"Town, city or region",
Expand Down
6 changes: 4 additions & 2 deletions src/peoplefinder/services/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ class PersonService:
ProfileSections.CONTACT: {
"edit_section": EditSections.CONTACT,
"fields": [
("contact_email", "Preferred email"),
("primary_phone_number", "Contact number"),
("contact_email", "Email"),
("primary_phone_number", "Phone number"),
("secondary_phone_number", "Alternative phone number"),
],
},
ProfileSections.ROLE: {
Expand Down Expand Up @@ -216,6 +217,7 @@ def create_user_profile(self, user: User) -> Person:
preferred_first_name=user.first_name,
last_name=user.last_name,
email=user.email,
contact_email=user.email,
login_count=1,
)

Expand Down
12 changes: 6 additions & 6 deletions src/peoplefinder/test/views/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,13 @@ def test_profile_edit_contact_view(state):
response = state.client.get(view_url)

assert response.status_code == 200
assert state.person.contact_email is None
assert state.person.contact_email == "[email protected]"
assert state.person.primary_phone_number is None
assert state.person.secondary_phone_number is None

form = ContactProfileEditForm(
{
"contact_email": "jane.smith@test.com",
"contact_email": "jane.smith123@test.com",
"primary_phone_number": "01234567890",
"secondary_phone_number": "09876543210",
},
Expand All @@ -445,7 +445,7 @@ def test_profile_edit_contact_view(state):

assert response.status_code == 302
assert response.url == view_url
assert state.person.contact_email == "jane.smith@test.com"
assert state.person.contact_email == "jane.smith123@test.com"
assert state.person.primary_phone_number == "01234567890"
assert state.person.secondary_phone_number == "09876543210"

Expand All @@ -462,9 +462,9 @@ def test_profile_edit_teams_view(state):
response = state.client.get(view_url)

assert response.status_code == 200
assert state.person.contact_email is None
assert state.person.primary_phone_number is None
assert state.person.secondary_phone_number is None
assert state.person.grade is None
assert state.person.manager is None
assert state.person.do_not_work_for_dit is False

grade = Grade.objects.all().first()

Expand Down
6 changes: 3 additions & 3 deletions src/peoplefinder/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class ProfileSections(models.TextChoices):


class EditSections(models.TextChoices):
PERSONAL = "personal", "Personal Details"
CONTACT = "contact", "Contact Details"
PERSONAL = "personal", "Personal details"
CONTACT = "contact", "Contact details"
TEAMS = "teams", "Team and role"
LOCATION = "location", "Location and working patterns"
SKILLS = "skills", "Skills, Networks and Interests"
SKILLS = "skills", "Skills, networks and interests"
ADMIN = "admin", "Administer profile"
2 changes: 1 addition & 1 deletion src/peoplefinder/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def get_context_data(self, **kwargs):
edit_sections.remove(EditSections.ADMIN)

context.update(
page_title=f"Edit profile: {self.edit_section.label}",
page_title=f"Edit profile: {self.edit_section.label.lower()}",
current_edit_section=self.edit_section,
edit_sections=edit_sections,
profile_slug=profile.slug,
Expand Down

0 comments on commit 2fad5a3

Please sign in to comment.