effective_logging 3.1.0 → 3.1.1

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: 91790ca464dd429fb345fcbef0d15cbdebefdbd56f8685aaa8206653a7cd4350
4
- data.tar.gz: fccd38fd9967c82487436ed7a25154bc7b84a4fc30c129691ce532683a951717
3
+ metadata.gz: e1dc7b7f4024ac664b211eba56892cd43828ec911f37361b91f1ac6496f87fb7
4
+ data.tar.gz: 512c990d5a8dddfcc665e28ff7dd6ef66302ce4f855d68d87fa89af44ef79ed4
5
5
  SHA512:
6
- metadata.gz: 57df8caf9cf1a316d2a4591f28ca072b08fa2fae0da1bf71cdd72474971e16637d60337eeb9ce903bfe35033c1fcf68fb7ed76e022aab47a8a7503289fd8cbbc
7
- data.tar.gz: 0b6106eade70761e9d71602846c5000308533de2058a6f8097e8aec22439155e5e55c83fafeeaf6a7e9c9339ec19cdd17cb15b372e3b3d79a1dc623eaf8b8bdf
6
+ metadata.gz: 612a1bed2cc27c80ee726a023a079e0a5a2dcf80b7d390e07bb9a692bf60da43c974d754bc29f99a17bc95d589e18457aa52261564da19e509947b47046a8f3c
7
+ data.tar.gz: 798375484126e11a779eaffbdf1c53e26a5530f701440b4190660948b52ee9c728e1e7f300684b088a636d4b9df1d08087b71dc3477a434a23c2422b576b27c7
@@ -16,19 +16,5 @@ module Admin
16
16
  @page_title = 'Logs'
17
17
  end
18
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
19
  end
34
20
  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 = log.message.gsub("\n", '<br>')
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
- unless attributes[:actions] == false
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, search: { as: :string }
19
- col :associated_id, search: { as: :integer }, visible: false, label: 'Associated Id'
20
- col :associated_to_s, search: { as: :string }, label: 'Associated'
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
- unless attributes[:actions] == false
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
@@ -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
- - if log.prev_log
12
- = link_to 'Prev', request.fullpath.sub('/' + log.to_param, '/' + log.prev_log.to_param), class: 'btn btn-primary'
11
+ - prev_log = log.prev_log
12
+ - next_log = log.next_log
13
13
 
14
- - if log.next_log
15
- = link_to 'Next', request.fullpath.sub('/' + log.to_param, '/' + log.next_log.to_param), class: 'btn btn-primary'
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{:class => (defined?(EffectiveBootstrap) ? "badge badge-#{status_class}" : "label label-#{status_class}")}= log.status
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
- - if (log.associated.present? rescue false)
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)
@@ -1,3 +1,3 @@
1
1
  module EffectiveLogging
2
- VERSION = '3.1.0'.freeze
2
+ VERSION = '3.1.1'.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.1.0
4
+ version: 3.1.1
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-02-18 00:00:00.000000000 Z
11
+ date: 2021-02-22 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