diff --git a/engine/apps/api/tests/test_webhooks.py b/engine/apps/api/tests/test_webhooks.py index 274e7dab..28cb3ad0 100644 --- a/engine/apps/api/tests/test_webhooks.py +++ b/engine/apps/api/tests/test_webhooks.py @@ -32,8 +32,11 @@ def webhook_internal_api_setup(make_organization_and_user_with_plugin_token, mak @pytest.mark.django_db -def test_get_list_webhooks(webhook_internal_api_setup, make_user_auth_headers): +def test_get_list_webhooks(webhook_internal_api_setup, make_custom_webhook, make_user_auth_headers): user, token, webhook = webhook_internal_api_setup + # connected integration webhooks are not included + make_custom_webhook(organization=user.organization, is_from_connected_integration=True) + client = APIClient() url = reverse("api-internal:webhooks-list") diff --git a/engine/apps/api/views/webhooks.py b/engine/apps/api/views/webhooks.py index dd836a0e..b17c68bf 100644 --- a/engine/apps/api/views/webhooks.py +++ b/engine/apps/api/views/webhooks.py @@ -94,6 +94,7 @@ class WebhooksView(TeamFilteringMixin, PublicPrimaryKeyMixin[Webhook], ModelView def get_queryset(self, ignore_filtering_by_available_teams=False): queryset = Webhook.objects.filter( organization=self.request.auth.organization, + is_from_connected_integration=False, ) if not ignore_filtering_by_available_teams: queryset = queryset.filter(*self.available_teams_lookup_args).distinct() diff --git a/engine/apps/public_api/tests/test_webhooks.py b/engine/apps/public_api/tests/test_webhooks.py index 35af79e3..eaccd119 100644 --- a/engine/apps/public_api/tests/test_webhooks.py +++ b/engine/apps/public_api/tests/test_webhooks.py @@ -37,6 +37,8 @@ def test_get_webhooks(make_organization_and_user_with_token, make_custom_webhook client = APIClient() webhook = make_custom_webhook(organization=organization) + # connected integration webhooks are not included + make_custom_webhook(organization=organization, is_from_connected_integration=True) url = reverse("api-public:webhooks-list") diff --git a/engine/apps/public_api/views/webhooks.py b/engine/apps/public_api/views/webhooks.py index b6a43c13..e8d7ed58 100644 --- a/engine/apps/public_api/views/webhooks.py +++ b/engine/apps/public_api/views/webhooks.py @@ -34,7 +34,10 @@ class WebhooksView(RateLimitHeadersMixin, UpdateSerializerMixin, ModelViewSet): def get_queryset(self): webhook_name = self.request.query_params.get("name", None) - queryset = Webhook.objects.filter(organization=self.request.auth.organization) + queryset = Webhook.objects.filter( + organization=self.request.auth.organization, + is_from_connected_integration=False, + ) if webhook_name: queryset = queryset.filter(name=webhook_name) diff --git a/engine/apps/webhooks/migrations/0015_webhook_is_from_connected_integration.py b/engine/apps/webhooks/migrations/0015_webhook_is_from_connected_integration.py new file mode 100644 index 00000000..b974b837 --- /dev/null +++ b/engine/apps/webhooks/migrations/0015_webhook_is_from_connected_integration.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.10 on 2024-02-22 17:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webhooks', '0014_webhook_filtered_integrations'), + ] + + operations = [ + migrations.AddField( + model_name='webhook', + name='is_from_connected_integration', + field=models.BooleanField(default=False, null=True), + ), + ] diff --git a/engine/apps/webhooks/models/webhook.py b/engine/apps/webhooks/models/webhook.py index a169140d..1e9fd2b7 100644 --- a/engine/apps/webhooks/models/webhook.py +++ b/engine/apps/webhooks/models/webhook.py @@ -158,6 +158,8 @@ class Webhook(models.Model): is_legacy = models.BooleanField(null=True, default=False) preset = models.CharField(max_length=100, null=True, blank=True, default=None) + is_from_connected_integration = models.BooleanField(null=True, default=False) + class Meta: unique_together = ("name", "organization")