audit-stash icon indicating copy to clipboard operation
audit-stash copied to clipboard

Why doesn't AuditDeleteEvent track the original entity?

Open kevinquinnyo opened this issue 7 years ago • 11 comments

The AuditDeleteEvent implements EventInterface but unlike AuditCreateEvent and AuditUpdateEvent, does not extend the BaseEvent class and as such, does not keep track of the original and changed values.

We know that the changed value is meaningless on a delete, but it seems like it should be tracking the original value shouldn't it?

If this were to be added, could it simply be passed to the AuditDeleteEvent::__construct() as an optional (default null) value?

I'd be happy to patch unless there's a specific reason the original entity data is not being tracked on deletes.

Thanks!

kevinquinnyo avatar Sep 11 '17 20:09 kevinquinnyo

What's the purpose of having the original data there for you?

lorenzo avatar Sep 11 '17 21:09 lorenzo

For my uses, our application is mostly used internally by company employees, and being able to track when an entity was deleted (perhaps carelessly or mistakenly) by an employee seems useful. I can however also see why someone would not care to track that.

kevinquinnyo avatar Sep 11 '17 21:09 kevinquinnyo

@kevinquinnyo but this does track when the entity was deleted, doesn't it? Or you mean that you wanted to store the last known state of the entity before it gets deleted

lorenzo avatar Sep 12 '17 14:09 lorenzo

Or you mean that you wanted to store the last known state of the entity before it gets deleted

Yes. I was thinking that the ~~primary key of the record that was deleted~~ date the record was deleted isn't too meaningful from the perspective of an audit trail, so it would be nice to see what data was there previously.

edit: still need more coffee, brain not working

kevinquinnyo avatar Sep 12 '17 14:09 kevinquinnyo

You also get the primary key of the record. The way I use this internally is that I show all events per primary key. I can see a full history of changes from the moment it gets created to the moment it gets deleted.

I don't see a problem in having the original entity in the delete event, though. If you send a PR with tests I'll merge it

lorenzo avatar Sep 12 '17 14:09 lorenzo

@lorenzo that's a good point actually. It might still be a good idea to have it on the delete event in case the entity was originally seeded through migrations or otherwise not tracked by the behavior.

I might send a PR later if I think I still need it, thanks!

kevinquinnyo avatar Sep 12 '17 15:09 kevinquinnyo

Having the deleted data would be useful for me, as most of my users just look through Kibana to see changes. This would save them some time for seeing what was deleted.

aceat64 avatar Oct 05 '17 22:10 aceat64

Hi.. very useful plugin, but as kevinquinnyo commented, it's useful to see what data was deleted and not only the primary key.. can you add this? I will try to add this functionality.. but if someone already did it.. please share..

GeekWiinik avatar Oct 26 '17 13:10 GeekWiinik

I'm willing to accept pull requests for this

lorenzo avatar Jun 12 '18 22:06 lorenzo

+1 Having the deleted entity captured would be helpful (for restoring entity in case of accidental deletion). @kevinquinnyo were you able to create a PR for this?

bmudda avatar Sep 11 '18 19:09 bmudda

@bmudda @GeekWiinik @lorenzo I finally found a half hour today to try adding this. https://github.com/lorenzo/audit-stash/pull/35

The problem is making sure not to break backwards compatibility with the previous AuditDeleteEvent signature, and I don't think it's quite right. I can probably add some tests soon.

kevinquinnyo avatar Oct 01 '18 22:10 kevinquinnyo

Seems like PR was merged.

dereuromark avatar Jan 10 '24 10:01 dereuromark