effective_logging 4.1.2 → 4.2.0

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: 7e070e874fc63fecb6464d0c4648cc15e09e88fbcc7a30110654070dfcfadac9
4
- data.tar.gz: e0cca60b349ad639ecbc98eb7f51262baa266e23fa79c6c05250db55d38c1ea3
3
+ metadata.gz: bd43bfe19f220a08425b7f93f3160ef4d2fa4107e6eb8c7d00d7e92dff2ede90
4
+ data.tar.gz: 3d0a977bcff9579e325523aa03472b107d028f2076197e947913b6b4d64df4c7
5
5
  SHA512:
6
- metadata.gz: 94ed4840cca24c47b64024f652ec7e2374fee2d2b83c393b801e623b92472c903e93aa743f8573dbe7677c615d5e393a614080602c5900738b587eb9535c6654
7
- data.tar.gz: 063274f9e2bff0309335b557ca3777aa8612cc03ac8860a8b9a8dc15535ddaa89b43535a9f0687d3f53f534a92071c42ce72ca23861809381b4dca90e6e93003
6
+ metadata.gz: 004220be5d784fce7fb075b9eac6a6f344d4416bfe1c9d64af6edb895b6ed1802e62cca9b52364746a2eba6b9b7b3a4418d3508f912954048d520a0e8106a5a1
7
+ data.tar.gz: d02dee405d04dd01b1bb135ecf90b7241e2feae917c911ad5785e8474eb04b5821a02e2478924c64a8b8458984c3691129bbd0265a326fef1f16350487f06ee7
data/README.md CHANGED
@@ -318,8 +318,7 @@ We can also use a similar method to create a datatable of logs for just one user
318
318
  When initialized with :for, the logs are scoped to any log where this id matches the User or Associated column.
319
319
 
320
320
  ```ruby
321
- EffectiveLogsDatatable.new(for: @user.id)
322
- EffectiveLogsDatatable.new(for: [1, 2, 3]) # Users with ID 1, 2 and 3
321
+ EffectiveLogsDatatable.new(for: @user)
323
322
  ```
324
323
 
325
324
  ### Upgrade from 2.0
@@ -43,7 +43,7 @@ module Effective
43
43
  # This is the User index event
44
44
  def index
45
45
  EffectiveResources.authorize!(self, :index, resource_scope.new(user: current_user, user_id: current_user.id))
46
- @datatable = EffectiveLogsDatatable.new(self, for: current_user.id)
46
+ @datatable = EffectiveLogsDatatable.new(self, for: current_user)
47
47
  end
48
48
 
49
49
  def html_part
@@ -44,24 +44,19 @@ class EffectiveLogsDatatable < Effective::Datatable
44
44
  collection do
45
45
  scope = EffectiveLogging.Log.deep.all
46
46
 
47
- # Older syntax, pass by integer
48
- if attributes[:for]
49
- user_ids = Array(attributes[:for])
50
- scope = scope.where('user_id IN (?) OR (associated_id IN (?) AND associated_type = ?)', user_ids, user_ids, 'User')
51
- end
52
-
53
47
  # Newer syntax, pass by object
54
48
  if attributes[:for_id] && attributes[:for_type]
55
49
  scope = scope.where(associated_id: attributes[:for_id], associated_type: attributes[:for_type])
56
50
  .or(scope.where(changes_to_id: attributes[:for_id], changes_to_type: attributes[:for_type]))
57
51
  .or(scope.where(user_id: attributes[:for_id], user_type: attributes[:for_type]))
52
+ elsif attributes[:for] # Older syntax, pass by integer
53
+ user_ids = Array(attributes[:for])
54
+ scope = scope.where('user_id IN (?) OR (associated_id IN (?) AND associated_type = ?)', user_ids, user_ids, 'User')
58
55
  end
59
56
 
60
57
  if attributes[:associated_id] && attributes[:associated_type]
61
58
  scope = scope.where(associated_id: attributes[:associated_id], associated_type: attributes[:associated_type])
62
- end
63
-
64
- if attributes[:associated]
59
+ elsif attributes[:associated]
65
60
  scope = scope.where(associated: attributes[:associated])
66
61
  end
67
62
 
@@ -20,7 +20,7 @@ module ActsAsLoggable
20
20
  end
21
21
 
22
22
  included do
23
- has_many :logged_changes, -> { EffectiveLogging.Log.order(:id).where(status: EffectiveLogging.log_changes_status) }, as: :changes_to
23
+ has_many :logged_changes, -> { where(status: EffectiveLogging.log_changes_status).order(:id) }, as: :changes_to, class_name: 'Effective::Log'
24
24
 
25
25
  log_changes_options = {
26
26
  to: @acts_as_loggable_options[:to],
@@ -35,15 +35,15 @@ module ActsAsLoggable
35
35
 
36
36
  self.send(:define_method, :log_changes_options) { log_changes_options }
37
37
 
38
- after_create(unless: -> { EffectiveLogging.supressed? }) do
38
+ after_create(if: -> { log_changes? }, unless: -> { EffectiveLogging.supressed? }) do
39
39
  ::EffectiveLogging::ActiveRecordLogger.new(self, log_changes_options).created!
40
40
  end
41
41
 
42
- after_destroy(unless: -> { EffectiveLogging.supressed? }) do
42
+ after_destroy(if: -> { log_changes? }, unless: -> { EffectiveLogging.supressed? }) do
43
43
  ::EffectiveLogging::ActiveRecordLogger.new(self, log_changes_options).destroyed!
44
44
  end
45
45
 
46
- after_update(unless: -> { EffectiveLogging.supressed? }) do
46
+ after_update(if: -> { log_changes? }, unless: -> { EffectiveLogging.supressed? }) do
47
47
  ::EffectiveLogging::ActiveRecordLogger.new(self, log_changes_options).updated!
48
48
  end
49
49
  end
@@ -54,6 +54,11 @@ module ActsAsLoggable
54
54
 
55
55
  # Regular instance methods
56
56
 
57
+ # Disable logging of changes for this resource
58
+ def log_changes?
59
+ true # Can be overridden to suppress logging
60
+ end
61
+
57
62
  # Format the title of this attribute. Return nil to use the default attribute.titleize
58
63
  def log_changes_formatted_attribute(attribute)
59
64
  'Roles' if attribute == :roles_mask && defined?(EffectiveRoles) && respond_to?(:roles)
@@ -1,3 +1,3 @@
1
1
  module EffectiveLogging
2
- VERSION = '4.1.2'.freeze
2
+ VERSION = '4.2.0'.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: 4.1.2
4
+ version: 4.2.0
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: 2023-12-01 00:00:00.000000000 Z
11
+ date: 2024-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails