Exemple #1
0
    def _get_subscriptions(
        groups: Iterable[Group], user: User
    ) -> Mapping[int, Tuple[bool, bool, Optional[GroupSubscription]]]:
        """
        Returns a mapping of group IDs to a two-tuple of (is_disabled: bool,
        subscribed: bool, subscription: Optional[GroupSubscription]) for the
        provided user and groups.
        """
        if not groups:
            return {}

        groups_by_project = collect_groups_by_project(groups)
        notification_settings_by_scope = transform_to_notification_settings_by_scope(
            NotificationSetting.objects.get_for_user_by_projects(
                NotificationSettingTypes.WORKFLOW,
                user,
                groups_by_project.keys(),
            )
        )
        query_groups = get_groups_for_query(groups_by_project, notification_settings_by_scope, user)
        subscriptions = GroupSubscription.objects.filter(group__in=query_groups, user=user)
        subscriptions_by_group_id = {
            subscription.group_id: subscription for subscription in subscriptions
        }

        return get_user_subscriptions_for_groups(
            groups_by_project,
            notification_settings_by_scope,
            subscriptions_by_group_id,
            user,
        )
Exemple #2
0
    def _get_subscriptions(
        groups: Iterable[Group], user: User
    ) -> Mapping[int, Tuple[bool, bool, Optional[GroupSubscription]]]:
        """
        Returns a mapping of group IDs to a two-tuple of (is_disabled: bool,
        subscribed: bool, subscription: Optional[GroupSubscription]) for the
        provided user and groups.
        """
        if not groups:
            return {}

        groups_by_project = collect_groups_by_project(groups)
        notification_settings = NotificationSetting.objects.get_for_user_by_projects(
            NotificationSettingTypes.WORKFLOW,
            user,
            groups_by_project.keys(),
        )

        (
            notification_settings_by_project_id_by_provider,
            default_subscribe_by_provider,
        ) = transform_to_notification_settings_by_parent_id(
            notification_settings,
            NotificationSettingOptionValues.SUBSCRIBE_ONLY)
        notification_settings_by_key = notification_settings_by_project_id_by_provider[
            ExternalProviders.EMAIL]
        global_default_workflow_option = default_subscribe_by_provider[
            ExternalProviders.EMAIL]

        query_groups = get_groups_for_query(
            groups_by_project,
            notification_settings_by_key,
            global_default_workflow_option,
        )
        subscriptions = GroupSubscription.objects.filter(
            group__in=query_groups, user=user)
        subscriptions_by_group_id = {
            subscription.group_id: subscription
            for subscription in subscriptions
        }

        return get_user_subscriptions_for_groups(
            groups_by_project,
            notification_settings_by_key,
            subscriptions_by_group_id,
            global_default_workflow_option,
        )
Exemple #3
0
 def test_collect_groups_by_project(self):
     assert collect_groups_by_project([self.group]) == {
         self.project: {self.group}
     }