-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidation of notification creation (#8824)
* Add basic TestNotificationTriggers * Clean eng * Fix product_added * Correct processing notification for "non-other" sources * Rename "process_notifications" to "process_tag_notifications" * Process product_deleted * process endpoint * process prod type * test URLs * Process others in all notification types * Fix test typo * Process tests * Add processing engagement_deleted * Fix unit tests * Process engagement_pre_save * Move functions to signals.py * "process" findings * "process" test * process finding_group * Fixes * Add test_auditlog_on_off * unittests: move auditloging * event name consolidation * Fix renamed engagement * Fix testing auditlog * Try exclude test_auditlog_on_off * Change get_system_setting('enable_auditlog') to settings.ENABLE_AUDITLOG * Change TODOs * JIRA: more specific event names * Fix Ruff * Fix tests * Unittest: Set username rendering Signed-off-by: kiblik <[email protected]> * Eng: Do not process "Not Started" -> "In Progress" Signed-off-by: kiblik <[email protected]> * Fix Eng ruff * Fix TokenAuthentication * localization --------- Signed-off-by: kiblik <[email protected]>
- Loading branch information
Showing
24 changed files
with
685 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from auditlog.models import LogEntry | ||
from django.conf import settings | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.db.models.signals import post_delete | ||
from django.dispatch import receiver | ||
from django.urls import reverse | ||
from django.utils.translation import gettext as _ | ||
|
||
from dojo.models import Endpoint | ||
from dojo.notifications.helper import create_notification | ||
|
||
|
||
@receiver(post_delete, sender=Endpoint) | ||
def endpoint_post_delete(sender, instance, using, origin, **kwargs): | ||
if instance == origin: | ||
if settings.ENABLE_AUDITLOG: | ||
le = LogEntry.objects.get( | ||
action=LogEntry.Action.DELETE, | ||
content_type=ContentType.objects.get(app_label='dojo', model='endpoint'), | ||
object_id=instance.id | ||
) | ||
description = _('The endpoint "%(name)s" was deleted by %(user)s') % { | ||
'name': str(instance), 'user': le.actor} | ||
else: | ||
description = _('The endpoint "%(name)s" was deleted') % {'name': str(instance)} | ||
create_notification(event='endpoint_deleted', # template does not exists, it will default to "other" but this event name needs to stay because of unit testing | ||
title=_('Deletion of %(name)s') % {'name': str(instance)}, | ||
description=description, | ||
url=reverse('endpoint'), | ||
icon="exclamation-triangle") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from auditlog.models import LogEntry | ||
from django.conf import settings | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.db.models.signals import post_delete, post_save, pre_save | ||
from django.dispatch import receiver | ||
from django.urls import reverse | ||
from django.utils.translation import gettext as _ | ||
|
||
from dojo.models import Engagement | ||
from dojo.notifications.helper import create_notification | ||
|
||
|
||
@receiver(post_save, sender=Engagement) | ||
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,))) | ||
|
||
|
||
@receiver(pre_save, sender=Engagement) | ||
def engagement_pre_save(sender, instance, **kwargs): | ||
old = sender.objects.filter(pk=instance.pk).first() | ||
if old and instance.status != old.status: | ||
if instance.status in ["Cancelled", "Completed"]: | ||
create_notification(event='engagement_closed', | ||
title=_('Closure of %s') % instance.name, | ||
description=_('The engagement "%s" was closed') % (instance.name), | ||
engagement=instance, url=reverse('engagement_all_findings', args=(instance.id, ))) | ||
elif instance.status in ["In Progress"] and old.status not in ["Not Started"]: | ||
create_notification(event='engagement_reopened', | ||
title=_('Reopening of %s') % instance.name, | ||
engagement=instance, | ||
description=_('The engagement "%s" was reopened') % (instance.name), | ||
url=reverse('view_engagement', args=(instance.id, ))) | ||
|
||
|
||
@receiver(post_delete, sender=Engagement) | ||
def engagement_post_delete(sender, instance, using, origin, **kwargs): | ||
if instance == origin: | ||
if settings.ENABLE_AUDITLOG: | ||
le = LogEntry.objects.get( | ||
action=LogEntry.Action.DELETE, | ||
content_type=ContentType.objects.get(app_label='dojo', model='engagement'), | ||
object_id=instance.id | ||
) | ||
description = _('The engagement "%(name)s" was deleted by %(user)s') % { | ||
'name': instance.name, 'user': le.actor} | ||
else: | ||
description = _('The engagement "%(name)s" was deleted') % {'name': instance.name} | ||
create_notification(event='engagement_deleted', # template does not exists, it will default to "other" but this event name needs to stay because of unit testing | ||
title=_('Deletion of %(name)s') % {'name': instance.name}, | ||
description=description, | ||
product=instance.product, | ||
url=reverse('view_product', args=(instance.product.id, )), | ||
recipients=[instance.lead], | ||
icon="exclamation-triangle") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from auditlog.models import LogEntry | ||
from django.conf import settings | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.db.models.signals import post_delete | ||
from django.dispatch import receiver | ||
from django.urls import reverse | ||
from django.utils.translation import gettext as _ | ||
|
||
from dojo.models import Finding_Group | ||
from dojo.notifications.helper import create_notification | ||
|
||
|
||
@receiver(post_delete, sender=Finding_Group) | ||
def finding_group_post_delete(sender, instance, using, origin, **kwargs): | ||
if instance == origin: | ||
if settings.ENABLE_AUDITLOG: | ||
le = LogEntry.objects.get( | ||
action=LogEntry.Action.DELETE, | ||
content_type=ContentType.objects.get(app_label='dojo', model='finding_group'), | ||
object_id=instance.id | ||
) | ||
description = _('The finding group "%(name)s" was deleted by %(user)s') % { | ||
'name': instance.name, 'user': le.actor} | ||
else: | ||
description = _('The finding group "%(name)s" was deleted') % {'name': instance.name} | ||
create_notification(event='finding_group_deleted', # template does not exists, it will default to "other" but this event name needs to stay because of unit testing | ||
title=_('Deletion of %(name)s') % {'name': instance.name}, | ||
description=description, | ||
product=instance.test.engagement.product, | ||
url=reverse('view_test', args=(instance.test.id, )), | ||
icon="exclamation-triangle") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.