kunklejr / auditor Goto Github PK
View Code? Open in Web Editor NEWRails 3 auditing of your ActiveRecord model changes
License: MIT License
Rails 3 auditing of your ActiveRecord model changes
License: MIT License
I was checking out auditor and noticed one of the specs is currently failing.
Here's a backtrace: https://gist.github.com/6009d955f7a4c6372ef6
Consider the following relationships
worksheet has_one balance_sheet
balance_sheet has_many line_items
line_item has_many line_item_details
In my case, owner is the worksheet. So for each audit record, I need to identify a worksheet as the owner. A worksheet has a balance_sheet. For the balance_sheet I can audit "on" worksheet and this works fine. But a balance_sheet can have multiple line_items and I'm auditing line_item changes (as well as line_item_details). I need line_item audits to have an owner of worksheet, not balance_sheet. I don't have a direct relationship from line_item to worksheet. So I get the "parent" of line_item which is the balance_sheet. Then balance_sheet gets its parent, worksheet. This is the last model, so it is the owner.
This code would be on line_item_detail
audit!(:create, :update, :destroy, :on => [:line_item, :balance_sheet, :worksheet])
This code would be on line_item
audit!(:create, :update, :destroy, :on => [:balance_sheet, :worksheet])
This code would be on balance_sheet
audit!(:create, :update, :destroy, :on => :worksheet)
Add the ability to audit as a specified user for a given block of code. For example:
Audit.as_user(user) do
# Perform changes on audited models
end
To address some performance issues we saw when the AUDITS table grew to around 300K rows we had to add a new composite index to speed up the query for the max version based on the auditable_id and auditable_type.
add_index "audits", ["auditable_id", "auditable_type", "version"], :name => "auditable_index"
I'm not sure if this is by design, but currently when I have audit(:destroy) on a model, it adds the record to the Audit table however the audited_changes field is nil. Would it be possible make it behave similar to :create? So it would have "name=>['Company Name', nil]" in the audited_changes field, similar to how it has "name=>[nil, 'Company Name']" for :create.
Thanks,
Michael
Hello,
Is there an easy way to set the primary object of Auditor as something other than User? My app uses an object called Account, rather than User, and so current_user is current_account, user_id is account_id, etc.
Thanks for the gem!
George
Add a required polymorphic owner field to all audit records. This provides the ability to associate an audit record with a different model. This is useful for models that belong_to another model, providing a way to group all audit records associated with a parent.
I am not sure if this is intended behavior. What I found is that "ORDER BY version, created_at" is always appended to database query generated by ActiveRecord. For example, if I do Audit.scoped.limit(20) in "rails c" window, without specifying any ordering criteria, the following SQL command is issued.
irb(main):001:0> Audit.scoped.limit(20)
Audit Load (1.2ms) SELECT "audits".* FROM "audits" ORDER BY version, created_at LIMIT 20
This is a bit surprising and caused some trouble. I would like to show audit records in absolute created_at order, ignoring "version".
I am using Rails 3.
I think a CHANGELOG.md
file would be useful as reference. :)
It doesn't make much sense to save a create or update audit record if it doesn't have any audited changes. This should be a noop instead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.