Просмотр исходного кода

Fixes #7333: Prevent inadvertent deletion of prior change records when deleting objects

jeremystretch 4 лет назад
Родитель
Сommit
6bccb6d90b
2 измененных файлов с 10 добавлено и 1 удалено
  1. 1 0
      docs/release-notes/version-3.0.md
  2. 9 1
      netbox/extras/graphql/mixins.py

+ 1 - 0
docs/release-notes/version-3.0.md

@@ -11,6 +11,7 @@
 
 
 * [#7321](https://github.com/netbox-community/netbox/issues/7321) - Don't overwrite multi-select custom fields during bulk edit
 * [#7321](https://github.com/netbox-community/netbox/issues/7321) - Don't overwrite multi-select custom fields during bulk edit
 * [#7324](https://github.com/netbox-community/netbox/issues/7324) - Fix TypeError exception in web UI when filtering objects using single-choice filters
 * [#7324](https://github.com/netbox-community/netbox/issues/7324) - Fix TypeError exception in web UI when filtering objects using single-choice filters
+* [#7333](https://github.com/netbox-community/netbox/issues/7333) - Prevent inadvertent deletion of prior change records when deleting objects
 
 
 ## v3.0.3 (2021-09-20)
 ## v3.0.3 (2021-09-20)
 
 

+ 9 - 1
netbox/extras/graphql/mixins.py

@@ -1,6 +1,9 @@
 import graphene
 import graphene
+from django.contrib.contenttypes.models import ContentType
 from graphene.types.generic import GenericScalar
 from graphene.types.generic import GenericScalar
 
 
+from extras.models import ObjectChange
+
 __all__ = (
 __all__ = (
     'ChangelogMixin',
     'ChangelogMixin',
     'ConfigContextMixin',
     'ConfigContextMixin',
@@ -15,7 +18,12 @@ class ChangelogMixin:
     changelog = graphene.List('extras.graphql.types.ObjectChangeType')
     changelog = graphene.List('extras.graphql.types.ObjectChangeType')
 
 
     def resolve_changelog(self, info):
     def resolve_changelog(self, info):
-        return self.object_changes.restrict(info.context.user, 'view')
+        content_type = ContentType.objects.get_for_model(self)
+        object_changes = ObjectChange.objects.filter(
+            changed_object_type=content_type,
+            changed_object_id=self.pk
+        )
+        return object_changes.restrict(info.context.user, 'view')
 
 
 
 
 class ConfigContextMixin:
 class ConfigContextMixin: