From 16f1ab7c0349d06c4713ec15173f18728ec34860 Mon Sep 17 00:00:00 2001 From: kiblik <5609770+kiblik@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:44:28 +0200 Subject: [PATCH] Rename `url` to `url_ui` and add `url_api` --- .../notification_webhooks/engagement_added.md | 15 +++-- .../notification_webhooks/product_added.md | 11 +++- .../product_type_added.md | 7 ++- .../notification_webhooks/scan_added.md | 31 ++++++++--- .../notification_webhooks/test_added.md | 19 +++++-- dojo/engagement/signals.py | 2 +- dojo/notifications/helper.py | 4 +- dojo/product/signals.py | 4 +- dojo/product_type/signals.py | 4 +- .../webhooks/subtemplates/base.tpl | 5 +- .../webhooks/subtemplates/engagement.tpl | 5 ++ .../webhooks/subtemplates/findings_list.tpl | 6 +- .../webhooks/subtemplates/product.tpl | 5 ++ .../webhooks/subtemplates/product_type.tpl | 5 ++ .../webhooks/subtemplates/test.tpl | 5 ++ unittests/test_notifications.py | 55 ++++++++++++++++--- 16 files changed, 143 insertions(+), 40 deletions(-) diff --git a/docs/content/en/integrations/notification_webhooks/engagement_added.md b/docs/content/en/integrations/notification_webhooks/engagement_added.md index 2d69d4bf299..64fd7746ec2 100644 --- a/docs/content/en/integrations/notification_webhooks/engagement_added.md +++ b/docs/content/en/integrations/notification_webhooks/engagement_added.md @@ -15,17 +15,24 @@ X-DefectDojo-Event: engagement_added "description": null, "engagement": { "id": 7, - "name": "notif eng" + "name": "notif eng", + "url_api": "http://localhost:8080/api/v2/engagements/7/", + "url_ui": "http://localhost:8080/engagement/7" }, "product": { "id": 4, - "name": "notif prod" + "name": "notif prod", + "url_api": "http://localhost:8080/api/v2/products/4/", + "url_ui": "http://localhost:8080/product/4" }, "product_type": { "id": 4, - "name": "notif prod type" + "name": "notif prod type", + "url_api": "http://localhost:8080/api/v2/product_types/4/", + "url_ui": "http://localhost:8080/product/type/4" }, - "url": "http://localhost:8080/engagement/7", + "url_api": "http://localhost:8080/api/v2/engagements/7/", + "url_ui": "http://localhost:8080/engagement/7", "user": null } ``` \ No newline at end of file diff --git a/docs/content/en/integrations/notification_webhooks/product_added.md b/docs/content/en/integrations/notification_webhooks/product_added.md index 1c0ace44def..2d90a6a681f 100644 --- a/docs/content/en/integrations/notification_webhooks/product_added.md +++ b/docs/content/en/integrations/notification_webhooks/product_added.md @@ -15,13 +15,18 @@ X-DefectDojo-Event: product_added "description": null, "product": { "id": 4, - "name": "notif prod" + "name": "notif prod", + "url_api": "http://localhost:8080/api/v2/products/4/", + "url_ui": "http://localhost:8080/product/4" }, "product_type": { "id": 4, - "name": "notif prod type" + "name": "notif prod type", + "url_api": "http://localhost:8080/api/v2/product_types/4/", + "url_ui": "http://localhost:8080/product/type/4" }, - "url": "http://localhost:8080/product/4", + "url_api": "http://localhost:8080/api/v2/products/4/", + "url_ui": "http://localhost:8080/product/4", "user": null } ``` \ No newline at end of file diff --git a/docs/content/en/integrations/notification_webhooks/product_type_added.md b/docs/content/en/integrations/notification_webhooks/product_type_added.md index 5b5168002e9..1171f513831 100644 --- a/docs/content/en/integrations/notification_webhooks/product_type_added.md +++ b/docs/content/en/integrations/notification_webhooks/product_type_added.md @@ -15,9 +15,12 @@ X-DefectDojo-Event: product_type_added "description": null, "product_type": { "id": 4, - "name": "notif prod type" + "name": "notif prod type", + "url_api": "http://localhost:8080/api/v2/product_types/4/", + "url_ui": "http://localhost:8080/product/type/4" }, - "url": "http://localhost:8080/product/type/4", + "url_api": "http://localhost:8080/api/v2/product_types/4/", + "url_ui": "http://localhost:8080/product/type/4", "user": null } ``` \ No newline at end of file diff --git a/docs/content/en/integrations/notification_webhooks/scan_added.md b/docs/content/en/integrations/notification_webhooks/scan_added.md index d02146932da..27a40e6cab1 100644 --- a/docs/content/en/integrations/notification_webhooks/scan_added.md +++ b/docs/content/en/integrations/notification_webhooks/scan_added.md @@ -22,7 +22,9 @@ X-DefectDojo-Event: scan_added_empty "description": null, "engagement": { "id": 7, - "name": "notif eng" + "name": "notif eng", + "url_api": "http://localhost:8080/api/v2/engagements/7/", + "url_ui": "http://localhost:8080/engagement/7" }, "finding_count": 4, "findings": { @@ -31,7 +33,8 @@ X-DefectDojo-Event: scan_added_empty "id": 233, "severity": "Medium", "title": "Mitigated Finding", - "url": "http://localhost:8080/finding/233" + "url_api": "http://localhost:8080/api/v2/findings/233/", + "url_ui": "http://localhost:8080/finding/233" } ], "new": [ @@ -39,7 +42,8 @@ X-DefectDojo-Event: scan_added_empty "id": 232, "severity": "Critical", "title": "New Finding", - "url": "http://localhost:8080/finding/232" + "url_api": "http://localhost:8080/api/v2/findings/232/", + "url_ui": "http://localhost:8080/finding/232" } ], "reactivated": [ @@ -47,7 +51,8 @@ X-DefectDojo-Event: scan_added_empty "id": 234, "severity": "Low", "title": "Reactivated Finding", - "url": "http://localhost:8080/finding/234" + "url_api": "http://localhost:8080/api/v2/findings/234/", + "url_ui": "http://localhost:8080/finding/234" } ], "untouched": [ @@ -55,23 +60,31 @@ X-DefectDojo-Event: scan_added_empty "id": 235, "severity": "Info", "title": "Untouched Finding", - "url": "http://localhost:8080/finding/235" + "url_api": "http://localhost:8080/api/v2/findings/235/", + "url_ui": "http://localhost:8080/finding/235" } ] }, "product": { "id": 4, - "name": "notif prod" + "name": "notif prod", + "url_api": "http://localhost:8080/api/v2/products/4/", + "url_ui": "http://localhost:8080/product/4" }, "product_type": { "id": 4, - "name": "notif prod type" + "name": "notif prod type", + "url_api": "http://localhost:8080/api/v2/product_types/4/", + "url_ui": "http://localhost:8080/product/type/4" }, "test": { "id": 90, - "title": "notif test" + "title": "notif test", + "url_api": "http://localhost:8080/api/v2/tests/90/", + "url_ui": "http://localhost:8080/test/90" }, - "url": "http://localhost:8080/test/90", + "url_api": "http://localhost:8080/api/v2/tests/90/", + "url_ui": "http://localhost:8080/test/90", "user": null } ``` \ No newline at end of file diff --git a/docs/content/en/integrations/notification_webhooks/test_added.md b/docs/content/en/integrations/notification_webhooks/test_added.md index 6295d513535..8614a80e0a6 100644 --- a/docs/content/en/integrations/notification_webhooks/test_added.md +++ b/docs/content/en/integrations/notification_webhooks/test_added.md @@ -15,21 +15,30 @@ X-DefectDojo-Event: test_added "description": null, "engagement": { "id": 7, - "name": "notif eng" + "name": "notif eng", + "url_api": "http://localhost:8080/api/v2/engagements/7/", + "url_ui": "http://localhost:8080/engagement/7" }, "product": { "id": 4, - "name": "notif prod" + "name": "notif prod", + "url_api": "http://localhost:8080/api/v2/products/4/", + "url_ui": "http://localhost:8080/product/4" }, "product_type": { "id": 4, - "name": "notif prod type" + "name": "notif prod type", + "url_api": "http://localhost:8080/api/v2/product_types/4/", + "url_ui": "http://localhost:8080/product/type/4" }, "test": { "id": 90, - "title": "notif test" + "title": "notif test", + "url_api": "http://localhost:8080/api/v2/tests/90/", + "url_ui": "http://localhost:8080/test/90" }, - "url": "http://localhost:8080/test/90", + "url_api": "http://localhost:8080/api/v2/tests/90/", + "url_ui": "http://localhost:8080/test/90", "user": null } ``` \ No newline at end of file diff --git a/dojo/engagement/signals.py b/dojo/engagement/signals.py index c2f09c9abbd..7b95d6fe87b 100644 --- a/dojo/engagement/signals.py +++ b/dojo/engagement/signals.py @@ -16,7 +16,7 @@ def engagement_post_save(sender, instance, created, **kwargs): if created: title = _('Engagement created for "%(product)s": %(name)s') % {"product": instance.product, "name": instance.name} create_notification(event="engagement_added", title=title, engagement=instance, product=instance.product, - url=reverse("view_engagement", args=(instance.id,))) + url=reverse("view_engagement", args=(instance.id,)), url_api=reverse("engagement-detail", args=(instance.id,))) @receiver(pre_save, sender=Engagement) diff --git a/dojo/notifications/helper.py b/dojo/notifications/helper.py index afddffec4d9..7fa5b1d1c19 100644 --- a/dojo/notifications/helper.py +++ b/dojo/notifications/helper.py @@ -558,7 +558,7 @@ def log_alert(e, notification_type=None, *args, **kwargs): def notify_test_created(test): title = "Test created for " + str(test.engagement.product) + ": " + str(test.engagement.name) + ": " + str(test) create_notification(event="test_added", title=title, test=test, engagement=test.engagement, product=test.engagement.product, - url=reverse("view_test", args=(test.id,))) + url=reverse("view_test", args=(test.id,)), url_api=reverse("test-detail", args=(test.id,))) def notify_scan_added(test, updated_count, new_findings=[], findings_mitigated=[], findings_reactivated=[], findings_untouched=[]): @@ -578,4 +578,4 @@ def notify_scan_added(test, updated_count, new_findings=[], findings_mitigated=[ create_notification(event=event, title=title, findings_new=new_findings, findings_mitigated=findings_mitigated, findings_reactivated=findings_reactivated, finding_count=updated_count, test=test, engagement=test.engagement, product=test.engagement.product, findings_untouched=findings_untouched, - url=reverse("view_test", args=(test.id,))) + url=reverse("view_test", args=(test.id,)), url_api=reverse("test-detail", args=(test.id,))) diff --git a/dojo/product/signals.py b/dojo/product/signals.py index 6871f5490d2..72e9771e82c 100644 --- a/dojo/product/signals.py +++ b/dojo/product/signals.py @@ -16,7 +16,9 @@ def product_post_save(sender, instance, created, **kwargs): create_notification(event="product_added", title=instance.name, product=instance, - url=reverse("view_product", args=(instance.id,))) + url=reverse("view_product", args=(instance.id,)), + url_api=reverse("product-detail", args=(instance.id,)), + ) @receiver(post_delete, sender=Product) diff --git a/dojo/product_type/signals.py b/dojo/product_type/signals.py index dde3ff502cd..743995768eb 100644 --- a/dojo/product_type/signals.py +++ b/dojo/product_type/signals.py @@ -16,7 +16,9 @@ def product_type_post_save(sender, instance, created, **kwargs): create_notification(event="product_type_added", title=instance.name, product_type=instance, - url=reverse("view_product_type", args=(instance.id,))) + url=reverse("view_product_type", args=(instance.id,)), + url_api=reverse("product_type-detail", args=(instance.id,)), + ) @receiver(post_delete, sender=Product_Type) diff --git a/dojo/templates/notifications/webhooks/subtemplates/base.tpl b/dojo/templates/notifications/webhooks/subtemplates/base.tpl index b5f1152e12c..44946cd8dd3 100644 --- a/dojo/templates/notifications/webhooks/subtemplates/base.tpl +++ b/dojo/templates/notifications/webhooks/subtemplates/base.tpl @@ -3,7 +3,10 @@ description: {{ description | default_if_none:'' }} user: {{ user | default_if_none:'' }} {% if url %} -url: {{ url|full_url }} +url_ui: {{ url|full_url }} +{% endif %} +{% if url_api %} +url_api: {{ url_api|full_url }} {% endif %} {% if system_settings.disclaimer and system_settings.disclaimer.strip %} disclaimer: {{ system_settings.disclaimer }} diff --git a/dojo/templates/notifications/webhooks/subtemplates/engagement.tpl b/dojo/templates/notifications/webhooks/subtemplates/engagement.tpl index 57b95068d9c..87504a1a479 100644 --- a/dojo/templates/notifications/webhooks/subtemplates/engagement.tpl +++ b/dojo/templates/notifications/webhooks/subtemplates/engagement.tpl @@ -1,8 +1,13 @@ +{% load display_tags %} {% if product %} {% include 'notifications/webhooks/subtemplates/product.tpl' with product=product %} {% else %} {% include 'notifications/webhooks/subtemplates/product.tpl' with product=engagement.product %} {% endif %} +{% url 'view_engagement' engagement.id as engagement_url_ui %} +{% url 'engagement-detail' engagement.id as engagement_url_api %} engagement: name: {{ engagement.name | default_if_none:'' }} id: {{ engagement.pk }} + url_ui: {{ engagement_url_ui|full_url }} + url_api: {{ engagement_url_api|full_url }} diff --git a/dojo/templates/notifications/webhooks/subtemplates/findings_list.tpl b/dojo/templates/notifications/webhooks/subtemplates/findings_list.tpl index 298113362f6..dea59ad1613 100644 --- a/dojo/templates/notifications/webhooks/subtemplates/findings_list.tpl +++ b/dojo/templates/notifications/webhooks/subtemplates/findings_list.tpl @@ -1,10 +1,12 @@ {% load display_tags %} {% for finding in findings %} -{% url 'view_finding' finding.id as finding_url %} +{% url 'view_finding' finding.id as finding_url_ui %} +{% url 'finding-detail' finding.id as finding_url_api %} - id: {{ finding.pk }} title: {{ finding.title | default_if_none:'' }} severity: {{ finding.severity | default_if_none:'' }} - url: {{ finding_url|full_url }} + url_ui: {{ finding_url_ui|full_url }} + url_api: {{ finding_url_api|full_url }} {% empty %} [] {% endfor %} diff --git a/dojo/templates/notifications/webhooks/subtemplates/product.tpl b/dojo/templates/notifications/webhooks/subtemplates/product.tpl index b1d4d0355f9..dba5d7b1619 100644 --- a/dojo/templates/notifications/webhooks/subtemplates/product.tpl +++ b/dojo/templates/notifications/webhooks/subtemplates/product.tpl @@ -1,8 +1,13 @@ +{% load display_tags %} {% if product_type %} {% include 'notifications/webhooks/subtemplates/product_type.tpl' with product_type=product_type %} {% else %} {% include 'notifications/webhooks/subtemplates/product_type.tpl' with product_type=product.prod_type %} {% endif %} +{% url 'view_product' product.id as product_url_ui %} +{% url 'product-detail' product.id as product_url_api %} product: name: {{ product.name | default_if_none:'' }} id: {{ product.pk }} + url_ui: {{ product_url_ui|full_url }} + url_api: {{ product_url_api|full_url }} diff --git a/dojo/templates/notifications/webhooks/subtemplates/product_type.tpl b/dojo/templates/notifications/webhooks/subtemplates/product_type.tpl index 49cdd4c508d..9eb39e7b130 100644 --- a/dojo/templates/notifications/webhooks/subtemplates/product_type.tpl +++ b/dojo/templates/notifications/webhooks/subtemplates/product_type.tpl @@ -1,3 +1,8 @@ +{% load display_tags %} +{% url 'view_product_type' product_type.id as product_type_url_ui %} +{% url 'product_type-detail' product_type.id as product_type_url_api %} product_type: name: {{ product_type.name | default_if_none:'' }} id: {{ product_type.pk }} + url_ui: {{ product_type_url_ui|full_url }} + url_api: {{ product_type_url_api|full_url }} diff --git a/dojo/templates/notifications/webhooks/subtemplates/test.tpl b/dojo/templates/notifications/webhooks/subtemplates/test.tpl index 9cea22d0481..28df2b437ea 100644 --- a/dojo/templates/notifications/webhooks/subtemplates/test.tpl +++ b/dojo/templates/notifications/webhooks/subtemplates/test.tpl @@ -1,8 +1,13 @@ +{% load display_tags %} {% if engagement %} {% include 'notifications/webhooks/subtemplates/engagement.tpl' with engagement=engagement %} {% else %} {% include 'notifications/webhooks/subtemplates/engagement.tpl' with engagement=test.engagement %} {% endif %} +{% url 'view_test' test.id as test_url_ui %} +{% url 'test-detail' test.id as test_url_api %} test: title: {{ test.title | default_if_none:'' }} id: {{ test.pk }} + url_ui: {{ test_url_ui|full_url }} + url_api: {{ test_url_api|full_url }} diff --git a/unittests/test_notifications.py b/unittests/test_notifications.py index 4f188dbafe4..7f5a2b76a4c 100644 --- a/unittests/test_notifications.py +++ b/unittests/test_notifications.py @@ -683,10 +683,13 @@ def test_events_messages(self, mock): self.assertEqual(mock.call_args.kwargs["json"], { "description": None, "user": None, - "url": f"http://localhost:8080/product/type/{prod_type.pk}", + "url_api": f"http://localhost:8080/api/v2/product_types/{prod_type.pk}/", + "url_ui": f"http://localhost:8080/product/type/{prod_type.pk}", "product_type": { "id": prod_type.pk, "name": "notif prod type", + "url_api": f"http://localhost:8080/api/v2/product_types/{prod_type.pk}/", + "url_ui": f"http://localhost:8080/product/type/{prod_type.pk}", }, }) @@ -696,14 +699,19 @@ def test_events_messages(self, mock): self.assertEqual(mock.call_args.kwargs["json"], { "description": None, "user": None, - "url": f"http://localhost:8080/product/{prod.pk}", + "url_api": f"http://localhost:8080/api/v2/products/{prod.pk}/", + "url_ui": f"http://localhost:8080/product/{prod.pk}", "product_type": { "id": prod_type.pk, "name": "notif prod type", + "url_api": f"http://localhost:8080/api/v2/product_types/{prod_type.pk}/", + "url_ui": f"http://localhost:8080/product/type/{prod_type.pk}", }, "product": { "id": prod.pk, "name": "notif prod", + "url_api": f"http://localhost:8080/api/v2/products/{prod.pk}/", + "url_ui": f"http://localhost:8080/product/{prod.pk}", }, }) @@ -713,18 +721,25 @@ def test_events_messages(self, mock): self.assertEqual(mock.call_args.kwargs["json"], { "description": None, "user": None, - "url": f"http://localhost:8080/engagement/{eng.pk}", + "url_api": f"http://localhost:8080/api/v2/engagements/{eng.pk}/", + "url_ui": f"http://localhost:8080/engagement/{eng.pk}", "product_type": { "id": prod_type.pk, "name": "notif prod type", + "url_api": f"http://localhost:8080/api/v2/product_types/{prod_type.pk}/", + "url_ui": f"http://localhost:8080/product/type/{prod_type.pk}", }, "product": { "id": prod.pk, "name": "notif prod", + "url_api": f"http://localhost:8080/api/v2/products/{prod.pk}/", + "url_ui": f"http://localhost:8080/product/{prod.pk}", }, "engagement": { "id": eng.pk, "name": "notif eng", + "url_api": f"http://localhost:8080/api/v2/engagements/{eng.pk}/", + "url_ui": f"http://localhost:8080/engagement/{eng.pk}", }, }) @@ -735,22 +750,31 @@ def test_events_messages(self, mock): self.assertEqual(mock.call_args.kwargs["json"], { "description": None, "user": None, - "url": f"http://localhost:8080/test/{test.pk}", + "url_api": f"http://localhost:8080/api/v2/tests/{test.pk}/", + "url_ui": f"http://localhost:8080/test/{test.pk}", "product_type": { "id": prod_type.pk, "name": "notif prod type", + "url_api": f"http://localhost:8080/api/v2/product_types/{prod_type.pk}/", + "url_ui": f"http://localhost:8080/product/type/{prod_type.pk}", }, "product": { "id": prod.pk, "name": "notif prod", + "url_api": f"http://localhost:8080/api/v2/products/{prod.pk}/", + "url_ui": f"http://localhost:8080/product/{prod.pk}", }, "engagement": { "id": eng.pk, "name": "notif eng", + "url_api": f"http://localhost:8080/api/v2/engagements/{eng.pk}/", + "url_ui": f"http://localhost:8080/engagement/{eng.pk}", }, "test": { "id": test.pk, "title": "notif test", + "url_api": f"http://localhost:8080/api/v2/tests/{test.pk}/", + "url_ui": f"http://localhost:8080/test/{test.pk}", }, }) @@ -760,22 +784,31 @@ def test_events_messages(self, mock): self.assertEqual(mock.call_args.kwargs["json"], { "description": None, "user": None, - "url": f"http://localhost:8080/test/{test.pk}", + "url_api": f"http://localhost:8080/api/v2/tests/{test.pk}/", + "url_ui": f"http://localhost:8080/test/{test.pk}", "product_type": { "id": prod_type.pk, "name": "notif prod type", + "url_api": f"http://localhost:8080/api/v2/product_types/{prod_type.pk}/", + "url_ui": f"http://localhost:8080/product/type/{prod_type.pk}", }, "product": { "id": prod.pk, "name": "notif prod", + "url_api": f"http://localhost:8080/api/v2/products/{prod.pk}/", + "url_ui": f"http://localhost:8080/product/{prod.pk}", }, "engagement": { "id": eng.pk, "name": "notif eng", + "url_api": f"http://localhost:8080/api/v2/engagements/{eng.pk}/", + "url_ui": f"http://localhost:8080/engagement/{eng.pk}", }, "test": { "id": test.pk, "title": "notif test", + "url_api": f"http://localhost:8080/api/v2/tests/{test.pk}/", + "url_ui": f"http://localhost:8080/test/{test.pk}", }, "finding_count": 0, "findings": { @@ -809,24 +842,28 @@ def test_events_messages(self, mock): "id": 232, "title": "New Finding", "severity": "Critical", - "url": "http://localhost:8080/finding/232", + "url_api": "http://localhost:8080/api/v2/findings/232/", + "url_ui": "http://localhost:8080/finding/232", }], "mitigated": [{ "id": 233, "title": "Mitigated Finding", "severity": "Medium", - "url": "http://localhost:8080/finding/233", + "url_api": "http://localhost:8080/api/v2/findings/233/", + "url_ui": "http://localhost:8080/finding/233", }], "reactivated": [{ "id": 234, "title": "Reactivated Finding", "severity": "Low", - "url": "http://localhost:8080/finding/234", + "url_api": "http://localhost:8080/api/v2/findings/234/", + "url_ui": "http://localhost:8080/finding/234", }], "untouched": [{ "id": 235, "title": "Untouched Finding", "severity": "Info", - "url": "http://localhost:8080/finding/235", + "url_api": "http://localhost:8080/api/v2/findings/235/", + "url_ui": "http://localhost:8080/finding/235", }], })