collectiveidea / audited

Audited (formerly acts_as_audited) is an ORM extension that logs all changes to your Rails models.
MIT License
3.35k stars 646 forks source link

Auditing file changes - ActiveStorage #470

Open BassamAziz opened 5 years ago

BassamAziz commented 5 years ago

Is there a way to audit file changes (with active storage). so that old files will still be associated with old versions, and new versions will refer to the new files. thank you all.

dmitry commented 5 years ago

@BassamAziz absolutely possible, you have to read the ActiveStorage model code here: https://github.com/rails/rails/tree/master/activestorage/app/models/active_storage

Basically, it's something like:

ActiveStorage::Attachment.audited
garyfoster commented 4 years ago

This works, if I put that code in config/initializers - is that a correct way to approach it?

dmitry commented 4 years ago

@garyfoster yes, I guess this is the best practice doing that. Created something like audited.rb and put it into the initializers and add this code. I suggest to use shrine for the attachments, as it's more modular and don't have many issues like activestorage has.

garyfoster commented 4 years ago

This has been working great in an initializer: (and yes, active storage has been a joke)

Rails.configuration.to_prepare do ActiveStorage::Attachment.audited associated_with: :record end

mscdit commented 6 months ago

Hi @garyfoster ... also trying to keep track of changes to file attachments with audited gem. I am using

Rails.configuration.to_prepare do ActiveStorage::Attachment.audited associated_with: :record end Rails.configuration.to_prepare do ActiveStorage::Blob.audited end

in initializer. Current situation is that only creation of ActiveStorage::Attachment objects are getting audited (no destroy) ... ?

So in general what's the right/clean way to get associated audits for file attachments for a given model?

THX a lot! mscdit