Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DWPF-746 Preferred name #440

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/templates/includes/profile_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a class="profile-link"
href="{% url 'profile-view' peoplefinder_profile.slug %}">
<div class="profile-details">
<span class="salutation">Hi {{ peoplefinder_profile.first_name|truncatechars:25 }}</span>
<span class="salutation">Hi {{ peoplefinder_profile.preferred_first_name|truncatechars:25 }}</span>
<span class="profile-prompt"><span>View your profile</span>
{% if peoplefinder_profile.profile_completion < 100 %}
<span>({{ peoplefinder_profile.profile_completion|floatformat:0 }}% complete)</span>
Expand Down
4 changes: 2 additions & 2 deletions src/e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
recreate_db,
)


os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"


Expand Down Expand Up @@ -158,7 +157,8 @@ def user(django_db_blocker, django_user_model):
john_user_profile = Person.objects.get(user=user)
super_user_profile = Person.objects.get(user__username="testsuperuser")

john_user_profile.preferred_first_name = "J"
john_user_profile.manager = super_user_profile
john_user_profile.save(update_fields=["manager"])
john_user_profile.save(update_fields=["preferred_first_name", "manager"])

return user
12 changes: 12 additions & 0 deletions src/peoplefinder/forms/profile_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Meta:
model = Person
fields = [
"first_name",
"preferred_first_name",
"last_name",
"pronouns",
"photo",
Expand All @@ -34,6 +35,12 @@ def __init__(self, *args, **kwargs):

first_name_label = self.fields["first_name"].label
self.fields["first_name"].label = ""
self.fields["first_name"].disabled = True

preferred_first_name_label = (
self.fields["preferred_first_name"].label + " (optional)"
)
self.fields["preferred_first_name"].label = ""

last_name_label = self.fields["last_name"].label
self.fields["last_name"].label = ""
Expand All @@ -54,6 +61,11 @@ def __init__(self, *args, **kwargs):
legend_size=Size.MEDIUM,
legend=first_name_label,
),
Fieldset(
"preferred_first_name",
legend_size=Size.MEDIUM,
legend=preferred_first_name_label,
),
Fieldset(
"last_name",
legend_size=Size.MEDIUM,
Expand Down
37 changes: 37 additions & 0 deletions src/peoplefinder/migrations/0109_person_preferred_first_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.1.10 on 2023-09-05 13:06

from django.db import migrations, models


def populate_preferred_first_name(apps, schema_editor):
Person = apps.get_model("peoplefinder", "Person")
Person.objects.update(preferred_first_name=models.F("first_name"))


class Migration(migrations.Migration):
dependencies = [
("peoplefinder", "0108_alter_person_contact_email_alter_person_email_and_more"),
]

operations = [
migrations.AddField(
model_name="person",
name="preferred_first_name",
field=models.CharField(
help_text="How you would prefer to be called, for example a shortened version of your name. This will appear on your profile.",
max_length=200,
null=True,
),
),
migrations.RunPython(
populate_preferred_first_name, reverse_code=migrations.RunPython.noop
),
migrations.AlterField(
model_name="person",
name="preferred_first_name",
field=models.CharField(
help_text="How you would prefer to be called, for example a shortened version of your name. This will appear on your profile.",
max_length=200,
),
),
]
39 changes: 35 additions & 4 deletions src/peoplefinder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,30 @@ class PersonIndexManager(ModelIndexManager):
autocomplete=True,
boost=7.0,
),
IndexedField(
"first_name",
fuzzy=True,
tokenized=True,
explicit=True,
autocomplete=True,
boost=7.0,
),
IndexedField(
"preferred_first_name",
fuzzy=True,
tokenized=True,
explicit=True,
autocomplete=True,
boost=7.0,
),
IndexedField(
"last_name",
fuzzy=True,
tokenized=True,
explicit=True,
autocomplete=True,
boost=7.0,
),
IndexedField(
"email",
keyword=True,
Expand Down Expand Up @@ -519,9 +543,16 @@ class RemoteWorking(models.TextChoices):

first_name = models.CharField(
max_length=200,
# help_text=(
# "If you enter a preferred name below, this name will be hidden to others"
# ),
help_text=(
"If you enter a preferred name below, this name will be hidden to others"
),
)
preferred_first_name = models.CharField(
max_length=200,
help_text=(
"How you would prefer to be called, for example a shortened "
"version of your name. This will appear on your profile."
),
)
last_name = models.CharField(
max_length=200,
Expand Down Expand Up @@ -700,7 +731,7 @@ def is_stale(self):

@property
def full_name(self) -> str:
return f"{self.first_name} {self.last_name}"
return f"{self.preferred_first_name} {self.last_name}"

@property
def preferred_email(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/peoplefinder/services/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class PersonAuditLogSerializer(AuditLogSerializer):
# the audit log code when we update the model. The tests will execute this code so
# it should fail locally and in CI. If you need to update this number you can call
# `len(Person._meta.get_fields())` in a shell to get the new value.
assert len(Person._meta.get_fields()) == 48, (
assert len(Person._meta.get_fields()) == 49, (
"It looks like you have updated the `Person` model. Please make sure you have"
" updated `PersonAuditLogSerializer.serialize` to reflect any field changes."
)
Expand Down
3 changes: 3 additions & 0 deletions src/peoplefinder/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def django_db_setup(django_db_setup, django_db_blocker):

team_software = Team.objects.get(slug="software")

user_john_smith.profile.preferred_first_name = "J"
user_john_smith.profile.save(update_fields=["preferred_first_name"])

user_john_smith.profile.roles.get_or_create(
team=team_software,
job_title="Software Engineer",
Expand Down
3 changes: 1 addition & 2 deletions src/peoplefinder/test/views/api/test_person.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from rest_framework.reverse import reverse
from rest_framework.test import APIClient


url_name = "person-api-people-list"
test_url = f"http://testserver{reverse(url_name)}"

Expand Down Expand Up @@ -100,7 +99,7 @@ def test_person_returned_with_authentication(self):
assert len(response.json()["results"]) == 1
person_returned = response.json()["results"][0]

assert person_returned["full_name"] == "John Smith"
assert person_returned["full_name"] == "J Smith"
assert person_returned["formatted_roles"] == ["Software Engineer in Software"]
roles = person_returned["roles"]
assert isinstance(roles, list)
Expand Down
2 changes: 1 addition & 1 deletion src/peoplefinder/test/views/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def test_profile_edit_personal_view(state):

form = PersonalProfileEditForm(
{
"first_name": "Jane",
"preferred_first_name": "Jane",
"last_name": "Smith",
"pronouns": "she/her",
"name_pronunciation": "Jay-n Smi-th",
Expand Down