예제 #1
0
 def filter_to_subscribed_users(
     self,
     project: "Project",
     users: List["User"],
 ) -> Mapping[ExternalProviders, Iterable["User"]]:
     """
     Filters a list of users down to the users by provider who are subscribed to alerts.
     We check both the project level settings and global default settings.
     """
     notification_settings = self.get_for_recipient_by_parent(
         NotificationSettingTypes.ISSUE_ALERTS,
         parent=project,
         recipients=users)
     notification_settings_by_user = transform_to_notification_settings_by_user(
         notification_settings, users)
     mapping = defaultdict(set)
     should_use_slack_automatic = features.has(
         "organizations:notification-slack-automatic", project.organization)
     for user in users:
         providers = where_should_user_be_notified(
             notification_settings_by_user, user,
             should_use_slack_automatic)
         for provider in providers:
             mapping[provider].add(user)
     return mapping
예제 #2
0
 def test_where_should_user_be_notified(self):
     notification_settings = {
         self.user: {
             NotificationScopeType.USER: {
                 ExternalProviders.EMAIL:
                 NotificationSettingOptionValues.ALWAYS
             }
         }
     }
     assert where_should_user_be_notified(
         notification_settings, self.user) == [ExternalProviders.EMAIL]
예제 #3
0
 def filter_to_subscribed_users(
     self,
     project: Any,
     users: List[Any],
 ) -> Mapping[ExternalProviders, Iterable[Any]]:
     """
     Filters a list of users down to the users by provider who are subscribed to alerts.
     We check both the project level settings and global default settings.
     """
     notification_settings = self.get_for_users_by_parent(
         NotificationSettingTypes.ISSUE_ALERTS, parent=project, users=users)
     notification_settings_by_user = transform_to_notification_settings_by_user(
         notification_settings, users)
     mapping = defaultdict(set)
     for user in users:
         providers = where_should_user_be_notified(
             notification_settings_by_user, user)
         for provider in providers:
             mapping[provider].add(user)
     return mapping