From 609e9db591e007448a6f0b1a6f356c9219f12dcc Mon Sep 17 00:00:00 2001 From: Wes Appler <145372368+wes-otf@users.noreply.github.com> Date: Sat, 1 Jun 2024 04:28:22 -0400 Subject: [PATCH] Utilize emails as display name on comments when no name is set (#3896) Fixes #3895. Quick one I noticed while working on the partner comment stuff. Comments will now display with the user email where no full name is set. --- .../activity/templatetags/activity_tags.py | 2 +- hypha/apply/users/models.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/hypha/apply/activity/templatetags/activity_tags.py b/hypha/apply/activity/templatetags/activity_tags.py index 4a0c6add9..7a6fb2754 100644 --- a/hypha/apply/activity/templatetags/activity_tags.py +++ b/hypha/apply/activity/templatetags/activity_tags.py @@ -35,7 +35,7 @@ def display_author(activity, user) -> str: return settings.ORG_LONG_NAME if isinstance(activity.related_object, Review) and activity.source.user == user: return "Reviewer" - return activity.user.get_full_name_with_group() + return activity.user.get_display_name_with_group() @register.filter diff --git a/hypha/apply/users/models.py b/hypha/apply/users/models.py index 2470e68af..5375aa29c 100644 --- a/hypha/apply/users/models.py +++ b/hypha/apply/users/models.py @@ -226,16 +226,26 @@ class User(AbstractUser): def get_full_name(self): return self.full_name.strip() - def get_short_name(self): - return self.email + def get_short_name(self) -> str: + """Gets the local-part (username) of the user's email - def get_full_name_with_group(self): + ie. hyphaiscool@hypha.app returns "hyphaiscool" + """ + return self.email.split("@")[0] + + def get_display_name_with_group(self) -> str: + """Gets the user's display name, along with their role in parenthesis + + If the user has a full name set that will be used, otherwise pulls the email. + """ + display_name = str(self) is_apply_staff = f" ({STAFF_GROUP_NAME})" if self.is_apply_staff else "" is_reviewer = f" ({REVIEWER_GROUP_NAME})" if self.is_reviewer else "" + is_partner = f" ({PARTNER_GROUP_NAME})" if self.is_partner else "" is_applicant = f" ({APPLICANT_GROUP_NAME})" if self.is_applicant else "" is_finance = f" ({FINANCE_GROUP_NAME})" if self.is_finance else "" is_contracting = f" ({CONTRACTING_GROUP_NAME})" if self.is_contracting else "" - return f"{self.full_name.strip()}{is_apply_staff}{is_reviewer}{is_applicant}{is_finance}{is_contracting}" + return f"{display_name}{is_apply_staff}{is_reviewer}{is_applicant}{is_partner}{is_finance}{is_contracting}" @cached_property def roles(self): -- GitLab