effective_logging 4.4.2 → 4.4.3
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 +4 -4
- data/app/datatables/effective_logs_datatable.rb +7 -1
- data/app/models/effective_logger.rb +9 -7
- data/config/effective_logging.rb +14 -0
- data/lib/effective_logging/active_storage_logger.rb +28 -8
- data/lib/effective_logging/engine.rb +15 -2
- data/lib/effective_logging/log_page_views.rb +3 -2
- data/lib/effective_logging/version.rb +1 -1
- data/lib/effective_logging.rb +15 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f638d885c609b3d6692821281b2a53da5ec21a4a99d71f7ec4295967b77c8dd
|
4
|
+
data.tar.gz: ab44aff2629b633235b9ce5468d9543c95ca6a79fb48fba14876f1fd09d5358e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5df219f0750704939d8aa6dec5c732c0df6a7e9120739fa2ffd5222a74d4012c63305309a761979942d5aa61a9fb46b2fda325dc9817203027e8caa9011866b0
|
7
|
+
data.tar.gz: 3b0552d07840260c40613a321c590aa811cce6c37ca7e0be16e9ff3ec1eee9fe000c8047a55f08b0dd0f9291652aa33fcda0cdce6df2d08f4ec27537300b4f86
|
@@ -26,7 +26,13 @@ class EffectiveLogsDatatable < Effective::Datatable
|
|
26
26
|
|
27
27
|
col :associated_type, visible: false, sort: false
|
28
28
|
col :associated_id, visible: false, label: 'Associated Id', sort: false
|
29
|
-
col :associated_to_s, label: '
|
29
|
+
col :associated_to_s, label: 'Item'
|
30
|
+
|
31
|
+
col(:associated, visible: false).search do |collection, term, column, sql_column|
|
32
|
+
collection.where("associated_to_s ILIKE ?", "%#{term}%")
|
33
|
+
end.sort do |collection, direction, column, sql_column|
|
34
|
+
collection.order(associated_to_s: direction)
|
35
|
+
end
|
30
36
|
|
31
37
|
col :message, sort: false do |log|
|
32
38
|
(log.message || '').gsub("\n", '<br>')
|
@@ -17,22 +17,24 @@ class EffectiveLogger
|
|
17
17
|
end
|
18
18
|
|
19
19
|
if options[:request].present? && options[:request].respond_to?(:referrer)
|
20
|
-
request = options
|
20
|
+
request = options[:request]
|
21
21
|
|
22
22
|
options[:ip] ||= request.ip
|
23
23
|
options[:referrer] ||= request.referrer
|
24
24
|
options[:user_agent] ||= request.user_agent
|
25
25
|
end
|
26
26
|
|
27
|
+
details = options.except(:request, :user_id, :user_type, :user, :associated_id, :associated_type, :associated, :associated_to_s)
|
28
|
+
|
27
29
|
log = EffectiveLogging.Log.new(
|
28
30
|
message: message,
|
29
31
|
status: status,
|
30
|
-
user_id: options
|
31
|
-
user_type: options
|
32
|
-
user: options
|
33
|
-
associated: options
|
34
|
-
associated_to_s: options
|
35
|
-
details:
|
32
|
+
user_id: options[:user_id],
|
33
|
+
user_type: options[:user_type],
|
34
|
+
user: options[:user],
|
35
|
+
associated: options[:associated],
|
36
|
+
associated_to_s: options[:associated_to_s],
|
37
|
+
details: details
|
36
38
|
)
|
37
39
|
|
38
40
|
if log.associated.present?
|
data/config/effective_logging.rb
CHANGED
@@ -17,6 +17,20 @@ EffectiveLogging.setup do |config|
|
|
17
17
|
# Log all active storage downloads
|
18
18
|
config.active_storage_enabled = true
|
19
19
|
|
20
|
+
# Only log active storage downloads for these attachment record types
|
21
|
+
# config.active_storage_only = []
|
22
|
+
|
23
|
+
# Don't log active storage downloads for these attachment record types
|
24
|
+
# config.active_storage_except = [
|
25
|
+
# 'ActionText::RichText'
|
26
|
+
# 'Effective::BannerAd',
|
27
|
+
# 'Effective::CarouselItem',
|
28
|
+
# 'Effective::PageBanner',
|
29
|
+
# 'Effective::PageSection',
|
30
|
+
# 'Effective::Permalink',
|
31
|
+
# 'Effective::Post',
|
32
|
+
# ]
|
33
|
+
|
20
34
|
# Log all sent emails
|
21
35
|
config.email_enabled = true
|
22
36
|
|
@@ -3,29 +3,49 @@
|
|
3
3
|
module EffectiveLogging
|
4
4
|
module ActiveStorageLogger
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def track_active_storage_download
|
7
|
+
@blob || set_download_blob()
|
8
|
+
track_active_storage_blob(@blob)
|
9
|
+
end
|
8
10
|
|
9
|
-
|
11
|
+
def track_active_storage_redirect
|
12
|
+
@blob || set_blob()
|
13
|
+
track_active_storage_blob(@blob)
|
14
|
+
end
|
10
15
|
|
11
|
-
|
12
|
-
return unless key.present?
|
13
|
-
return if (key[:content_type] || '').starts_with?('image')
|
16
|
+
private
|
14
17
|
|
15
|
-
|
18
|
+
def track_active_storage_blob(blob)
|
19
|
+
return if EffectiveLogging.supressed?
|
16
20
|
return unless blob.present?
|
17
21
|
|
22
|
+
onlies = EffectiveLogging.active_storage_onlies
|
23
|
+
excepts = EffectiveLogging.active_storage_excepts
|
24
|
+
|
18
25
|
blob.attachments.each do |attachment|
|
19
26
|
next if attachment.name == 'embeds'
|
20
|
-
next if attachment.record_type
|
27
|
+
next if attachment.record_type.blank?
|
28
|
+
|
29
|
+
# Process except and only
|
30
|
+
next if excepts.present? && excepts.any? { |type| attachment.record_type.start_with?(type) || attachment.record_type.end_with?(type) }
|
31
|
+
next if onlies.present? && !onlies.any? { |type| attachment.record_type.start_with?(type) || attachment.record_type.end_with?(type) }
|
21
32
|
|
22
33
|
associated = attachment.record
|
23
34
|
filename = blob.filename.to_s
|
24
35
|
message = [associated.to_s, filename.to_s].uniq.join(' ')
|
36
|
+
user = current_user
|
25
37
|
|
26
38
|
EffectiveLogger.download(message, associated: associated, associated_to_s: filename, filename: filename, user: user)
|
27
39
|
end
|
28
40
|
end
|
29
41
|
|
42
|
+
def set_download_blob
|
43
|
+
@blob ||= ActiveStorage::Blob.where(key: decode_verified_key().try(:dig, :key)).first
|
44
|
+
end
|
45
|
+
|
46
|
+
def current_user
|
47
|
+
(defined?(Tenant) ? send("current_#{Tenant.current}_user") : super)
|
48
|
+
end
|
49
|
+
|
30
50
|
end
|
31
51
|
end
|
@@ -38,8 +38,21 @@ module EffectiveLogging
|
|
38
38
|
initializer 'effective_logging.active_storage' do |app|
|
39
39
|
if EffectiveLogging.active_storage_enabled == true && defined?(ActiveStorage)
|
40
40
|
app.config.to_prepare do
|
41
|
-
ActiveStorage::
|
42
|
-
|
41
|
+
ActiveStorage::BaseController.class_eval do
|
42
|
+
include ActiveStorageLogger
|
43
|
+
end
|
44
|
+
|
45
|
+
ActiveStorage::DiskController.class_eval do
|
46
|
+
after_action :track_active_storage_download, only: [:show]
|
47
|
+
end
|
48
|
+
|
49
|
+
ActiveStorage::Blobs::RedirectController.class_eval do
|
50
|
+
after_action :track_active_storage_redirect, only: [:show]
|
51
|
+
end
|
52
|
+
|
53
|
+
ActiveStorage::Representations::RedirectController.class_eval do
|
54
|
+
after_action :track_active_storage_redirect, only: [:show]
|
55
|
+
end
|
43
56
|
end
|
44
57
|
end
|
45
58
|
end
|
@@ -42,14 +42,15 @@ module EffectiveLogging
|
|
42
42
|
user = EffectiveLogging.current_user || (current_user if respond_to?(:current_user))
|
43
43
|
|
44
44
|
if self.class.log_page_views_opts[:details] == false
|
45
|
-
::EffectiveLogger.view("#{request.request_method} #{request.path}", user: user)
|
45
|
+
::EffectiveLogger.view("#{request.request_method} #{request.path}", user: user, associated: try(:resource))
|
46
46
|
else
|
47
47
|
::EffectiveLogger.view(
|
48
48
|
"#{request.request_method} #{request.path}",
|
49
49
|
user: user,
|
50
50
|
format: (request.format.to_s == 'text/html' ? nil : request.format.to_s),
|
51
51
|
params: request.filtered_parameters.reject { |k, v| (k == 'controller' || k == 'action') },
|
52
|
-
request: request
|
52
|
+
request: request,
|
53
|
+
associated: try(:resource)
|
53
54
|
)
|
54
55
|
end
|
55
56
|
end
|
data/lib/effective_logging.rb
CHANGED
@@ -7,7 +7,8 @@ module EffectiveLogging
|
|
7
7
|
[
|
8
8
|
:logs_table_name, :tracks_table_name, :layout, :additional_statuses,
|
9
9
|
:log_class_name,
|
10
|
-
:active_storage_enabled, :
|
10
|
+
:active_storage_enabled, :active_storage_only, :active_storage_except,
|
11
|
+
:email_enabled, :sign_in_enabled, :sign_out_enabled
|
11
12
|
]
|
12
13
|
end
|
13
14
|
|
@@ -66,4 +67,17 @@ module EffectiveLogging
|
|
66
67
|
Thread.current[:effective_logging_supressed] == true
|
67
68
|
end
|
68
69
|
|
70
|
+
# For ActiveStorageLogger
|
71
|
+
def self.active_storage_onlies
|
72
|
+
onlies = Array(active_storage_only) - [nil, '', ' ']
|
73
|
+
raise("effective_logging.active_storage_only should be an Array of Strings") if onlies.present? && !onlies.all? { |type| type.kind_of?(String) }
|
74
|
+
onlies
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.active_storage_excepts
|
78
|
+
excepts = Array(active_storage_except) - [nil, '', ' ']
|
79
|
+
raise("effective_logging.active_storage_except should be an Array of Strings") if excepts.present? && !excepts.all? { |type| type.kind_of?(String) }
|
80
|
+
excepts
|
81
|
+
end
|
82
|
+
|
69
83
|
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.4.
|
4
|
+
version: 4.4.3
|
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: 2025-
|
11
|
+
date: 2025-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|