effective_logging 3.1.0 → 3.1.5
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/controllers/admin/logs_controller.rb +0 -20
- data/app/controllers/effective/logs_controller.rb +0 -17
- data/app/datatables/effective_log_changes_datatable.rb +9 -9
- data/app/datatables/effective_logs_datatable.rb +5 -7
- data/app/models/effective/log.rb +12 -5
- data/app/views/effective/logs/_log.html.haml +12 -9
- data/config/routes.rb +1 -1
- data/lib/effective_logging/active_record_logger.rb +3 -0
- data/lib/effective_logging/active_storage_logger.rb +7 -1
- data/lib/effective_logging/email_logger.rb +13 -4
- data/lib/effective_logging/version.rb +1 -1
- metadata +2 -4
- data/app/models/effective/access_denied.rb +0 -17
- data/app/views/admin/logs/_actions.html.haml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fded3d821985ef83c7634533c8160498abfaef98e23976e1cd1e0df89646bc91
|
4
|
+
data.tar.gz: 4a662a9883fb91fdcadf09969e0f826e5e9e5a339d6a150b3b902b05420fb86c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfbeda5d1e61db271cc68476f00c31a3ada3ab4fcb6726ee5496f4cd2132cabf5e449def28339dde8533eed82cf0be2ac7b1e69d5c54cdf61b6682fa7ab4d5ed
|
7
|
+
data.tar.gz: cab6daf708f644c173844c3b7b01e8a98145c1afe7f8ba6824f248804f59dc4b4a98250b5d363239549be5f789789c249f21f6eb95fc453183c058f1f3c3c631
|
@@ -10,25 +10,5 @@ module Admin
|
|
10
10
|
layout(config.kind_of?(Hash) ? config[:admin] : config)
|
11
11
|
end
|
12
12
|
|
13
|
-
def index
|
14
|
-
EffectiveResources.authorize!(self, :index, Effective::Log)
|
15
|
-
@datatable = EffectiveLogsDatatable.new(self)
|
16
|
-
@page_title = 'Logs'
|
17
|
-
end
|
18
|
-
|
19
|
-
def show
|
20
|
-
@log = Effective::Log.includes(:logs).find(params[:id])
|
21
|
-
EffectiveResources.authorize!(self, :show, @log)
|
22
|
-
|
23
|
-
@log.next_log = Effective::Log.order(:id).where(parent_id: @log.parent_id).where('id > ?', @log.id).first
|
24
|
-
@log.prev_log = Effective::Log.order(:id).where(parent_id: @log.parent_id).where('id < ?', @log.id).last
|
25
|
-
|
26
|
-
@page_title = "Log ##{@log.to_param}"
|
27
|
-
|
28
|
-
if @log.logs.present?
|
29
|
-
@log.datatable = EffectiveLogsDatatable.new(self, log_id: @log.id)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
13
|
end
|
34
14
|
end
|
@@ -41,26 +41,9 @@ module Effective
|
|
41
41
|
# This is the User index event
|
42
42
|
def index
|
43
43
|
EffectiveResources.authorize!(self, :index, Effective::Log.new(user_id: current_user.id))
|
44
|
-
|
45
44
|
@datatable = EffectiveLogsDatatable.new(self, user_id: current_user.id)
|
46
45
|
end
|
47
46
|
|
48
|
-
# This is the User show event
|
49
|
-
def show
|
50
|
-
@log = Effective::Log.includes(:logs).find(params[:id])
|
51
|
-
|
52
|
-
EffectiveLogging.authorize!(self, :show, @log)
|
53
|
-
|
54
|
-
@log.next_log = Effective::Log.unscoped.order(:id).where(parent_id: @log.parent_id).where('id > ?', @log.id).first
|
55
|
-
@log.prev_log = Effective::Log.unscoped.order(:id).where(parent_id: @log.parent_id).where('id < ?', @log.id).last
|
56
|
-
|
57
|
-
@page_title = "Log ##{@log.to_param}"
|
58
|
-
|
59
|
-
if @log.logs.present?
|
60
|
-
@log.datatable = EffectiveLogsDatatable.new(self, log_id: @log.id)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
47
|
def html_part
|
65
48
|
@log = Effective::Log.find(params[:id])
|
66
49
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class EffectiveLogChangesDatatable < Effective::Datatable
|
2
4
|
datatable do
|
3
5
|
order :updated_at
|
@@ -5,19 +7,19 @@ class EffectiveLogChangesDatatable < Effective::Datatable
|
|
5
7
|
col :updated_at, label: 'Date'
|
6
8
|
col :id, visible: false
|
7
9
|
|
8
|
-
col :user, sort: false
|
10
|
+
col :user, search: :string, sort: false
|
9
11
|
|
10
12
|
col :associated_type, visible: false
|
11
|
-
col :associated_id, visible: false
|
12
|
-
col :associated_to_s, visible: false
|
13
|
+
col :associated_id, visible: false, label: 'Associated Id'
|
14
|
+
col :associated_to_s, visible: false, label: 'Associated'
|
13
15
|
|
14
16
|
col :message, sort: false do |log|
|
15
|
-
message
|
17
|
+
(log.message || '').gsub!("\n", '<br>')
|
16
18
|
|
17
19
|
if log.associated_id == attributes[:changes_to_id] && log.associated_type == attributes[:changes_to_type]
|
18
|
-
message
|
20
|
+
log.message
|
19
21
|
else
|
20
|
-
"#{log.associated_type} #{log.associated_to_s} - #{message}"
|
22
|
+
"#{log.associated_type} #{log.associated_to_s} - #{log.message}"
|
21
23
|
end
|
22
24
|
|
23
25
|
end.search do |collection, term, column, sql_column|
|
@@ -29,9 +31,7 @@ class EffectiveLogChangesDatatable < Effective::Datatable
|
|
29
31
|
tableize_hash(log.details)
|
30
32
|
end
|
31
33
|
|
32
|
-
|
33
|
-
actions_col partial: 'admin/logs/actions', partial_as: :log
|
34
|
-
end
|
34
|
+
actions_col
|
35
35
|
end
|
36
36
|
|
37
37
|
# A nil attributes[:log_id] means give me all the top level log entries
|
@@ -8,16 +8,16 @@ class EffectiveLogsDatatable < Effective::Datatable
|
|
8
8
|
if attributes[:user] == false
|
9
9
|
# Do not include
|
10
10
|
else
|
11
|
-
col :user, search: :string
|
11
|
+
col :user, search: :string, sort: false
|
12
12
|
end
|
13
13
|
|
14
14
|
unless attributes[:status] == false
|
15
15
|
col :status, search: { collection: EffectiveLogging.statuses }
|
16
16
|
end
|
17
17
|
|
18
|
-
col :associated_type,
|
19
|
-
col :associated_id,
|
20
|
-
col :associated_to_s,
|
18
|
+
col :associated_type, visible: false
|
19
|
+
col :associated_id, visible: false, label: 'Associated Id'
|
20
|
+
col :associated_to_s, label: 'Associated'
|
21
21
|
|
22
22
|
col :message do |log|
|
23
23
|
log.message.gsub("\n", '<br>')
|
@@ -29,9 +29,7 @@ class EffectiveLogsDatatable < Effective::Datatable
|
|
29
29
|
tableize_hash(log.details.except(:email))
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
actions_col partial: 'admin/logs/actions', partial_as: :log
|
34
|
-
end
|
32
|
+
actions_col
|
35
33
|
end
|
36
34
|
|
37
35
|
# A nil attributes[:log_id] means give me all the top level log entries
|
data/app/models/effective/log.rb
CHANGED
@@ -2,11 +2,6 @@ module Effective
|
|
2
2
|
class Log < ActiveRecord::Base
|
3
3
|
self.table_name = EffectiveLogging.logs_table_name.to_s
|
4
4
|
|
5
|
-
# These 3 attr_accessors are set on the controller #show actions
|
6
|
-
attr_accessor :datatable
|
7
|
-
attr_accessor :next_log
|
8
|
-
attr_accessor :prev_log
|
9
|
-
|
10
5
|
# Self-Referencing relationship
|
11
6
|
belongs_to :parent, class_name: 'Effective::Log', counter_cache: true, optional: true
|
12
7
|
has_many :logs, class_name: 'Effective::Log', foreign_key: :parent_id
|
@@ -58,6 +53,18 @@ module Effective
|
|
58
53
|
self[:details] || {}
|
59
54
|
end
|
60
55
|
|
56
|
+
def next_log
|
57
|
+
Log.order(id: :asc).where(parent_id: parent_id).where('id > ?', id).first
|
58
|
+
end
|
59
|
+
|
60
|
+
def prev_log
|
61
|
+
Log.order(id: :desc).where(parent_id: parent_id).where('id < ?', id).first
|
62
|
+
end
|
63
|
+
|
64
|
+
def child_logs_datatable
|
65
|
+
EffectiveLogsDatatable.new(log_id: id)
|
66
|
+
end
|
67
|
+
|
61
68
|
# Dynamically add logging methods based on the defined statuses
|
62
69
|
# EffectiveLogging.info 'my message'
|
63
70
|
(EffectiveLogging.statuses || []).each do |status|
|
@@ -8,18 +8,22 @@
|
|
8
8
|
%p= log.message.to_s.gsub("\n", '<br>').html_safe
|
9
9
|
|
10
10
|
.col-md-4.text-right
|
11
|
-
-
|
12
|
-
|
11
|
+
- prev_log = log.prev_log
|
12
|
+
- next_log = log.next_log
|
13
13
|
|
14
|
-
- if
|
15
|
-
= link_to '
|
14
|
+
- if prev_log.present?
|
15
|
+
= link_to 'Prev', request.fullpath.sub('/' + log.to_param, '/' + prev_log.to_param), class: 'btn btn-primary'
|
16
|
+
|
17
|
+
- if next_log.present?
|
18
|
+
= link_to 'Next', request.fullpath.sub('/' + log.to_param, '/' + next_log.to_param), class: 'btn btn-primary'
|
16
19
|
|
17
20
|
.panel-body.card-body
|
18
21
|
.row
|
19
22
|
.col-md-6
|
20
23
|
%p
|
21
24
|
- status_class = bootstrap_class_for_status(log.status)
|
22
|
-
%span{:
|
25
|
+
%span{class: (defined?(EffectiveBootstrap) ? "badge badge-#{status_class}" : "label label-#{status_class}")}= log.status
|
26
|
+
|
23
27
|
= log.created_at.strftime("%F %H:%M:%S")
|
24
28
|
= '(' + time_ago_in_words(log.created_at) + ' ago)'
|
25
29
|
|
@@ -28,7 +32,8 @@
|
|
28
32
|
%p
|
29
33
|
%strong User:
|
30
34
|
= (log.user.to_s.starts_with?('#<User:0x') ? (log.user.email rescue log.user) : log.user)
|
31
|
-
|
35
|
+
|
36
|
+
- if log.associated_id.present? && log.associated_type.present? && (log.associated.present? rescue false)
|
32
37
|
%p
|
33
38
|
%strong Associated:
|
34
39
|
- if log.associated.to_s.starts_with?('#<')
|
@@ -47,6 +52,4 @@
|
|
47
52
|
- if log.logs.present?
|
48
53
|
%hr
|
49
54
|
%p This log contains #{log.logs_count} additional sub entries:
|
50
|
-
|
51
|
-
- unless log.datatable.nil?
|
52
|
-
= render_datatable(log.datatable)
|
55
|
+
= render_datatable(log.child_logs_datatable)
|
data/config/routes.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
EffectiveLogging::Engine.routes.draw do
|
2
|
-
scope :
|
2
|
+
scope module: 'effective' do
|
3
3
|
# Create is our javascript POST event for EffectiveLogging from JS side
|
4
4
|
# The show and index routes are for user specific logs
|
5
5
|
resources :logs, only: [:create, :index, :show] do
|
@@ -33,6 +33,9 @@ module EffectiveLogging
|
|
33
33
|
return true if changes.blank? # If you just click save and change nothing, don't log it.
|
34
34
|
|
35
35
|
message = (['Updated'] + changes.map do |attribute, (before, after)|
|
36
|
+
before = "HTML content (#{before.length})" if before.kind_of?(String) && before.include?('<div')
|
37
|
+
after = "HTML content (#{after.length})" if after.kind_of?(String) && after.include?('<div')
|
38
|
+
|
36
39
|
"#{attribute}: #{before.presence || BLANK} → #{after.presence || BLANK}"
|
37
40
|
end).join("\n")
|
38
41
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module EffectiveLogging
|
2
4
|
module ActiveStorageLogger
|
3
5
|
|
@@ -6,16 +8,20 @@ module EffectiveLogging
|
|
6
8
|
|
7
9
|
key = decode_verified_key()
|
8
10
|
return unless key.present?
|
11
|
+
return if (key[:content_type] || '').starts_with?('image')
|
9
12
|
|
10
13
|
blob = ActiveStorage::Blob.where(key: key[:key]).first
|
11
14
|
return unless blob.present?
|
12
15
|
|
13
16
|
blob.attachments.each do |attachment|
|
17
|
+
next if attachment.name == 'embeds'
|
18
|
+
next if attachment.record_type == 'ActionText::RichText'
|
19
|
+
|
14
20
|
associated = attachment.record
|
15
21
|
filename = blob.filename.to_s
|
16
22
|
message = [associated.to_s, filename.to_s].uniq.join(' ')
|
17
23
|
|
18
|
-
EffectiveLogger.download(message, associated: associated, filename: filename, user: user)
|
24
|
+
EffectiveLogger.download(message, associated: associated, associated_to_s: filename, filename: filename, user: user)
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
@@ -8,10 +8,19 @@ module EffectiveLogging
|
|
8
8
|
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
|
-
# mail(to: 'admin@example.com', subject: @post.title, log:
|
11
|
+
# mail(to: 'admin@example.com', subject: @post.title, log: @post)
|
12
|
+
|
12
13
|
if message.header['log'].present?
|
13
|
-
|
14
|
-
|
14
|
+
obj = message.header['log'].instance_variable_get(:@unparsed_value)
|
15
|
+
obj ||= message.header['log'].instance_variable_get(:@value)
|
16
|
+
|
17
|
+
if obj.kind_of?(ActiveRecord::Base)
|
18
|
+
fields.merge!(associated: obj)
|
19
|
+
elsif obj.kind_of?(Hash)
|
20
|
+
fields.merge!(obj)
|
21
|
+
else
|
22
|
+
raise('log expected an ActiveRecord object or Hash')
|
23
|
+
end
|
15
24
|
|
16
25
|
# Get rid of the extra header, as it should not be set in the real mail message.
|
17
26
|
message.header['log'] = nil
|
@@ -49,7 +58,7 @@ module EffectiveLogging
|
|
49
58
|
tos.each do |to|
|
50
59
|
user = (user_klass.where(email: to.downcase).first if user_klass.present?)
|
51
60
|
|
52
|
-
user_fields = fields.merge(to: to, user: user
|
61
|
+
user_fields = fields.merge(to: to, user: user)
|
53
62
|
::EffectiveLogger.email("#{message.subject} - #{tos.join(', ')}", user_fields)
|
54
63
|
end
|
55
64
|
|
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.1.
|
4
|
+
version: 3.1.5
|
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-
|
11
|
+
date: 2021-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -98,10 +98,8 @@ files:
|
|
98
98
|
- app/datatables/effective_logs_datatable.rb
|
99
99
|
- app/helpers/effective_logging_helper.rb
|
100
100
|
- app/models/concerns/acts_as_loggable.rb
|
101
|
-
- app/models/effective/access_denied.rb
|
102
101
|
- app/models/effective/log.rb
|
103
102
|
- app/models/effective_logger.rb
|
104
|
-
- app/views/admin/logs/_actions.html.haml
|
105
103
|
- app/views/admin/logs/index.html.haml
|
106
104
|
- app/views/admin/logs/show.html.haml
|
107
105
|
- app/views/effective/logs/_log.html.haml
|
@@ -1,17 +0,0 @@
|
|
1
|
-
unless defined?(Effective::AccessDenied)
|
2
|
-
module Effective
|
3
|
-
class AccessDenied < StandardError
|
4
|
-
attr_reader :action, :subject
|
5
|
-
|
6
|
-
def initialize(message = nil, action = nil, subject = nil)
|
7
|
-
@message = message
|
8
|
-
@action = action
|
9
|
-
@subject = subject
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
@message || I18n.t(:'unauthorized.default', :default => 'Access Denied')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
- show_path = (datatable.admin_namespace? ? effective_logging.admin_log_path(log) : effective_logging.log_path(log))
|
2
|
-
|
3
|
-
- if defined?(EffectiveBootstrap)
|
4
|
-
= dropdown(variation: :dropleft) do
|
5
|
-
= dropdown_link_to 'View', show_path
|
6
|
-
- else
|
7
|
-
= link_to show_path, title: 'View' do
|
8
|
-
%span.glyphicon.glyphicon-eye-open
|