diff --git a/compendium_v2/auth/session_management.py b/compendium_v2/auth/session_management.py index 5c6b016b88710c67e3efe86fb30907ad7b509a90..a244f0a1ad9b587368a372ea82526fed8a8fc213 100644 --- a/compendium_v2/auth/session_management.py +++ b/compendium_v2/auth/session_management.py @@ -33,13 +33,14 @@ def admin_required(func): return wraps(func)(wrapper) -def create_user(email: str, fullname: str, oidc_sub: str): +def create_user(email: str, fullname: str, oidc_sub: str, given_name: str): """ Function used to create a new user in the database. :param email: The email of the user :param fullname: The full name of the user :param oidc_sub: The OIDC subject identifier (ID) of the user + :param given_name: The given name of the user :return: The user object """ @@ -47,7 +48,7 @@ def create_user(email: str, fullname: str, oidc_sub: str): user = User(email=email, fullname=fullname, oidc_sub=oidc_sub) session.add(user) send_admin_signup_notification(user) - send_user_signup_notification(user) + send_user_signup_notification(user, given_name) return user diff --git a/compendium_v2/email/__init__.py b/compendium_v2/email/__init__.py index 7edf05ca2e718893300d226dc88218b00a8cea7d..be3349efdb0a72d165cc5caa7a8615bfd0bd6ac5 100644 --- a/compendium_v2/email/__init__.py +++ b/compendium_v2/email/__init__.py @@ -75,10 +75,9 @@ def send_admin_signup_notification(user: User): send_mail(contents=contents, subject='New user signed up for Compendium') -def send_user_signup_notification(user: User): - fullname = user.fullname +def send_user_signup_notification(user: User, given_name: str): email = user.email + name = f' {given_name}' if given_name else '' - first_name = ' ' + fullname.split()[0] if fullname else '' - contents = USER_NOTIFICATION_TEMPLATE.format(name=first_name) + contents = USER_NOTIFICATION_TEMPLATE.format(name=name) send_mail(contents=contents, subject='You have signed up for the Compendium Survey', recipients=email) diff --git a/compendium_v2/routes/authentication.py b/compendium_v2/routes/authentication.py index aec7d330a40ba5837ce3b168e6177af965bb1d5b..f16360657ac50139f01b56d7ca821b9d3cce061a 100644 --- a/compendium_v2/routes/authentication.py +++ b/compendium_v2/routes/authentication.py @@ -36,7 +36,7 @@ def authorize(): user = fetch_user(profile) if user is None: # create a new user - user = create_user(profile['email'], profile['name'], profile['sub']) + user = create_user(profile['email'], profile['name'], profile['sub'], profile['given_name']) login_user(user) # redirect to / diff --git a/test/test_send_mail.py b/test/test_send_mail.py index d68b067dbfdf5919e13790cf4cef15a7f30b92e4..e3ae5a9e448b4e1a2e11ab74d1624d64b49543d0 100644 --- a/test/test_send_mail.py +++ b/test/test_send_mail.py @@ -33,4 +33,4 @@ def test_signup_email_user(app, mocker): mocker.patch('compendium_v2.email._send_mail', _send_mail) with test_user(app) as user: - send_user_signup_notification(user) + send_user_signup_notification(user, 'testname')