bencrouse / mongoid-audit_log Goto Github PK
View Code? Open in Web Editor NEWSimple audit logging for Mongoid.
License: MIT License
Simple audit logging for Mongoid.
License: MIT License
Ran into two issues around embedded relationships.
The first I'm not sure what the best solution is. If #save
is called on the embedded relationship, it doesn't fire the parent callbacks and the audit log entry is not saved. I "fixed" it by adding a module thats included in embedded relationships that I want to fire a log entry that just call up to the parents methods before and after update.
The second issue is with how changes are logged for embedded relationships when they do save. When tracking changes from an embedded relationship, they end up looking something like
{
"skus" => [
{ "inventory" => [10, 8] },
{ "inventory" => [10, 5] }
]
}
Theres no way of knowing which embedded document had what changes.
I patched the Mongoid::AuditLog::Changes.extract_from
method to look like this:
def self.extract_from(value)
if value.is_a?(Hash)
raise ArgumentError, 'does not support hashes'
elsif value.is_a?(Enumerable)
changes = value.map do |model|
change = Mongoid::AuditLog::Changes.new(model).all
change.present? ? { id: model.id.to_s, changes: change } : change
end
changes.reject(&:blank?)
else
Mongoid::AuditLog::Changes.new(value).all
end
end
where if its passed an Enumerable
, the change becomes a Hash
with two keys, id
and changes
. So the above would turn into something like:
{
"skus" => [
{
"id" => "12345",
"changes" => { "inventory" => [10, 8] }
},
{
"id" => "6789",
"changes" => { "inventory" => [10, 5] }
}
]
}
I don't think its a great solution, but is in the neighbor of what I think it needs. Thoughts?
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.