Add is_from_connected_integration field to webhook model (#3951)

Related to https://github.com/grafana/oncall-private/issues/2541.
This commit is contained in:
Matias Bordese 2024-02-23 12:57:57 -03:00 committed by GitHub
parent d2917373b7
commit 19b5c6553c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 31 additions and 2 deletions

View file

@ -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")

View file

@ -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()

View file

@ -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")

View file

@ -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)

View file

@ -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),
),
]

View file

@ -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")