diff --git a/src/sentry/notifications/helpers.py b/src/sentry/notifications/helpers.py index 542941581b9ac8..dbb747ecadfcef 100644 --- a/src/sentry/notifications/helpers.py +++ b/src/sentry/notifications/helpers.py @@ -71,15 +71,9 @@ def _get_setting_mapping_from_mapping( for provider in notification_providers() } - notification_settings_mapping = notification_settings_by_recipient.get(recipient) - if notification_settings_mapping: - specific_scope = get_scope_type(type) - notification_setting_option.update( - notification_settings_mapping.get(specific_scope) - or notification_settings_mapping.get(NotificationScopeType.USER) - or notification_settings_mapping.get(NotificationScopeType.TEAM) - or {} - ) + notification_settings_mapping = notification_settings_by_recipient.get(recipient, {}) + for scope in [NotificationScopeType.USER, NotificationScopeType.TEAM, get_scope_type(type)]: + notification_setting_option.update(notification_settings_mapping.get(scope, {})) return notification_setting_option diff --git a/tests/sentry/notifications/utils/test_get_setting_mapping_from_mapping.py b/tests/sentry/notifications/utils/test_get_setting_mapping_from_mapping.py index 4ccb45e3098d2b..05d816fce9d7a7 100644 --- a/tests/sentry/notifications/utils/test_get_setting_mapping_from_mapping.py +++ b/tests/sentry/notifications/utils/test_get_setting_mapping_from_mapping.py @@ -114,3 +114,26 @@ def test_get_setting_mapping_from_mapping_slack_always(self): ExternalProviders.EMAIL: NotificationSettingOptionValues.ALWAYS, ExternalProviders.SLACK: NotificationSettingOptionValues.ALWAYS, } + + def test_get_setting_mapping_from_mapping_project(self): + notification_settings = { + self.user: { + NotificationScopeType.USER: { + ExternalProviders.EMAIL: NotificationSettingOptionValues.NEVER, + ExternalProviders.SLACK: NotificationSettingOptionValues.ALWAYS, + }, + NotificationScopeType.PROJECT: { + ExternalProviders.EMAIL: NotificationSettingOptionValues.NEVER, + }, + } + } + + mapping = _get_setting_mapping_from_mapping( + notification_settings, + self.user, + NotificationSettingTypes.ISSUE_ALERTS, + ) + assert mapping == { + ExternalProviders.EMAIL: NotificationSettingOptionValues.NEVER, + ExternalProviders.SLACK: NotificationSettingOptionValues.ALWAYS, + } diff --git a/tests/sentry/notifications/utils/test_should_be_participating.py b/tests/sentry/notifications/utils/test_should_be_participating.py index 0952426a4598f3..fc836c8795977d 100644 --- a/tests/sentry/notifications/utils/test_should_be_participating.py +++ b/tests/sentry/notifications/utils/test_should_be_participating.py @@ -74,7 +74,6 @@ def test_where_should_be_participating(self): assert providers == [ExternalProviders.EMAIL, ExternalProviders.SLACK] def test_subscription_null(self): - self.user = User(id=1) notification_settings = { self.user: { NotificationScopeType.USER: {