Skip to content

Commit

Permalink
[GH-174] - Allow all "whitepages email addresses" to appear for users…
Browse files Browse the repository at this point in the history
… on all screens (#175)

* feat: Show all available employee emails
* [Bot] Update version to 2.3.0

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
soufianerafik and github-actions[bot] authored Jan 29, 2025
1 parent 2a9e35e commit 93bc02e
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion husky_directory/models/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Config(DirectoryBaseModel.Config):
class Person(DirectoryBaseModel):
name: str
phone_contacts: PhoneContactMethods = PhoneContactMethods()
email: Optional[str]
emails: List[str] = []
box_number: Optional[str]
departments: List[UWDepartmentRole] = []
sort_key: Optional[str]
Expand Down
2 changes: 1 addition & 1 deletion husky_directory/models/vcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ class VCard(DirectoryBaseModel):
display_name: str
titles: List[str] = []
departments: List[str] = []
email: Optional[str]
emails: List[str] = []
phones: List[VCardPhone] = []
addresses: List[str] = []
12 changes: 7 additions & 5 deletions husky_directory/services/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def _translate_student_attributes(
student: StudentPersonAffiliation,
result_in_progress: Person,
) -> NoReturn:
result_in_progress.email = student.directory_listing.email
# Supports multiple emails: students have one, employees may have many.
# Assigning student email as a single-item list for consistency.
if student.directory_listing.email:
result_in_progress.emails = [student.directory_listing.email]
result_in_progress.departments.extend(
UWDepartmentRole(
title=student.directory_listing.class_level, department=dept
Expand All @@ -58,11 +61,10 @@ def _translate_student_attributes(
def _translate_employee_attributes(
employee: EmployeePersonAffiliation, result_in_progress: Person
) -> NoReturn:
# Email will usually be the same, but just in case, we'll prefer the
# employee email address and not overwrite it with the student's if
# it's already set.
# Display all available employee emails
# More info on: https://github.com/UWIT-IAM/uw-husky-directory/issues/174
if employee.directory_listing.emails:
result_in_progress.email = employee.directory_listing.emails[0]
result_in_progress.emails = employee.directory_listing.emails

result_in_progress.box_number = employee.mail_stop
result_in_progress.departments.extend(
Expand Down
4 changes: 2 additions & 2 deletions husky_directory/services/vcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def set_employee_vcard_attrs(vcard: VCard, person: PersonOutput) -> NoReturn:
# If student email exists, we prefer employee email (in case they are different),
# so we overwrite.
if employee.emails:
vcard.email = employee.emails[0]
vcard.emails = employee.emails

if employee.addresses:
vcard.addresses = [
Expand All @@ -95,7 +95,7 @@ def set_student_vcard_attrs(vcard: VCard, person: PersonOutput) -> NoReturn:
VCardPhone(types=[VCardPhoneType.home], value=student.phone)
)
if student.email:
vcard.email = student.email
vcard.emails.append(student.email)

if student.class_level:
vcard.titles.append(student.class_level)
Expand Down
4 changes: 3 additions & 1 deletion husky_directory/templates/full_result.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h4>{{ person['name'] }}</h4>
<ul class="dir-listing">
<li>{{ person['email'] }}</li>
{% for email in person['emails'] %}
<li>{{ email }}</li>
{% endfor %}
{% for contact_method, numbers in
person['phone_contacts'].items() %}
{% if numbers|length %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
{% set phone = data['phone_contacts']['phones']|first %}
{% if phone %}{{ phone }}{% endif %}
</td>
<td valign="top">{{ data['email'] }}&nbsp;</td>
<td valign="top">
{% for email in data['emails'] %}
{{ email }}{% if not loop.last %}, {% endif %}
{% endfor %}
&nbsp;
</td>
<td>
{% set form_id = "more-form-" ~ loop.index %}
<form action="/person/listing" id="{{ form_id }}"
Expand Down
4 changes: 2 additions & 2 deletions husky_directory/templates/vcard.vcf.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ FN:{{ display_name }}
ORG:University of Washington;{{ dept }}
{% endfor %}
{# EMAIL;type=INTERNET,type=WORK:[email protected] #}
{% if not email is blank -%}
{% for email in emails -%}
EMAIL;type=INTERNET,type=WORK:{{ email }}
{% endif %}
{% endfor %}
{# TEL;type="pager,voice":5558675309 #}
{% for phone in phones -%}
TEL;type="{% for pt in phone['types'] -%}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "uw-husky-directory"
version = "2.2.8"
version = "2.3.0"
description = "An updated version of the UW Directory"
authors = ["Thomas Thorogood <[email protected]>"]
license = "MIT"
Expand Down
6 changes: 4 additions & 2 deletions tests/services/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ def test_translate_scenario(self, generate_person):

person = employees.people[0]

# Ensure student email was overwritten by employee email
assert person.email == "[email protected]"
# Ensure student email is overwritten by employee email,
# and verify that both employee emails are displayed instead of just one.
# More on: https://github.com/UWIT-IAM/uw-husky-directory/blob/main/tests/conftest.py#L135
assert person.emails == ["[email protected]", "[email protected]"]
assert person.box_number == "351234"
assert person.phone_contacts.phones == ["2068675309 Ext. 4242", "19999674222"]
assert person.departments[0].department == "Cybertronic Engineering"
Expand Down
4 changes: 2 additions & 2 deletions tests/services/test_vcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ def test_set_employee_vcard_attrs(self, employee):
VCardPhone(types=["MSG"], value="5555555"),
]

assert vcard.email == "[email protected]"
assert vcard.emails == ["[email protected]"]
assert vcard.departments == ["Snack Eating", "Napping"]
assert vcard.titles == ["Chief of Kibble Testing", "Assistant Snuggler"]

def test_set_student_vcard_attrs(self, student):
vcard = VCard.construct()
self.service.set_student_vcard_attrs(vcard, student)
assert vcard.phones == [VCardPhone(types=["home"], value="4444444")]
assert vcard.email == "[email protected]"
assert vcard.emails == ["[email protected]"]
assert vcard.titles == ["Goodboi"]
assert vcard.departments == ["Barkochemical Engineering"]

Expand Down

0 comments on commit 93bc02e

Please sign in to comment.