|
@@ -1,7 +1,7 @@
|
|
|
import logging
|
|
|
-from typing import Any, Sequence
|
|
|
+from typing import Any, List, Sequence
|
|
|
|
|
|
-from django.db import IntegrityError, models
|
|
|
+from django.db import IntegrityError, models, transaction
|
|
|
|
|
|
from sentry.constants import ObjectStatus
|
|
|
from sentry.db.models import (
|
|
@@ -11,8 +11,9 @@ from sentry.db.models import (
|
|
|
)
|
|
|
from sentry.db.models.fields.jsonfield import JSONField
|
|
|
from sentry.db.models.manager import BaseManager
|
|
|
+from sentry.db.postgres.roles import in_test_psql_role_override
|
|
|
from sentry.models.integrations.organization_integration import OrganizationIntegration
|
|
|
-from sentry.models.integrations.project_integration import ProjectIntegration
|
|
|
+from sentry.models.outbox import ControlOutbox, OutboxCategory, OutboxScope, find_regions_for_orgs
|
|
|
from sentry.signals import integration_added
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
@@ -34,9 +35,6 @@ class Integration(DefaultFieldsModel):
|
|
|
organizations = models.ManyToManyField(
|
|
|
"sentry.Organization", related_name="integrations", through=OrganizationIntegration
|
|
|
)
|
|
|
- projects = models.ManyToManyField(
|
|
|
- "sentry.Project", related_name="integrations", through=ProjectIntegration
|
|
|
- )
|
|
|
provider = models.CharField(max_length=64)
|
|
|
external_id = models.CharField(max_length=64)
|
|
|
name = models.CharField(max_length=200)
|
|
@@ -60,6 +58,28 @@ class Integration(DefaultFieldsModel):
|
|
|
|
|
|
return integrations.get(self.provider)
|
|
|
|
|
|
+ def delete(self, *args, **kwds):
|
|
|
+ with transaction.atomic(), in_test_psql_role_override("postgres"):
|
|
|
+ for outbox in Integration.outboxes_for_update(self.id):
|
|
|
+ outbox.save()
|
|
|
+ return super().delete(*args, **kwds)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def outboxes_for_update(identifier: int) -> List[ControlOutbox]:
|
|
|
+ org_ids: List[int] = OrganizationIntegration.objects.filter(
|
|
|
+ integration_id=identifier
|
|
|
+ ).values_list("organization_id", flat=True)
|
|
|
+ return [
|
|
|
+ ControlOutbox(
|
|
|
+ shard_scope=OutboxScope.INTEGRATION_SCOPE,
|
|
|
+ shard_identifier=identifier,
|
|
|
+ object_identifier=identifier,
|
|
|
+ category=OutboxCategory.INTEGRATION_UPDATE,
|
|
|
+ region_name=region_name,
|
|
|
+ )
|
|
|
+ for region_name in find_regions_for_orgs(org_ids)
|
|
|
+ ]
|
|
|
+
|
|
|
def get_installation(self, organization_id: int, **kwargs: Any) -> Any:
|
|
|
return self.get_provider().get_installation(self, organization_id, **kwargs)
|
|
|
|