models_auditor 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/controllers/models_auditor/audit_controller.rb +24 -4
- data/lib/models_auditor/audit.rb +1 -1
- data/lib/models_auditor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5052949bdc7e490427a00314160a258c9723482
|
4
|
+
data.tar.gz: b8e74cd2f69767f64068ca54fbab58cf9d1f04d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dfacc7dba0be169d3c815af3ffae7cb7cf4a52239ad73653098b29831f6a6f7ba55a63eeec2e6e7e8c7dbfd82b6e3724b07a598a5ef98a8afe34a8e27468010
|
7
|
+
data.tar.gz: 8403c277ebd5d53911f70d37c2113df4b07fd364da7d14bfe6d8e72e4afab72f4dde78eb278480de1ceab63cfa95642004cd93fed32e3e0e16879eb6190491fc
|
data/README.md
CHANGED
@@ -76,11 +76,11 @@
|
|
76
76
|
|
77
77
|
3. Add to each association models
|
78
78
|
|
79
|
-
`enable_audit ModelsAuditor::Audit::AUDIT_MODE_JSON, bridge: {Author.name
|
79
|
+
`enable_audit ModelsAuditor::Audit::AUDIT_MODE_JSON, bridge: {author_id: Author.name, post_id: Post.name}`
|
80
80
|
|
81
81
|
```ruby
|
82
82
|
class AuthorsPost < ActiveRecord::Base
|
83
|
-
enable_audit ModelsAuditor::Audit::AUDIT_MODE_JSON, bridge: {Author.name
|
83
|
+
enable_audit ModelsAuditor::Audit::AUDIT_MODE_JSON, bridge: {author_id: Author.name, post_id: Post.name}
|
84
84
|
end
|
85
85
|
```
|
86
86
|
|
@@ -76,14 +76,34 @@ module ModelsAuditor
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def get_relations(record, records)
|
79
|
-
rel_records = records.select
|
79
|
+
rel_records = records.select do |r|
|
80
|
+
!r.bridge.nil? && r.bridge.any? do |_, v|
|
81
|
+
v_type, v_id = v.to_a[0]
|
82
|
+
v_type.to_s == record.object_type && v_id.to_i == record.object_id.to_i
|
83
|
+
end
|
84
|
+
end
|
80
85
|
rel_records.map do |i|
|
81
|
-
|
82
|
-
next
|
83
|
-
|
86
|
+
target_info = except_target_class(i.bridge, record.object_type, record.object_id)
|
87
|
+
next if target_info.empty?
|
88
|
+
t_key, klass_with_id = target_info.to_a[0]
|
89
|
+
target_klass, target_id = klass_with_id.to_a[0]
|
90
|
+
i.attributes.slice('id', 'object_type', 'object_id').merge(target: {
|
91
|
+
class: target_klass,
|
92
|
+
foreign_key: t_key,
|
93
|
+
foreign_id: target_id,
|
94
|
+
})
|
84
95
|
end.compact
|
85
96
|
end
|
86
97
|
|
98
|
+
# @return [Array]
|
99
|
+
def except_target_class(bridge, target_class, target_id)
|
100
|
+
target_id = target_id.to_i
|
101
|
+
bridge.select do |_, v|
|
102
|
+
klass, id = v.to_a[0]
|
103
|
+
!(klass.to_s == target_class.to_s && id.to_i == target_id.to_i)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
87
107
|
# @param [ActiveRecord::Relation|ModelsAuditor::AuditRequest|Array] data
|
88
108
|
def structure_requests_data(data)
|
89
109
|
requests =
|
data/lib/models_auditor/audit.rb
CHANGED
@@ -50,7 +50,7 @@ module ModelsAuditor
|
|
50
50
|
|
51
51
|
bridge =
|
52
52
|
if options[:bridge]
|
53
|
-
options[:bridge].each_with_object({}) { |(
|
53
|
+
options[:bridge].each_with_object({}) { |(key, model_name), o| o[key] = {model_name => __send__(key)} }
|
54
54
|
end
|
55
55
|
|
56
56
|
Thread.new do
|