effective_logging 3.3.0 → 3.4.1

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
  SHA256:
3
- metadata.gz: ddf74b601f163ea150e25b7e529d1e8abf13664ea6d19389efb79a092e67e653
4
- data.tar.gz: 99916c1974d5f545b53df560f94969d58a58b0d20381a7623ee97b54c947218e
3
+ metadata.gz: 4453f03163296e4fc99e3b71b9726b5d6a94c111464aabf554789639bd09db42
4
+ data.tar.gz: 2dcb56c63e969fa619cedf4a3deb2da0a4204b080f426f077eececabdb0faf94
5
5
  SHA512:
6
- metadata.gz: 50589f9370ed4005cabfcaa8cc3377ec845b8800acd8f195434c3a288f123160c7e0636491b5f204d4e6b98d8f50dedc00500a5fba9bcd34be83ee6ccc46523a
7
- data.tar.gz: 900e0b21b045f223333e852ba09d66c4e798edf855dd747fe6f251138f341b5d8b03f7d2da37c83a040a9b1b1e3cca941342692a0d065d6fd38f88d5d0639a88
6
+ metadata.gz: 60c3450c050554ae8edf1dc069f6bfa44eb8b444f5fe561f4cc3111162b4e60c8b1eb4f50cf6e56c6f48770313b62580081bac0a6852afa4d48b112997b738b1
7
+ data.tar.gz: d54d72ea79a1b414444f465f837d0342466b6dba91f7bf6415b0c47c0eed601b14961e7d4d299c26e179a456881efa2d243077cb86ad12fddb93964c8a693215
@@ -2,7 +2,7 @@
2
2
 
3
3
  class EffectiveLogChangesDatatable < Effective::Datatable
4
4
  datatable do
5
- order :updated_at
5
+ order :id, :desc
6
6
 
7
7
  col :updated_at, label: 'Date'
8
8
  col :id, visible: false
@@ -14,12 +14,12 @@ class EffectiveLogChangesDatatable < Effective::Datatable
14
14
  col :associated_to_s, visible: false, label: 'Associated'
15
15
 
16
16
  col :message, sort: false do |log|
17
- (log.message || '').gsub!("\n", '<br>')
17
+ message = (log.message || '').gsub("\n", '<br>')
18
18
 
19
19
  if log.associated_id == attributes[:changes_to_id] && log.associated_type == attributes[:changes_to_type]
20
- log.message
20
+ message
21
21
  else
22
- "#{log.associated_type} #{log.associated_to_s} - #{log.message}"
22
+ "#{log.associated_type} #{log.associated_to_s} - #{message}"
23
23
  end
24
24
 
25
25
  end.search do |collection, term, column, sql_column|
@@ -1,6 +1,6 @@
1
1
  class EffectiveLogsDatatable < Effective::Datatable
2
2
  datatable do
3
- order :updated_at
3
+ order :id, :desc
4
4
 
5
5
  col :updated_at, label: 'Date'
6
6
  col :id, visible: false
@@ -15,6 +15,9 @@ class EffectiveLogsDatatable < Effective::Datatable
15
15
  col :status, search: { collection: EffectiveLogging.statuses }
16
16
  end
17
17
 
18
+ col :changes_to_type, visible: false
19
+ col :changes_to_id, visible: false
20
+
18
21
  col :associated_type, visible: false
19
22
  col :associated_id, visible: false, label: 'Associated Id'
20
23
  col :associated_to_s, label: 'Associated'
@@ -35,13 +38,21 @@ class EffectiveLogsDatatable < Effective::Datatable
35
38
  # A nil attributes[:log_id] means give me all the top level log entries
36
39
  # If we set a log_id then it's for sub logs
37
40
  collection do
38
- scope = Effective::Log.deep.where(parent_id: attributes[:log_id])
41
+ scope = Effective::Log.includes(:user).where(parent_id: attributes[:log_id])
39
42
 
43
+ # Older syntax, pass by integer
40
44
  if attributes[:for]
41
45
  user_ids = Array(attributes[:for])
42
46
  scope = scope.where('user_id IN (?) OR (associated_id IN (?) AND associated_type = ?)', user_ids, user_ids, 'User')
43
47
  end
44
48
 
49
+ # Newer syntax, pass by object
50
+ if attributes[:for_id] && attributes[:for_type]
51
+ scope = scope.where(associated_id: attributes[:for_id], associated_type: attributes[:for_type])
52
+ .or(scope.where(changes_to_id: attributes[:for_id], changes_to_type: attributes[:for_type]))
53
+ .or(scope.where(user_id: attributes[:for_id], user_type: attributes[:for_type]))
54
+ end
55
+
45
56
  if attributes[:associated_id] && attributes[:associated_type]
46
57
  scope = scope.where(associated_id: attributes[:associated_id], associated_type: attributes[:associated_type])
47
58
  end
@@ -64,8 +64,12 @@ module ActsAsLoggable
64
64
  EffectiveRoles.roles_for(value) if attribute == :roles_mask && defined?(EffectiveRoles) && respond_to?(:roles)
65
65
  end
66
66
 
67
+ def logs_datatable
68
+ EffectiveLogsDatatable.new(for: self) if persisted?
69
+ end
70
+
67
71
  def log_changes_datatable
68
- EffectiveLogChangesDatatable.new(changes_to_id: id, changes_to_type: self.class.name) if persisted?
72
+ EffectiveLogChangesDatatable.new(changes_to: self) if persisted?
69
73
  end
70
74
 
71
75
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveLogging
2
- VERSION = '3.3.0'.freeze
2
+ VERSION = '3.4.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-06 00:00:00.000000000 Z
11
+ date: 2022-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails