effective_logging 3.0.8 → 3.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e927867ada599e7421b8ff9d05e502647dcc2efb7512a5315ca47275e3edf0c
4
- data.tar.gz: 002fb78421be669cc009c6fc237353a56ae5013944a1b3b44702ca3acb77cec7
3
+ metadata.gz: 1fc5a45c2f4f2b72d25f2440ab60382a4e86455ac95176a4b8c927009aa1712b
4
+ data.tar.gz: 75fb045296a8e2887ada0a2e637c3f0005b4ba7efaca433c2c7f49d29f0505b9
5
5
  SHA512:
6
- metadata.gz: 268d59bf22f25ff827e5fd5112283e4c21f566fb6e011283bb88942043dccfd84b8c62f5168d4987ce4069e7c63b2a55fcaa4b88b7ad58cd25464e4197c43ea3
7
- data.tar.gz: 9aab2bcae402baca16d24ec20088921aee6c0121e0b080dd27d74727d894e7ddaeb6d6526d54a95627ee58219db78e0b5d748e30449785bd705b1ed8f1f89ba5
6
+ metadata.gz: c17d99ed81e95846c101e19384c6be111147fec944ec6fe95ed2913cbec52344e4ac0ba6132e3dcdb66cf811b9d0336ca6af3fb80ac1253b53e0b1296b442b59
7
+ data.tar.gz: 971f6803ddf2e57e2b66068a33bd7ce6bdac5b8cfa735290656df37f2a569234d2dd5b86b9710c846cca37b49abdb0db16b15c1f99f9ae817289f37c94b4ce7a
data/README.md CHANGED
@@ -197,19 +197,17 @@ This logging includes the resource's base attributes, all autosaved associations
197
197
 
198
198
  It will recurse through all accepts_nested_attributes has_many's and handle any number of child objects.
199
199
 
200
- Add to your model:
200
+ Add to your application controller:
201
201
 
202
- ```ruby
203
- class Post < ActiveRecord::Base
204
- log_changes
205
- end
202
+ ```
203
+ around_action :set_effective_logging_current_user
206
204
  ```
207
205
 
208
- and to your controller:
206
+ Add to your model:
209
207
 
210
208
  ```ruby
211
- class ApplicationController < ActionController::Base
212
- before_action :set_effective_logging_current_user
209
+ class Post < ActiveRecord::Base
210
+ log_changes
213
211
  end
214
212
  ```
215
213
 
@@ -371,4 +369,3 @@ MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
371
369
  4. Push to the branch (`git push origin my-new-feature`)
372
370
  5. Bonus points for test coverage
373
371
  6. Create new Pull Request
374
-
@@ -40,7 +40,7 @@
40
40
  - next unless value.present?
41
41
  .row
42
42
  .col-md-12
43
- %p
43
+ .mt-3
44
44
  %strong= "#{key.to_s.titleize}:"
45
45
  = format_log_details_value(log, key)
46
46
 
@@ -50,4 +50,3 @@
50
50
 
51
51
  - unless log.datatable.nil?
52
52
  = render_datatable(log.datatable)
53
-
@@ -40,6 +40,9 @@ EffectiveLogging.setup do |config|
40
40
  #### Automatic Logging Functionality ####
41
41
  #########################################
42
42
 
43
+ # Log all active storage downloads
44
+ config.active_storage_enabled = true
45
+
43
46
  # Log all sent emails
44
47
  config.email_enabled = true
45
48
 
@@ -11,6 +11,7 @@ module EffectiveLogging
11
11
  mattr_accessor :layout
12
12
  mattr_accessor :additional_statuses
13
13
 
14
+ mattr_accessor :active_storage_enabled
14
15
  mattr_accessor :email_enabled
15
16
  mattr_accessor :sign_in_enabled
16
17
  mattr_accessor :sign_out_enabled
@@ -48,8 +49,21 @@ module EffectiveLogging
48
49
 
49
50
  def self.statuses
50
51
  @statuses ||= (
51
- Array(@@additional_statuses).map { |status| status.to_s.downcase } | # union
52
- ['info', 'success', 'error', 'view', log_changes_status, ('email' if email_enabled), ('sign_in' if sign_in_enabled), ('sign_out' if sign_out_enabled)].compact
52
+ base = [
53
+ 'info',
54
+ 'success',
55
+ 'error',
56
+ 'view',
57
+ log_changes_status, # 'change'
58
+ ('download' if active_storage_enabled),
59
+ ('email' if email_enabled),
60
+ ('sign_in' if sign_in_enabled),
61
+ ('sign_out' if sign_out_enabled)
62
+ ].compact
63
+
64
+ additional = Array(@@additional_statuses).map { |status| status.to_s.downcase }
65
+
66
+ base | additional # union
53
67
  )
54
68
  end
55
69
 
@@ -0,0 +1,23 @@
1
+ module EffectiveLogging
2
+ module ActiveStorageLogger
3
+
4
+ def track_downloads
5
+ user = current_user if respond_to?(:current_user)
6
+
7
+ key = decode_verified_key()
8
+ return unless key.present?
9
+
10
+ blob = ActiveStorage::Blob.where(key: key[:key]).first
11
+ return unless blob.present?
12
+
13
+ blob.attachments.each do |attachment|
14
+ associated = attachment.record
15
+ filename = blob.filename.to_s
16
+ message = [associated.to_s, filename.to_s].uniq.join(' ')
17
+
18
+ EffectiveLogger.download(message, associated: associated, filename: filename, user: user)
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -5,7 +5,7 @@ module EffectiveLogging
5
5
  return unless message.present?
6
6
 
7
7
  # collect a Hash of arguments used to invoke EffectiveLogger.success
8
- logged_fields = { from: message.from.join(','), to: message.to, subject: message.subject }
8
+ logged_fields = { from: message.from.join(','), to: message.to, subject: message.subject, cc: message.cc, bcc: message.bcc }
9
9
 
10
10
  # Add a log header to your mailer to pass some objects or additional things to EffectiveLogger
11
11
  # mail(to: 'admin@example.com', subject: @post.title, log: { post: @post })
@@ -18,10 +18,11 @@ module EffectiveLogging
18
18
  end
19
19
 
20
20
  body = (message.body.try(:parts) || []).find { |part| part.content_type.to_s.downcase.include?('text/html') }
21
+ to = Array(message.to) - [nil, '']
21
22
 
22
23
  logged_fields[:email] = "#{message.header}<hr>#{(body.presence || message.body)}"
23
24
 
24
- (message.to || []).each do |to|
25
+ to.each do |to|
25
26
  user = (User.where(email: to).first rescue nil)
26
27
 
27
28
  logged_fields[:to] = to
@@ -30,6 +31,11 @@ module EffectiveLogging
30
31
 
31
32
  ::EffectiveLogger.email("#{message.subject} - #{message.to.join(', ')}", logged_fields)
32
33
  end
34
+
35
+ if to.blank? && (message.cc.present? || message.bcc.present?)
36
+ ::EffectiveLogger.email("#{message.subject} - multiple recipients", logged_fields)
37
+ end
38
+
33
39
  end
34
40
 
35
41
  end
@@ -1,11 +1,14 @@
1
1
  require 'effective_logging/active_record_logger'
2
+ require 'effective_logging/active_storage_logger'
3
+ require 'effective_logging/email_logger'
4
+ require 'effective_logging/log_page_views'
5
+ require 'effective_logging/set_current_user'
6
+ require 'effective_logging/user_logger'
2
7
 
3
8
  module EffectiveLogging
4
9
  class Engine < ::Rails::Engine
5
10
  engine_name 'effective_logging'
6
11
 
7
- config.autoload_paths += Dir["#{config.root}/lib/"]
8
-
9
12
  # Set up our default configuration options.
10
13
  initializer "effective_logging.defaults", :before => :load_config_initializers do |app|
11
14
  eval File.read("#{config.root}/config/effective_logging.rb")
@@ -14,7 +17,6 @@ module EffectiveLogging
14
17
  # Automatically Log Emails
15
18
  initializer 'effective_logging.emails' do |app|
16
19
  if EffectiveLogging.email_enabled == true
17
- require 'effective_logging/email_logger'
18
20
  ActionMailer::Base.register_interceptor(EffectiveLogging::EmailLogger)
19
21
  end
20
22
  end
@@ -26,11 +28,20 @@ module EffectiveLogging
26
28
  end
27
29
  end
28
30
 
31
+ # Log all ActiveStorage downloads
32
+ initializer 'effective_logging.active_storage' do |app|
33
+ if EffectiveLogging.active_storage_enabled == true && defined?(ActiveStorage)
34
+ Rails.application.config.to_prepare do
35
+ ActiveStorage::DiskController.include(EffectiveLogging::ActiveStorageLogger)
36
+ ActiveStorage::DiskController.class_eval { after_action(:track_downloads, only: :show) }
37
+ end
38
+ end
39
+ end
40
+
29
41
  # Register the log_page_views concern so that it can be called in ActionController or elsewhere
30
42
  initializer 'effective_logging.log_changes_action_controller' do |app|
31
43
  Rails.application.config.to_prepare do
32
44
  ActiveSupport.on_load :action_controller do
33
- require 'effective_logging/set_current_user'
34
45
  ActionController::Base.include(EffectiveLogging::SetCurrentUser::ActionController)
35
46
  end
36
47
  end
@@ -3,13 +3,17 @@ module EffectiveLogging
3
3
  module ActionController
4
4
 
5
5
  # Add me to your ApplicationController
6
- # before_action :set_effective_logging_current_user
6
+ # around_action :set_effective_logging_current_user
7
7
 
8
8
  def set_effective_logging_current_user
9
9
  EffectiveLogging.current_user = current_user
10
+
11
+ if block_given?
12
+ yield
13
+ EffectiveLogging.current_user = nil
14
+ end
10
15
  end
11
16
 
12
17
  end
13
18
  end
14
19
  end
15
-
@@ -1,3 +1,3 @@
1
1
  module EffectiveLogging
2
- VERSION = '3.0.8'.freeze
2
+ VERSION = '3.0.13'.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.0.8
4
+ version: 3.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-12 00:00:00.000000000 Z
11
+ date: 2021-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -112,6 +112,7 @@ files:
112
112
  - db/migrate/01_create_effective_logging.rb.erb
113
113
  - lib/effective_logging.rb
114
114
  - lib/effective_logging/active_record_logger.rb
115
+ - lib/effective_logging/active_storage_logger.rb
115
116
  - lib/effective_logging/email_logger.rb
116
117
  - lib/effective_logging/engine.rb
117
118
  - lib/effective_logging/log_page_views.rb
@@ -123,7 +124,7 @@ homepage: https://github.com/code-and-effect/effective_logging
123
124
  licenses:
124
125
  - MIT
125
126
  metadata: {}
126
- post_install_message:
127
+ post_install_message:
127
128
  rdoc_options: []
128
129
  require_paths:
129
130
  - lib
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  version: '0'
140
141
  requirements: []
141
142
  rubygems_version: 3.1.2
142
- signing_key:
143
+ signing_key:
143
144
  specification_version: 4
144
145
  summary: Automatically log all sent emails, user logins, and page views. This also
145
146
  will log custom events from Ruby and JavaScript.