diff --git a/taiga/webhooks/migrations/0002_webhook_name.py b/taiga/webhooks/migrations/0002_webhook_name.py new file mode 100644 index 00000000..9def6115 --- /dev/null +++ b/taiga/webhooks/migrations/0002_webhook_name.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('webhooks', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='webhook', + name='name', + field=models.CharField(max_length=250, default='webhook', verbose_name='name'), + preserve_default=False, + ), + ] diff --git a/taiga/webhooks/models.py b/taiga/webhooks/models.py index af802535..e4a418c1 100644 --- a/taiga/webhooks/models.py +++ b/taiga/webhooks/models.py @@ -23,6 +23,8 @@ from django_pgjson.fields import JsonField class Webhook(models.Model): project = models.ForeignKey("projects.Project", null=False, blank=False, related_name="webhooks") + name = models.CharField(max_length=250, null=False, blank=False, + verbose_name=_("name")) url = models.URLField(null=False, blank=False, verbose_name=_("URL")) key = models.TextField(null=False, blank=False, verbose_name=_("secret key")) diff --git a/taiga/webhooks/serializers.py b/taiga/webhooks/serializers.py index 388e4d5f..7bc08e0f 100644 --- a/taiga/webhooks/serializers.py +++ b/taiga/webhooks/serializers.py @@ -34,9 +34,14 @@ class HistoryDiffField(serializers.Field): class WebhookSerializer(serializers.ModelSerializer): + logs_counter = serializers.SerializerMethodField("get_logs_counter") class Meta: model = Webhook + def get_logs_counter(self, obj): + return obj.logs.count() + + class WebhookLogSerializer(serializers.ModelSerializer): request_data = JsonField() diff --git a/tests/factories.py b/tests/factories.py index 9c96224e..14f120a8 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -205,6 +205,7 @@ class WebhookFactory(Factory): project = factory.SubFactory("tests.factories.ProjectFactory") url = "http://localhost:8080/test" key = "factory-key" + name = "Factory-name" class WebhookLogFactory(Factory): diff --git a/tests/integration/resources_permissions/test_webhooks_resources.py b/tests/integration/resources_permissions/test_webhooks_resources.py index ab5cad17..9514fc88 100644 --- a/tests/integration/resources_permissions/test_webhooks_resources.py +++ b/tests/integration/resources_permissions/test_webhooks_resources.py @@ -137,6 +137,7 @@ def test_webhook_create(client, data): ] create_data = json.dumps({ + "name": "Test", "url": "http://test.com", "key": "test", "project": data.project1.pk, @@ -145,6 +146,7 @@ def test_webhook_create(client, data): assert results == [401, 403, 201] create_data = json.dumps({ + "name": "Test", "url": "http://test.com", "key": "test", "project": data.project2.pk,