From 2d9882930d510ce25374283523a6beedbf9c6f79 Mon Sep 17 00:00:00 2001 From: Michael Wedl Date: Mon, 8 Jul 2024 09:26:39 +0200 Subject: [PATCH] Prevent creating collab events during backup restore --- api/src/reportcreator_api/pentests/signals.py | 1 + api/src/reportcreator_api/tests/test_backup.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/api/src/reportcreator_api/pentests/signals.py b/api/src/reportcreator_api/pentests/signals.py index 92d43ad70..198866c64 100644 --- a/api/src/reportcreator_api/pentests/signals.py +++ b/api/src/reportcreator_api/pentests/signals.py @@ -409,6 +409,7 @@ def uploaded_file_deleted(sender, instance, *args, **kwargs): @receiver(signals.post_save, sender=PentestProject) @receiver(signals.post_save, sender=Comment) @receiver(signals.post_save, sender=CommentAnswer) +@disable_for_loaddata def collab_updated(sender, instance, created=False, *args, **kwargs): from reportcreator_api.pentests.consumers import send_collab_event_project, send_collab_event_user from reportcreator_api.pentests.serializers.notes import ( diff --git a/api/src/reportcreator_api/tests/test_backup.py b/api/src/reportcreator_api/tests/test_backup.py index 1f7b14af7..736910b15 100644 --- a/api/src/reportcreator_api/tests/test_backup.py +++ b/api/src/reportcreator_api/tests/test_backup.py @@ -20,6 +20,8 @@ from reportcreator_api.management.commands import restorebackup from reportcreator_api.notifications.models import NotificationSpec from reportcreator_api.pentests.models import UploadedImage +from reportcreator_api.pentests.models.collab import CollabClientInfo, CollabEvent +from reportcreator_api.pentests.models.common import LockInfo from reportcreator_api.tests.mock import ( api_client, create_archived_project, @@ -230,6 +232,11 @@ def test_backup_restore(self): assert fo.file.name == f['name'] assert fo.file.read() == f['content'] + # No temporary DB data created + assert CollabEvent.objects.count() == 0 + assert CollabClientInfo.objects.count() == 0 + assert LockInfo.objects.count() == 0 + # BackupLog entry created assert list(BackupLog.objects.values_list('type', flat=True)) == [BackupLogType.RESTORE, BackupLogType.BACKUP, BackupLogType.SETUP]