コード例 #1
0
    def assign(self, work_batch, assigned_to, acting_user=None):
        from sentry.models import User, Team
        from clims.models import WorkBatchSubscription, WorkBatchSubscriptionReason

        WorkBatchSubscription.objects.subscribe_actor(
            work_batch=work_batch,
            actor=assigned_to,
            reason=WorkBatchSubscriptionReason.assigned,
        )

        if isinstance(assigned_to, User):
            assignee_type = 'user'
            other_type = 'team'
        elif isinstance(assigned_to, Team):
            assignee_type = 'team'
            other_type = 'user'
        else:
            raise AssertionError('Invalid type to assign to: %r' % type(assigned_to))

        now = timezone.now()
        assignee, created = WorkBatchAssignee.objects.get_or_create(
            work_batch=work_batch,
            defaults={
                assignee_type: assigned_to,
                'date_added': now,
            }
        )

        if not created:
            affected = WorkBatchAssignee.objects.filter(
                work_batch=work_batch,
            ).exclude(**{
                assignee_type: assigned_to,
            }).update(**{
                assignee_type: assigned_to,
                other_type: None,
                'date_added': now,
            })
        else:
            affected = True
            issue_assigned.send_robust(
                work_batch=work_batch,
                user=acting_user,
                sender=self.__class__)

        if affected:
            activity = Activity.objects.create(
                work_batch=work_batch,
                type=Activity.ASSIGNED,
                user=acting_user,
                data={
                    'assignee': six.text_type(assigned_to.id),
                    'assigneeEmail': getattr(assigned_to, 'email', None),
                    'assigneeType': assignee_type,
                },
            )
            activity.send_notification()
            # TODO: Look into this
            metrics.incr('work_batch.assignee.change', instance='assigned', skip_internal=True)
コード例 #2
0
    def assign(self, group, assigned_to, acting_user=None):
        from sentry import features
        from sentry.models import GroupSubscription, Team, User

        GroupSubscription.objects.subscribe_actor(
            group=group,
            actor=assigned_to,
            reason=GroupSubscriptionReason.assigned)

        if isinstance(assigned_to, User):
            assignee_type = "user"
            other_type = "team"
        elif isinstance(assigned_to, Team):
            assignee_type = "team"
            other_type = "user"
        else:
            raise AssertionError("Invalid type to assign to: %r" %
                                 type(assigned_to))

        now = timezone.now()
        assignee, created = GroupAssignee.objects.get_or_create(
            group=group,
            defaults={
                "project": group.project,
                assignee_type: assigned_to,
                "date_added": now
            },
        )

        if not created:
            affected = (GroupAssignee.objects.filter(group=group).exclude(
                **{
                    assignee_type: assigned_to
                }).update(
                    **{
                        assignee_type: assigned_to,
                        other_type: None,
                        "date_added": now
                    }))
        else:
            affected = True
            issue_assigned.send_robust(project=group.project,
                                       group=group,
                                       user=acting_user,
                                       sender=self.__class__)

        if affected:
            activity = Activity.objects.create(
                project=group.project,
                group=group,
                type=Activity.ASSIGNED,
                user=acting_user,
                data={
                    "assignee": str(assigned_to.id),
                    "assigneeEmail": getattr(assigned_to, "email", None),
                    "assigneeType": assignee_type,
                },
            )
            activity.send_notification()
            metrics.incr("group.assignee.change",
                         instance="assigned",
                         skip_internal=True)
            # sync Sentry assignee to external issues
            if assignee_type == "user" and features.has(
                    "organizations:integrations-issue-sync",
                    group.organization,
                    actor=acting_user):
                sync_group_assignee_outbound(group,
                                             assigned_to.id,
                                             assign=True)
コード例 #3
0
    def assign(
        self,
        group: Group,
        assigned_to: Team | User,
        acting_user: User | None = None,
        create_only: bool = False,
    ):
        from sentry import features
        from sentry.integrations.utils import sync_group_assignee_outbound
        from sentry.models import Activity, GroupSubscription, Team, User

        GroupSubscription.objects.subscribe_actor(
            group=group,
            actor=assigned_to,
            reason=GroupSubscriptionReason.assigned)

        if isinstance(assigned_to, User):
            assignee_type = "user"
            other_type = "team"
        elif isinstance(assigned_to, Team):
            assignee_type = "team"
            other_type = "user"
        else:
            raise AssertionError(
                f"Invalid type to assign to: {type(assigned_to)}")

        now = timezone.now()
        assignee, created = self.get_or_create(
            group=group,
            defaults={
                "project": group.project,
                assignee_type: assigned_to,
                "date_added": now
            },
        )

        if not created:
            affected = not create_only and self.filter(group=group).exclude(
                **{
                    assignee_type: assigned_to
                }).update(**{
                    assignee_type: assigned_to,
                    other_type: None,
                    "date_added": now
                })
        else:
            affected = True
            issue_assigned.send_robust(project=group.project,
                                       group=group,
                                       user=acting_user,
                                       sender=self.__class__)

        if affected:
            Activity.objects.create_group_activity(
                group,
                ActivityType.ASSIGNED,
                user=acting_user,
                data={
                    "assignee": str(assigned_to.id),
                    "assigneeEmail": getattr(assigned_to, "email", None),
                    "assigneeType": assignee_type,
                },
            )
            record_group_history(group,
                                 GroupHistoryStatus.ASSIGNED,
                                 actor=acting_user)

            metrics.incr("group.assignee.change",
                         instance="assigned",
                         skip_internal=True)
            # sync Sentry assignee to external issues
            if assignee_type == "user" and features.has(
                    "organizations:integrations-issue-sync",
                    group.organization,
                    actor=acting_user):
                sync_group_assignee_outbound(group,
                                             assigned_to.id,
                                             assign=True)

        return {
            "new_assignment": created,
            "updated_assignment": bool(not created and affected)
        }
コード例 #4
0
    def assign(self, group, assigned_to, acting_user=None):
        from sentry import features
        from sentry.models import User, Team, GroupSubscription, GroupSubscriptionReason

        GroupSubscription.objects.subscribe_actor(
            group=group,
            actor=assigned_to,
            reason=GroupSubscriptionReason.assigned,
        )

        if isinstance(assigned_to, User):
            assignee_type = 'user'
            other_type = 'team'
        elif isinstance(assigned_to, Team):
            assignee_type = 'team'
            other_type = 'user'
        else:
            raise AssertionError('Invalid type to assign to: %r' % type(assigned_to))

        now = timezone.now()
        assignee, created = GroupAssignee.objects.get_or_create(
            group=group,
            defaults={
                'project': group.project,
                assignee_type: assigned_to,
                'date_added': now,
            }
        )

        if not created:
            affected = GroupAssignee.objects.filter(
                group=group,
            ).exclude(**{
                assignee_type: assigned_to,
            }).update(**{
                assignee_type: assigned_to,
                other_type: None,
                'date_added': now,
            })
        else:
            affected = True
            issue_assigned.send_robust(
                project=group.project,
                group=group,
                user=acting_user,
                sender=self.__class__)

        if affected:
            activity = Activity.objects.create(
                project=group.project,
                group=group,
                type=Activity.ASSIGNED,
                user=acting_user,
                data={
                    'assignee': six.text_type(assigned_to.id),
                    'assigneeEmail': getattr(assigned_to, 'email', None),
                    'assigneeType': assignee_type,
                },
            )
            activity.send_notification()
            metrics.incr('group.assignee.change', instance='assigned', skip_internal=True)
            # sync Sentry assignee to external issues
            if assignee_type == 'user' and features.has(
                    'organizations:integrations-issue-sync', group.organization, actor=acting_user):
                sync_group_assignee_outbound(group, assigned_to.id, assign=True)
コード例 #5
0
ファイル: groupassignee.py プロジェクト: Kayle009/sentry
    def assign(self, group, assigned_to, acting_user=None):
        from sentry import features
        from sentry.models import User, Team, GroupSubscription, GroupSubscriptionReason

        GroupSubscription.objects.subscribe_actor(
            group=group,
            actor=assigned_to,
            reason=GroupSubscriptionReason.assigned,
        )

        if isinstance(assigned_to, User):
            assignee_type = 'user'
            other_type = 'team'
        elif isinstance(assigned_to, Team):
            assignee_type = 'team'
            other_type = 'user'
        else:
            raise AssertionError('Invalid type to assign to: %r' % type(assigned_to))

        now = timezone.now()
        assignee, created = GroupAssignee.objects.get_or_create(
            group=group,
            defaults={
                'project': group.project,
                assignee_type: assigned_to,
                'date_added': now,
            }
        )

        if not created:
            affected = GroupAssignee.objects.filter(
                group=group,
            ).exclude(**{
                assignee_type: assigned_to,
            }).update(**{
                assignee_type: assigned_to,
                other_type: None,
                'date_added': now,
            })
        else:
            affected = True
            issue_assigned.send_robust(
                project=group.project,
                group=group,
                user=acting_user,
                sender=self.__class__)

        if affected:
            activity = Activity.objects.create(
                project=group.project,
                group=group,
                type=Activity.ASSIGNED,
                user=acting_user,
                data={
                    'assignee': six.text_type(assigned_to.id),
                    'assigneeEmail': getattr(assigned_to, 'email', None),
                    'assigneeType': assignee_type,
                },
            )
            activity.send_notification()
            metrics.incr('group.assignee.change', instance='assigned', skip_internal=True)
            # sync Sentry assignee to external issues
            if assignee_type == 'user' and features.has(
                    'organizations:integrations-issue-sync', group.organization, actor=acting_user):
                sync_group_assignee_outbound(group, assigned_to.id, assign=True)