mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 01:48:21 +02:00
Don't trigger signals when we add an object through a permission check
This commit is contained in:
@ -57,8 +57,8 @@ class InstancedPermission:
|
||||
|
||||
# Force insertion, no data verification, no trigger
|
||||
obj._force_save = True
|
||||
# We don't want log anything
|
||||
obj._no_log = True
|
||||
# We don't want to trigger any signal (log, ...)
|
||||
obj.no_signal = True
|
||||
Model.save(obj, force_insert=True)
|
||||
ret = self.model.model_class().objects.filter(self.query & Q(pk=0)).exists()
|
||||
# Delete testing object
|
||||
|
@ -28,7 +28,7 @@ def pre_save_object(sender, instance, **kwargs):
|
||||
if instance._meta.label_lower in EXCLUDED:
|
||||
return
|
||||
|
||||
if hasattr(instance, "_force_save"):
|
||||
if hasattr(instance, "_force_save") or hasattr(instance, "_no_signal"):
|
||||
return
|
||||
|
||||
user = get_current_authenticated_user()
|
||||
@ -82,7 +82,8 @@ def pre_delete_object(instance, **kwargs):
|
||||
if instance._meta.label_lower in EXCLUDED:
|
||||
return
|
||||
|
||||
if hasattr(instance, "_force_delete") or hasattr(instance, "pk") and instance.pk == 0:
|
||||
if hasattr(instance, "_force_delete") or hasattr(instance, "pk") and instance.pk == 0 \
|
||||
or hasattr(instance, "_no_signal"):
|
||||
# Don't check permissions on force-deleted objects
|
||||
return
|
||||
|
||||
|
Reference in New Issue
Block a user