Exemple #1
0
 def get_for_users_by_parent(
     self,
     provider: ExternalProviders,
     type: NotificationSettingTypes,
     parent: Any,
     users: List[Any],
 ) -> QuerySet:
     """
     Find all of a project/organization's notification settings for a list of users.
     This will include each user's project/organization-independent settings.
     """
     scope_type = get_scope_type(type)
     return self.filter(
         Q(
             scope_type=scope_type.value,
             scope_identifier=parent.id,
         )
         | Q(
             scope_type=NotificationScopeType.USER.value,
             scope_identifier__in=[user.id for user in users],
         ),
         provider=provider.value,
         type=type.value,
         target__in=[user.actor.id for user in users],
     )
Exemple #2
0
 def get_for_user_by_projects(
     self,
     provider: ExternalProviders,
     type: NotificationSettingTypes,
     user: Any,
     parents: List[Any],
 ) -> QuerySet:
     """
     Find all of a user's notification settings for a list of projects or organizations.
     This will include the user's  setting.
     """
     scope_type = get_scope_type(type)
     return self.filter(
         Q(
             scope_type=scope_type.value,
             scope_identifier__in=[parent.id for parent in parents],
         )
         | Q(
             scope_type=NotificationScopeType.USER.value,
             scope_identifier=user.id,
         ),
         provider=provider.value,
         type=type.value,
         target=user.actor,
     )
Exemple #3
0
 def get_for_recipient_by_parent(
     self,
     type: NotificationSettingTypes,
     parent: Any,
     recipient: Any,
 ) -> QuerySet:
     """
     Find all of a project/organization's notification settings for a recipient.
     This will include each recipient's project/organization-independent settings.
     """
     scope_type = get_scope_type(type)
     return self.filter(
         scope_type=scope_type.value,
         scope_identifier=parent.id,
         type=type.value,
         target=recipient.actor_id,
     )
Exemple #4
0
 def test_get_scope_type(self):
     assert get_scope_type(NotificationSettingTypes.DEPLOY
                           ) == NotificationScopeType.ORGANIZATION
     assert get_scope_type(
         NotificationSettingTypes.WORKFLOW) == NotificationScopeType.PROJECT
     assert (get_scope_type(NotificationSettingTypes.ISSUE_ALERTS) ==
             NotificationScopeType.PROJECT)
     assert not get_scope_type(
         NotificationSettingTypes.DEPLOY) == NotificationScopeType.PROJECT
     assert (not get_scope_type(NotificationSettingTypes.WORKFLOW)
             == NotificationScopeType.ORGANIZATION)
     assert (not get_scope_type(NotificationSettingTypes.ISSUE_ALERTS)
             == NotificationScopeType.ORGANIZATION)
Exemple #5
0
    def get_for_recipient_by_parent(
        self,
        type_: NotificationSettingTypes,
        parent: Union["Organization", "Project"],
        recipients: Iterable[Union["Team", "User"]],
    ) -> QuerySet:
        from sentry.models import Team, User

        """
        Find all of a project/organization's notification settings for a list of
        users or teams. Note that this WILL work with a mixed list. This will
        include each user or team's project/organization-independent settings.
        """
        user_ids: MutableSet[int] = set()
        team_ids: MutableSet[int] = set()
        actor_ids: MutableSet[int] = set()
        for recipient in recipients:
            if type(recipient) == Team:
                team_ids.add(recipient.id)
            if type(recipient) == User:
                user_ids.add(recipient.id)
            actor_ids.add(recipient.actor.id)

        # If the list would be empty, don't bother querying.
        if not actor_ids:
            return self.none()

        parent_specific_scope_type = get_scope_type(type_)
        return self.filter(
            Q(
                scope_type=parent_specific_scope_type.value,
                scope_identifier=parent.id,
            )
            | Q(
                scope_type=NotificationScopeType.USER.value,
                scope_identifier__in=user_ids,
            )
            | Q(
                scope_type=NotificationScopeType.TEAM.value,
                scope_identifier__in=team_ids,
            ),
            type=type_.value,
            target__in=actor_ids,
        )
Exemple #6
0
 def get_for_user_by_projects(
     self,
     type: NotificationSettingTypes,
     user: "******",
     parents: List[Union["Organization", "Project"]],
 ) -> QuerySet:
     """
     Find all of a user's notification settings for a list of projects or
     organizations. This will include the user's parent-independent setting.
     """
     scope_type = get_scope_type(type)
     return self.filter(
         Q(
             scope_type=scope_type.value,
             scope_identifier__in=[parent.id for parent in parents],
         )
         | Q(
             scope_type=NotificationScopeType.USER.value,
             scope_identifier=user.id,
         ),
         type=type.value,
         target=user.actor,
     )