Fixed and updated activity stream delete operations

Switched to using pre_delete instead of post_delete to record activity
stream delete operations so we have access to all of the fields that may
be associated with the field (eg things that may be being deleted with
this object through a cascade delete).

Switched to recording the full dict of the object instead of a diff
(since the diff will always be empty).
This commit is contained in:
Akita Noek
2016-04-28 09:49:26 -04:00
parent 521e0645a2
commit 951d728472
2 changed files with 5 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
import logging import logging
from django.db.models.signals import pre_save, post_save, post_delete, m2m_changed from django.db.models.signals import pre_save, post_save, pre_delete, m2m_changed
logger = logging.getLogger('awx.main.registrar') logger = logging.getLogger('awx.main.registrar')
@@ -22,7 +22,7 @@ class ActivityStreamRegistrar(object):
self.models.append(model) self.models.append(model)
post_save.connect(activity_stream_create, sender=model, dispatch_uid=str(self.__class__) + str(model) + "_create") post_save.connect(activity_stream_create, sender=model, dispatch_uid=str(self.__class__) + str(model) + "_create")
pre_save.connect(activity_stream_update, sender=model, dispatch_uid=str(self.__class__) + str(model) + "_update") pre_save.connect(activity_stream_update, sender=model, dispatch_uid=str(self.__class__) + str(model) + "_update")
post_delete.connect(activity_stream_delete, sender=model, dispatch_uid=str(self.__class__) + str(model) + "_delete") pre_delete.connect(activity_stream_delete, sender=model, dispatch_uid=str(self.__class__) + str(model) + "_delete")
for m2mfield in model._meta.many_to_many: for m2mfield in model._meta.many_to_many:
try: try:
@@ -36,7 +36,7 @@ class ActivityStreamRegistrar(object):
if model in self.models: if model in self.models:
post_save.disconnect(dispatch_uid=str(self.__class__) + str(model) + "_create") post_save.disconnect(dispatch_uid=str(self.__class__) + str(model) + "_create")
pre_save.disconnect(dispatch_uid=str(self.__class__) + str(model) + "_update") pre_save.disconnect(dispatch_uid=str(self.__class__) + str(model) + "_update")
post_delete.disconnect(dispatch_uid=str(self.__class__) + str(model) + "_delete") pre_delete.disconnect(dispatch_uid=str(self.__class__) + str(model) + "_delete")
self.models.pop(model) self.models.pop(model)

View File

@@ -340,14 +340,10 @@ def activity_stream_update(sender, instance, **kwargs):
def activity_stream_delete(sender, instance, **kwargs): def activity_stream_delete(sender, instance, **kwargs):
if not activity_stream_enabled: if not activity_stream_enabled:
return return
try:
old = sender.objects.get(id=instance.id)
except sender.DoesNotExist:
return
# Skip recording any inventory source directly associated with a group. # Skip recording any inventory source directly associated with a group.
if isinstance(instance, InventorySource) and instance.group: if isinstance(instance, InventorySource) and instance.group:
return return
changes = model_instance_diff(old, instance) changes = model_to_dict(instance)
object1 = camelcase_to_underscore(instance.__class__.__name__) object1 = camelcase_to_underscore(instance.__class__.__name__)
activity_entry = ActivityStream( activity_entry = ActivityStream(
operation='delete', operation='delete',