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
4 changes: 3 additions & 1 deletion src/sentry/mail/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ def send_notification_as_email(
**get_builder_args(notification, recipient, shared_context, extra_context_by_user_id)
)
# TODO: find better way of handling this
add_users_kwargs = {}
if isinstance(notification, ProjectNotification):
msg.add_users([recipient.id], project=notification.project)
add_users_kwargs["project"] = notification.project
msg.add_users([recipient.id], **add_users_kwargs)
msg.send_async()


Expand Down
23 changes: 16 additions & 7 deletions src/sentry/notifications/notifications/organization_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from typing import TYPE_CHECKING, Any, Iterable, Mapping, MutableMapping, Sequence, Type, Union

from sentry import analytics, features
from sentry import analytics, features, roles
from sentry.integrations.slack.utils.notifications import get_settings_url
from sentry.models import OrganizationMember, Team
from sentry.notifications.notifications.base import BaseNotification, MessageAction
Expand Down Expand Up @@ -66,10 +66,8 @@ def get_participants(self) -> Mapping[ExternalProviders, Iterable[Union["Team",
available_providers = notification_providers()

# TODO: need to read off notification settings
recipients = self.determine_recipients()
output = {
provider: [recipient for recipient in recipients] for provider in available_providers
}
recipients = list(self.determine_recipients())
output = {provider: recipients for provider in available_providers}

return output

Expand All @@ -82,6 +80,7 @@ def send(self) -> None:

context = self.get_context()
for provider, recipients in participants_by_provider.items():
# TODO: use safe_excute
notify(provider, self, recipients, context)

def get_member(self, user: "User") -> "OrganizationMember":
Expand All @@ -98,6 +97,10 @@ def set_member_in_cache(self, member: OrganizationMember) -> None:
"""
self.member_by_user_id[member.user_id] = member

def get_notification_title(self) -> str:
# purposely use empty string for the notification title
return ""

def build_attachment_title(self) -> str:
raise NotImplementedError

Expand All @@ -110,14 +113,20 @@ def get_actions(self) -> Sequence[Mapping[str, str]]:
def get_message_actions(self) -> Sequence[MessageAction]:
raise NotImplementedError

def get_role_string(self, member: OrganizationMember) -> str:
role_string: str = roles.get(member.role).name
return role_string

def build_notification_footer(self, recipient: Union["Team", "User"]) -> str:
# not implemented for teams
if isinstance(recipient, Team):
raise NotImplementedError
recipient_member = self.get_member(recipient)
settings_url = get_settings_url(self, recipient)
return f"""You are receiving this notification because you're listed
as an organization {recipient_member.role} | <{settings_url}|Notification Settings>"""
return (
"You are receiving this notification because you're listed as an organization "
f"{self.get_role_string(recipient_member)} | <{settings_url}|Notification Settings>"
)

def record_notification_sent(
self, recipient: Union["Team", "User"], provider: ExternalProviders
Expand Down