effective_logging 3.0.12 → 3.0.13

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: 2898e7d8542c2b5c528242611aa2e80becf21097da0e71506e4ca205c0169933
4
- data.tar.gz: edad3789ae84819c00bd87b507314f1dc7abe79d75809249b48ad53f28799ffa
3
+ metadata.gz: 1fc5a45c2f4f2b72d25f2440ab60382a4e86455ac95176a4b8c927009aa1712b
4
+ data.tar.gz: 75fb045296a8e2887ada0a2e637c3f0005b4ba7efaca433c2c7f49d29f0505b9
5
5
  SHA512:
6
- metadata.gz: 01e10ee66306428c3185065f036d33b54b76520e448510048a35a39e29ba6180bf256065183f472df5471f3df8b4e671f33f72c0dc2eab591b38be19c7a2eded
7
- data.tar.gz: 5a1d5c5833d61581879e0204197dfacd511ae8d27042234372d0b41350beed0e52daf959952d7df8d16732738695ee73a0f3dbfdfa3381cb6769ce5f8981534d
6
+ metadata.gz: c17d99ed81e95846c101e19384c6be111147fec944ec6fe95ed2913cbec52344e4ac0ba6132e3dcdb66cf811b9d0336ca6af3fb80ac1253b53e0b1296b442b59
7
+ data.tar.gz: 971f6803ddf2e57e2b66068a33bd7ce6bdac5b8cfa735290656df37f2a569234d2dd5b86b9710c846cca37b49abdb0db16b15c1f99f9ae817289f37c94b4ce7a
@@ -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
@@ -1,4 +1,5 @@
1
1
  require 'effective_logging/active_record_logger'
2
+ require 'effective_logging/active_storage_logger'
2
3
  require 'effective_logging/email_logger'
3
4
  require 'effective_logging/log_page_views'
4
5
  require 'effective_logging/set_current_user'
@@ -27,6 +28,16 @@ module EffectiveLogging
27
28
  end
28
29
  end
29
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
+
30
41
  # Register the log_page_views concern so that it can be called in ActionController or elsewhere
31
42
  initializer 'effective_logging.log_changes_action_controller' do |app|
32
43
  Rails.application.config.to_prepare do
@@ -1,3 +1,3 @@
1
1
  module EffectiveLogging
2
- VERSION = '3.0.12'.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.12
4
+ version: 3.0.13
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: 2021-01-19 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