models_auditor 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b97d84628732df40bbcf5f795dab1cb0def7099c
4
- data.tar.gz: 0588d971945a2c86b6abb775d3a88db96eb31db8
3
+ metadata.gz: 798b2ce9bbeff3dcf829c00e38160fe960e4a859
4
+ data.tar.gz: 413c51cb3cd244947eaaa018a2888b8a0ec11b78
5
5
  SHA512:
6
- metadata.gz: 305e685e80a2671aed2d00038287cc7acb3808f389cd5ea858192ff64dc1e8913d11fb90a1959b72b48501a0d580bda57210430c14e7bc1af36f5bb7162dfe89
7
- data.tar.gz: d8fc089476d78eee2cff0adcd8a77f06813ef597f32913146229c7a334944a1f5d341e452b0157048564eeaed9d770ee73a1024f0959d3b4898d4ff2ddae22c3
6
+ metadata.gz: dc1360fbfa0a78fca9217e99610a56e121e6efcea0e617356e4ed01148586d6c29a30612bd225917efc8c7a2da846ce4b0d4827d115ecc525d8850db2e1fe8e4
7
+ data.tar.gz: f872f90f9657606ee1be07db44673172e05af11b11c90a75c4af2a802816cdf84e336df39870d4242748448a062f8f95958a8d1a37cc9db34d60df31b6164eb3
@@ -12,7 +12,7 @@ module ModelsAuditor
12
12
 
13
13
  @collection =
14
14
  ModelsAuditor::AuditRequest.includes(:records).all
15
- .order(created_at: :desc)
15
+ .order("#{ModelsAuditor::AuditRequest.table_name}.created_at DESC")
16
16
  .paginate(paginate_info)
17
17
 
18
18
  @collection = apply_filters(@collection, params[:filters])
@@ -40,21 +40,23 @@ module ModelsAuditor
40
40
 
41
41
  def apply_filters(collection, filters)
42
42
  return collection if filters.blank? || collection.nil?
43
+ original = collection
43
44
  if filters[:since_at].present? && (time = (Time.parse(filters[:since_at]) rescue nil)).present?
44
45
  collection =
45
46
  collection
47
+ .includes(:records)
46
48
  .where(ModelsAuditor::AuditRecord.arel_table[:created_at].gteq(time))
47
49
  .references(ModelsAuditor::AuditRecord.table_name.to_sym)
48
50
  end
49
51
  if filters[:before_at].present? && (time = (Time.parse(filters[:before_at]) rescue nil)).present?
50
52
  collection =
51
53
  collection
54
+ .includes(:records)
52
55
  .where(ModelsAuditor::AuditRecord.arel_table[:created_at].lteq(time))
53
56
  .references(ModelsAuditor::AuditRecord.table_name.to_sym)
54
57
  end
55
58
  if filters[:action].present?
56
- collection = collection.where(ModelsAuditor::AuditRecord.arel_table[:action].eq(ModelsAuditor::AuditRecord.actions[filters[:action]])).references(ModelsAuditor::AuditRecord.table_name.to_sym)
57
-
59
+ collection = collection.includes(:records).where(ModelsAuditor::AuditRecord.arel_table[:action].eq(ModelsAuditor::AuditRecord.actions[filters[:action]])).references(ModelsAuditor::AuditRecord.table_name.to_sym)
58
60
  end
59
61
  if filters[:user_id].present?
60
62
  collection = collection.where(user_id: filters[:user_id])
@@ -68,11 +70,11 @@ module ModelsAuditor
68
70
  cond[:object_type] = object_type
69
71
  end
70
72
 
71
- filtered_requests = collection.where(ModelsAuditor::AuditRecord.table_name.to_sym => cond).pluck(:id)
72
- collection = collection.where(id: filtered_requests)
73
+ collection = collection.includes(:records).where(ModelsAuditor::AuditRecord.table_name.to_sym => cond)
73
74
  end
74
75
 
75
- collection
76
+ filtered_requests = collection.pluck(:id)
77
+ original.where(id: filtered_requests)
76
78
  end
77
79
 
78
80
  def get_relations(record, records)
@@ -1,3 +1,3 @@
1
1
  module ModelsAuditor
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: models_auditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Gorbunov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-07 00:00:00.000000000 Z
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails