effective_logging 3.5.3 → 4.0.0
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/MIT-LICENSE +1 -1
- data/README.md +2 -2
- data/app/controllers/admin/logs_controller.rb +3 -0
- data/app/controllers/effective/logs_controller.rb +6 -4
- data/app/datatables/admin/effective_logs_datatable.rb +2 -0
- data/app/datatables/effective_log_changes_datatable.rb +1 -1
- data/app/datatables/effective_logs_datatable.rb +1 -1
- data/app/models/concerns/acts_as_loggable.rb +1 -1
- data/app/models/concerns/effective_logging_log.rb +91 -0
- data/app/models/effective/log.rb +1 -62
- data/app/models/effective_logger.rb +1 -1
- data/config/effective_logging.rb +3 -0
- data/lib/effective_logging/active_record_logger.rb +1 -1
- data/lib/effective_logging/email_logger.rb +3 -7
- data/lib/effective_logging/engine.rb +1 -0
- data/lib/effective_logging/version.rb +1 -1
- data/lib/effective_logging.rb +5 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07b93fb924886c7eb67bebfa52af0ebba0955dcf70f882631b20b6c8d1ad4561
|
4
|
+
data.tar.gz: af822e66e051e26100da80e9edab36e0c3665922924fadae8d2d8a9f0a34eed4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39fca8a1eb4fe170a48c4e588d711cdee34cbd5999f05220a905e308e346ce80c2ece0bb840b480d67c11f43cd7f5215c009e32f1e13bf15c3526dab20a790f8
|
7
|
+
data.tar.gz: aff176f1e23569d3f91a6e3b9c59bf3d8636efb753ae32dee906937db304769230762f85df3ef986cfc6b461c3251233e2affe8c6cd5887fd249b7167a0656fc
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -254,7 +254,7 @@ First, require the javascript in your application.js:
|
|
254
254
|
and add the user permission:
|
255
255
|
|
256
256
|
```ruby
|
257
|
-
can :create,
|
257
|
+
can :create, EffectiveLogging.Log
|
258
258
|
```
|
259
259
|
|
260
260
|
then logging an event from JavaScript is almost the same one-liner as from ruby:
|
@@ -290,7 +290,7 @@ link_to 'Logs', effective_logging.admin_logs_path # /admin/logs
|
|
290
290
|
But you may need to add the permission (using CanCan):
|
291
291
|
|
292
292
|
```ruby
|
293
|
-
can :manage,
|
293
|
+
can :manage, EffectiveLoggging.Log
|
294
294
|
can :admin, :effective_logging
|
295
295
|
```
|
296
296
|
|
@@ -6,6 +6,9 @@ module Admin
|
|
6
6
|
include Effective::CrudController
|
7
7
|
skip_log_page_views
|
8
8
|
|
9
|
+
resource_scope -> { EffectiveLogging.Log.deep.all }
|
10
|
+
datatable -> { Admin::EffectiveLogsDatatable.new }
|
11
|
+
|
9
12
|
if (config = EffectiveLogging.layout)
|
10
13
|
layout(config.kind_of?(Hash) ? config[:admin] : config)
|
11
14
|
end
|
@@ -5,15 +5,17 @@ module Effective
|
|
5
5
|
include Effective::CrudController
|
6
6
|
skip_log_page_views
|
7
7
|
|
8
|
+
resource_scope -> { EffectiveLogging.Log.all }
|
9
|
+
|
8
10
|
if (config = EffectiveLogging.layout)
|
9
11
|
layout(config.kind_of?(Hash) ? config[:application] : config)
|
10
12
|
end
|
11
13
|
|
12
14
|
# This is a post from our Javascript
|
13
15
|
def create
|
14
|
-
EffectiveResources.authorize!(self, :create,
|
16
|
+
EffectiveResources.authorize!(self, :create, resource_scope.new)
|
15
17
|
|
16
|
-
@log =
|
18
|
+
@log = resource_scope.new.tap do |log|
|
17
19
|
log.message = log_params[:message]
|
18
20
|
log.status = EffectiveLogging.statuses.find { |status| status == log_params[:status] } || 'info'
|
19
21
|
log.user = EffectiveLogging.current_user || current_user
|
@@ -40,12 +42,12 @@ module Effective
|
|
40
42
|
|
41
43
|
# This is the User index event
|
42
44
|
def index
|
43
|
-
EffectiveResources.authorize!(self, :index,
|
45
|
+
EffectiveResources.authorize!(self, :index, resource_scope.new(user: current_user, user_id: current_user.id))
|
44
46
|
@datatable = EffectiveLogsDatatable.new(self, for: current_user.id)
|
45
47
|
end
|
46
48
|
|
47
49
|
def html_part
|
48
|
-
@log =
|
50
|
+
@log = resource_scope.find(params[:id])
|
49
51
|
|
50
52
|
EffectiveResources.authorize!(self, :show, @log)
|
51
53
|
|
@@ -37,7 +37,7 @@ class EffectiveLogChangesDatatable < Effective::Datatable
|
|
37
37
|
# A nil attributes[:log_id] means give me all the top level log entries
|
38
38
|
# If we set a log_id then it's for sub logs
|
39
39
|
collection do
|
40
|
-
|
40
|
+
EffectiveLogging.Log.logged_changes.deep
|
41
41
|
.where(changes_to_type: attributes[:changes_to_type], changes_to_id: attributes[:changes_to_id])
|
42
42
|
end
|
43
43
|
|
@@ -42,7 +42,7 @@ class EffectiveLogsDatatable < Effective::Datatable
|
|
42
42
|
# A nil attributes[:log_id] means give me all the top level log entries
|
43
43
|
# If we set a log_id then it's for sub logs
|
44
44
|
collection do
|
45
|
-
scope =
|
45
|
+
scope = EffectiveLogging.Log.deep.all
|
46
46
|
|
47
47
|
# Older syntax, pass by integer
|
48
48
|
if attributes[:for]
|
@@ -20,7 +20,7 @@ module ActsAsLoggable
|
|
20
20
|
end
|
21
21
|
|
22
22
|
included do
|
23
|
-
has_many :logged_changes, -> { order(:id).where(status: EffectiveLogging.log_changes_status) }, as: :changes_to
|
23
|
+
has_many :logged_changes, -> { EffectiveLogging.Log.order(:id).where(status: EffectiveLogging.log_changes_status) }, as: :changes_to
|
24
24
|
|
25
25
|
log_changes_options = {
|
26
26
|
to: @acts_as_loggable_options[:to],
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# EffectiveLoggingLog
|
4
|
+
#
|
5
|
+
# Mark your log model with effective_logging_log to get all the includes
|
6
|
+
|
7
|
+
module EffectiveLoggingLog
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
module Base
|
11
|
+
def effective_logging_log
|
12
|
+
include ::EffectiveLoggingLog
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def effective_logging_log?; true; end
|
18
|
+
end
|
19
|
+
|
20
|
+
included do
|
21
|
+
self.table_name = (EffectiveLogging.logs_table_name || :logs).to_s
|
22
|
+
|
23
|
+
belongs_to :user, polymorphic: true, optional: true
|
24
|
+
belongs_to :changes_to, polymorphic: true, optional: true # This is the log_changes to: option
|
25
|
+
belongs_to :associated, polymorphic: true, optional: true
|
26
|
+
|
27
|
+
effective_resource do
|
28
|
+
status :string
|
29
|
+
|
30
|
+
changes_to_type :string
|
31
|
+
changes_to_id :string
|
32
|
+
|
33
|
+
associated_type :string
|
34
|
+
associated_id :integer
|
35
|
+
associated_to_s :string
|
36
|
+
|
37
|
+
message :text
|
38
|
+
details :text
|
39
|
+
|
40
|
+
timestamps
|
41
|
+
end
|
42
|
+
|
43
|
+
serialize :details, Hash
|
44
|
+
|
45
|
+
validates :message, presence: true
|
46
|
+
validates :status, presence: true
|
47
|
+
|
48
|
+
validate(if: -> { status.present? }) do
|
49
|
+
errors.add(:status, "is not included") unless EffectiveLogging.statuses.include?(status)
|
50
|
+
end
|
51
|
+
|
52
|
+
scope :deep, -> { includes(:user, :associated, :changes_to) }
|
53
|
+
scope :sorted, -> { order(:id) }
|
54
|
+
scope :logged_changes, -> { where(status: EffectiveLogging.log_changes_status) }
|
55
|
+
scope :changes, -> { where(status: EffectiveLogging.log_changes_status) }
|
56
|
+
|
57
|
+
# Dynamically add logging methods based on the defined statuses
|
58
|
+
# EffectiveLogging.info 'my message'
|
59
|
+
(EffectiveLogging.statuses || []).each do |status|
|
60
|
+
send(:define_method, status) { |message, options={}| log(message, status, options) }
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
# Instance Methods
|
66
|
+
def to_s
|
67
|
+
"#{model_name.human} ##{id}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def associated_to_s=(value)
|
71
|
+
super(value.to_s[0...255].presence) # Take only first 255 characters
|
72
|
+
end
|
73
|
+
|
74
|
+
def log(message, status = nil, options = {})
|
75
|
+
status ||= EffectiveLogging.statuses.first
|
76
|
+
EffectiveLogger.log(message, status, options)
|
77
|
+
end
|
78
|
+
|
79
|
+
def details
|
80
|
+
self[:details] || {}
|
81
|
+
end
|
82
|
+
|
83
|
+
def next_log
|
84
|
+
self.class.order(id: :asc).where('id > ?', id).first
|
85
|
+
end
|
86
|
+
|
87
|
+
def prev_log
|
88
|
+
self.class.order(id: :desc).where('id < ?', id).first
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
data/app/models/effective/log.rb
CHANGED
@@ -1,68 +1,7 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Effective
|
4
2
|
class Log < ActiveRecord::Base
|
5
3
|
self.table_name = EffectiveLogging.logs_table_name.to_s
|
6
4
|
|
7
|
-
|
8
|
-
belongs_to :changes_to, polymorphic: true, optional: true # This is the log_changes to: option
|
9
|
-
belongs_to :associated, polymorphic: true, optional: true
|
10
|
-
|
11
|
-
effective_resource do
|
12
|
-
status :string
|
13
|
-
|
14
|
-
changes_to_type :string
|
15
|
-
changes_to_id :string
|
16
|
-
|
17
|
-
associated_type :string
|
18
|
-
associated_id :integer
|
19
|
-
associated_to_s :string
|
20
|
-
|
21
|
-
message :text
|
22
|
-
details :text
|
23
|
-
|
24
|
-
timestamps
|
25
|
-
end
|
26
|
-
|
27
|
-
serialize :details, Hash
|
28
|
-
|
29
|
-
validates :message, presence: true
|
30
|
-
validates :status, presence: true, inclusion: { in: EffectiveLogging.statuses }
|
31
|
-
|
32
|
-
scope :deep, -> { includes(:user, :associated) }
|
33
|
-
scope :sorted, -> { order(:id) }
|
34
|
-
scope :logged_changes, -> { where(status: EffectiveLogging.log_changes_status) }
|
35
|
-
scope :changes, -> { where(status: EffectiveLogging.log_changes_status) }
|
36
|
-
|
37
|
-
def to_s
|
38
|
-
"Log #{id}"
|
39
|
-
end
|
40
|
-
|
41
|
-
def associated_to_s=(value)
|
42
|
-
super(value.to_s[0...255].presence) # Take only first 255 characters
|
43
|
-
end
|
44
|
-
|
45
|
-
def log(message, status = EffectiveLogging.statuses.first, options = {})
|
46
|
-
EffectiveLogger.log(message, status, options)
|
47
|
-
end
|
48
|
-
|
49
|
-
def details
|
50
|
-
self[:details] || {}
|
51
|
-
end
|
52
|
-
|
53
|
-
def next_log
|
54
|
-
Log.order(id: :asc).where('id > ?', id).first
|
55
|
-
end
|
56
|
-
|
57
|
-
def prev_log
|
58
|
-
Log.order(id: :desc).where('id < ?', id).first
|
59
|
-
end
|
60
|
-
|
61
|
-
# Dynamically add logging methods based on the defined statuses
|
62
|
-
# EffectiveLogging.info 'my message'
|
63
|
-
(EffectiveLogging.statuses || []).each do |status|
|
64
|
-
send(:define_method, status) { |message, options={}| log(message, status, options) }
|
65
|
-
end
|
66
|
-
|
5
|
+
effective_logging_log
|
67
6
|
end
|
68
7
|
end
|
data/config/effective_logging.rb
CHANGED
@@ -2,6 +2,9 @@ EffectiveLogging.setup do |config|
|
|
2
2
|
# Configure Database Tables
|
3
3
|
config.logs_table_name = :logs
|
4
4
|
|
5
|
+
# Specify Log class
|
6
|
+
# config.log_class_name = 'Effective::Log'
|
7
|
+
|
5
8
|
# Admin Screens Layout Settings
|
6
9
|
# config.layout = { application: 'application', admin: 'admin' }
|
7
10
|
|
@@ -51,17 +51,13 @@ module EffectiveLogging
|
|
51
51
|
private
|
52
52
|
|
53
53
|
def self.log_email(message, fields, user_klass)
|
54
|
-
tos = Array(message.to) - [nil, '']
|
54
|
+
tos = (Array(message.to) + Array(message.cc)) - [nil, '']
|
55
55
|
|
56
56
|
tos.each do |to|
|
57
57
|
user = (user_klass.where(email: to.downcase).first if user_klass.present?)
|
58
|
+
details = fields.merge(to: to, user: user)
|
58
59
|
|
59
|
-
|
60
|
-
::EffectiveLogger.email("#{message.subject} - #{tos.join(', ')}", user_fields)
|
61
|
-
end
|
62
|
-
|
63
|
-
if tos.blank? && (message.cc.present? || message.bcc.present?)
|
64
|
-
::EffectiveLogger.email("#{message.subject} - multiple recipients", fields)
|
60
|
+
::EffectiveLogger.email("#{message.subject} - #{to}", details)
|
65
61
|
end
|
66
62
|
|
67
63
|
true
|
data/lib/effective_logging.rb
CHANGED
@@ -6,12 +6,17 @@ module EffectiveLogging
|
|
6
6
|
def self.config_keys
|
7
7
|
[
|
8
8
|
:logs_table_name, :layout, :additional_statuses,
|
9
|
+
:log_class_name,
|
9
10
|
:active_storage_enabled, :email_enabled, :sign_in_enabled, :sign_out_enabled
|
10
11
|
]
|
11
12
|
end
|
12
13
|
|
13
14
|
include EffectiveGem
|
14
15
|
|
16
|
+
def self.Log
|
17
|
+
log_class_name&.constantize || Effective::Log
|
18
|
+
end
|
19
|
+
|
15
20
|
def self.statuses
|
16
21
|
@statuses ||= (
|
17
22
|
base = [
|
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
|
+
version: 4.0.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-
|
11
|
+
date: 2023-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,10 +94,12 @@ files:
|
|
94
94
|
- app/assets/javascripts/effective_logging/effective_logger.js.coffee.erb
|
95
95
|
- app/controllers/admin/logs_controller.rb
|
96
96
|
- app/controllers/effective/logs_controller.rb
|
97
|
+
- app/datatables/admin/effective_logs_datatable.rb
|
97
98
|
- app/datatables/effective_log_changes_datatable.rb
|
98
99
|
- app/datatables/effective_logs_datatable.rb
|
99
100
|
- app/helpers/effective_logging_helper.rb
|
100
101
|
- app/models/concerns/acts_as_loggable.rb
|
102
|
+
- app/models/concerns/effective_logging_log.rb
|
101
103
|
- app/models/effective/log.rb
|
102
104
|
- app/models/effective_logger.rb
|
103
105
|
- app/views/admin/logs/_layout.html.haml
|
@@ -139,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
141
|
- !ruby/object:Gem::Version
|
140
142
|
version: '0'
|
141
143
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
144
|
+
rubygems_version: 3.4.10
|
143
145
|
signing_key:
|
144
146
|
specification_version: 4
|
145
147
|
summary: Automatically log all sent emails, user logins, and page views. This also
|