Skip to content
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
16 changes: 16 additions & 0 deletions src/sentry/notifications/notifications/activity/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

from typing import Any, Mapping, Optional

from django.utils.html import format_html
from django.utils.safestring import SafeString

from sentry.notifications.utils.avatar import avatar_as_html
from sentry.services.hybrid_cloud.actor import RpcActor
from sentry.types.integrations import ExternalProviders

Expand Down Expand Up @@ -33,3 +37,15 @@ def get_notification_title(

def get_message_description(self, recipient: RpcActor, provider: ExternalProviders) -> Any:
return self.get_context()["text_description"]

def description_as_html(self, description: str, params: Mapping[str, Any]) -> SafeString:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description and params aren't actually needed here, but that's what the base function accepts. It's funny that we don't need description because that's the comment itself, but in the template (note.html) it's rendered from data.text.

"""Note emails are formatted differently from almost all other activity emails.
Rather than passing the `description` as a string to be formatted into HTML with
`author` and `an_issue` (see base definition and resolved.py's `get_description`
as an example) we are simply passed the comment as a string that needs no formatting,
and want the avatar on it's own rather than bundled with the author's display name
because the display name is already shown in the notification title."""
fmt = '<span class="avatar-container">{}</span>'
if self.user:
return format_html(fmt, avatar_as_html(self.user, 48))
return format_html(description)
11 changes: 7 additions & 4 deletions src/sentry/notifications/utils/avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ def get_sentry_avatar_url() -> str:
return str(absolute_uri(get_asset_url("sentry", url)))


def avatar_as_html(user: User | RpcUser) -> SafeString:
def avatar_as_html(user: User | RpcUser, size: int = 20) -> SafeString:
if not user:
return format_html(
'<img class="avatar" src="{}" width="20px" height="20px" />', get_sentry_avatar_url()
'<img class="avatar" src="{}" width="{}px" height="{}px" />',
get_sentry_avatar_url(),
size,
size,
)
avatar_type = user.get_avatar_type()
if avatar_type == "upload":
return format_html('<img class="avatar" src="{}" />', get_user_avatar_url(user))
elif avatar_type == "letter_avatar":
return get_email_avatar(user.get_display_name(), user.get_label(), 20, False)
return get_email_avatar(user.get_display_name(), user.get_label(), size, False)
else:
return get_email_avatar(user.get_display_name(), user.get_label(), 20, True)
return get_email_avatar(user.get_display_name(), user.get_label(), size, True)
8 changes: 1 addition & 7 deletions src/sentry/templates/sentry/emails/activity/note.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ <h3>{{ title }}</h3>
<table class="note">
<tr>
<td class="avatar-column">
{% if author.get_avatar_type == 'upload' %}
<img class="avatar" src="{% profile_photo_url author.id 48 %}">
{% elif author.get_avatar_type == 'letter_avatar' %}
{% email_avatar author.get_display_name author.get_label 48 False %}
{% else %}
{% email_avatar author.get_display_name author.get_label 48 %}
{% endif %}
{{ html_description }}
</td>
<td class="notch-column">
<img width="7" height="48" src="{% absolute_asset_url 'sentry' 'images/email/avatar-notch.png' %}">
Expand Down