Skip to content

Commit

Permalink
Rename url to url_ui and add url_api
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Aug 26, 2024
1 parent f6b5a48 commit 16f1ab7
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```
31 changes: 22 additions & 9 deletions docs/content/en/integrations/notification_webhooks/scan_added.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -31,47 +33,58 @@ 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": [
{
"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": [
{
"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": [
{
"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
}
```
19 changes: 14 additions & 5 deletions docs/content/en/integrations/notification_webhooks/test_added.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```
2 changes: 1 addition & 1 deletion dojo/engagement/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions dojo/notifications/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[]):
Expand All @@ -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,)))
4 changes: 3 additions & 1 deletion dojo/product/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion dojo/product_type/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion dojo/templates/notifications/webhooks/subtemplates/base.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 5 additions & 0 deletions dojo/templates/notifications/webhooks/subtemplates/test.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
Loading

0 comments on commit 16f1ab7

Please sign in to comment.