Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(notification platform): Remove hardcoded email provider #28577

Merged
merged 3 commits into from
Sep 15, 2021

Conversation

ceorourke
Copy link
Member

Remove the hard coded email provider and just check for any provider - I believe this was leftover from a refactor before we were ready to launch. This fixes an issue where if a user's delivery method for issue alerts was set to Slack (and not Slack and email) and a rule fired which was set to send a notification to issue owners, it would not send.

@@ -91,7 +91,7 @@ def _get_setting_mapping_from_mapping(

return {
provider: _get_notification_setting_default(provider, type, user=user)
for provider in [ExternalProviders.EMAIL]
for provider in [ExternalProviders.EMAIL, ExternalProviders.SLACK]
Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't sure if I should do this or just get all ExternalProviders enum values

Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the XXX(CEO) comment now.

Copy link
Member Author

Choose a reason for hiding this comment

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

the comment was about if we change the front end to allow a user to set Slack notifications for project A, and email notifications for project B, which we don't allow, so I think it still stands.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah we should just do all of them here.

from sentry.notifications.notify import notification_providers
...
for provider in notification_providers()

Copy link
Member

Choose a reason for hiding this comment

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

Maybe a separate Notification Platform enum? If this list is replicated in multiple places it'd make for easier changes down the line.

Copy link
Member

Choose a reason for hiding this comment

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

^^ guess im late

@ceorourke ceorourke requested a review from a team September 14, 2021 19:15
ExternalProviders.EMAIL
]
recipients = NotificationSetting.objects.get_notification_recipients(project)
return set.union(*recipients.values()) if recipients else {}
Copy link
Contributor

Choose a reason for hiding this comment

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

get_notification_recipients() never returns None so it's safe to always return the union. I'd also rename the variable to make it clearer why we're calling .values().

recipients_by_provider = NotificationSetting.objects.get_notification_recipients(project)
return set.union(*recipients_by_provider.values())

Copy link
Member Author

Choose a reason for hiding this comment

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

It does in

def test_should_not_notify_no_users(self):

which is why I added the check

Copy link
Contributor

Choose a reason for hiding this comment

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

I just checked this out:

>>> set.union(set([1]), set([1]))
{1}
>>> set.union(set([1]), [1])
{1}
>>> set.union([1], [1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor 'union' requires a 'set' object but received a 'list'

I think because .values() returns lists you won't be able to use set.union(*...).

recipients_by_provider = NotificationSetting.objects.get_notification_recipients(project)
return set([user for users in recipients_by_provider.values() for user in users])

@ceorourke ceorourke requested a review from mgaeta September 14, 2021 19:27
ExternalProviders.EMAIL
]
recipients = NotificationSetting.objects.get_notification_recipients(project)
return set.union(*recipients.values()) if recipients else {}
Copy link
Member

Choose a reason for hiding this comment

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

some cleeeaan python 🐍

i had to look up almost everything in this line

Copy link
Member Author

Choose a reason for hiding this comment

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

ty stackoverflow

@@ -91,7 +91,7 @@ def _get_setting_mapping_from_mapping(

return {
provider: _get_notification_setting_default(provider, type, user=user)
for provider in [ExternalProviders.EMAIL]
for provider in [ExternalProviders.EMAIL, ExternalProviders.SLACK]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a separate Notification Platform enum? If this list is replicated in multiple places it'd make for easier changes down the line.

}
rule = Rule.objects.create(
project=self.project,
label="ja rule",
Copy link
Member

Choose a reason for hiding this comment

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

not enough people make tests fun 👏

@ceorourke ceorourke merged commit e0bbea3 into master Sep 15, 2021
@ceorourke ceorourke deleted the ceorourke/rm-hardcoded-email branch September 15, 2021 18:31
@github-actions github-actions bot locked and limited conversation to collaborators Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants