effective_logging 1.11.5 → 2.0.0

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
  SHA1:
3
- metadata.gz: 937a74b79730479f2f0994cc786d8eabff3903dc
4
- data.tar.gz: 63dc477e50b0f04be570827151e9d5d7eaaf39f0
3
+ metadata.gz: ee73b0a26f21fe2980801d4b8e901ec547ae7721
4
+ data.tar.gz: 46e1f46fac857042523878446ea3c364e138d887
5
5
  SHA512:
6
- metadata.gz: e38a2c8bde33e965ada2d85341e23fc13d5062d99bf6bc184cc9710538c3dd29dae792b49dc1b5c4ec19c938cc8e4070add8d160ab3e6da43e1b7cae5904dc8f
7
- data.tar.gz: 614b8ae1532afe2f49b1dc292a461a4430806db91ec676ab80cc8a0e3c0f48b78049ba45598a0dede8bca0cdd673cc120e8f10f75b5a37f2d8fdb92a016af9d5
6
+ metadata.gz: daaddf8064d083684ca67c8629f210d5cde233ff0d4c03cc39b428cdd3f078599417c5b121aa82dcbe7a5e23a37c26e5e954025b3ba4b74cf41a12805b17ec2c
7
+ data.tar.gz: c7a757f10c577b05c8069f822a3f2427c8a2e0cb9d14e0f4cda880a8cb33f806c0ab6681d844b98eb02e7a5dd8e97b037c3a54ffdfb89d8eb88f056630d910f6
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2017 Code and Effect Inc.
1
+ Copyright 2018 Code and Effect Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  Automatically log all sent emails, user logins, and page views. This also will log custom events from Ruby and JavaScript.
4
4
 
5
- A Rails3 / Rails4 engine to completely handle logging of events.
6
-
7
5
  Logs are stored in a single database table. A Log (one logged event) can have many children Logs, nested to any depth.
8
6
 
9
7
  Provides a ruby one-liner to log a message, status, user, associated object and any number of additional details.
@@ -294,13 +292,7 @@ Creating child logs via JavaScript is not yet supported.
294
292
 
295
293
  ## Admin Screen
296
294
 
297
- To use the Admin screen, please also install the [effective_datatables](https://github.com/code-and-effect/effective_datatables/) gem:
298
-
299
- ```ruby
300
- gem 'effective_datatables'
301
- ```
302
-
303
- Then you should be able to visit:
295
+ Visit:
304
296
 
305
297
  ```ruby
306
298
  link_to 'Logs', effective_logging.admin_logs_path # /admin/logs
@@ -341,22 +333,10 @@ EffectiveLogsDatatable.new(for: @user.id)
341
333
  EffectiveLogsDatatable.new(for: [1, 2, 3]) # Users with ID 1, 2 and 3
342
334
  ```
343
335
 
344
-
345
336
  ## License
346
337
 
347
338
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
348
339
 
349
- ## Testing
350
-
351
- The test suite for this gem is unfortunately not yet complete.
352
-
353
- Run tests by:
354
-
355
- ```ruby
356
- rake spec
357
- ```
358
-
359
-
360
340
  ## Contributing
361
341
 
362
342
  1. Fork it
@@ -1,42 +1,32 @@
1
1
  module Admin
2
2
  class LogsController < ApplicationController
3
- respond_to?(:before_action) ? before_action(:authenticate_user!) : before_filter(:authenticate_user!) # Devise
3
+ before_action :authenticate_user!
4
+ skip_log_page_views
4
5
 
5
6
  layout (EffectiveLogging.layout.kind_of?(Hash) ? EffectiveLogging.layout[:admin_logs] : EffectiveLogging.layout)
6
7
 
7
- skip_log_page_views quiet: true
8
- helper EffectiveLoggingHelper
9
-
10
8
  def index
11
- if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
12
- @datatable = Effective::Datatables::Logs.new()
13
- else
14
- @datatable = EffectiveLogsDatatable.new(self)
15
- end
9
+ @datatable = EffectiveLogsDatatable.new(self)
16
10
 
17
11
  @page_title = 'Logs'
18
12
 
19
- EffectiveLogging.authorized?(self, :index, Effective::Log)
20
- EffectiveLogging.authorized?(self, :admin, :effective_logging)
13
+ EffectiveLogging.authorize!(self, :index, Effective::Log)
14
+ EffectiveLogging.authorize!(self, :admin, :effective_logging)
21
15
  end
22
16
 
23
17
  def show
24
18
  @log = Effective::Log.includes(:logs).find(params[:id])
25
- @log.next_log = Effective::Log.unscoped.order(:id).where(parent_id: @log.parent_id).where('id > ?', @log.id).first
26
- @log.prev_log = Effective::Log.unscoped.order(:id).where(parent_id: @log.parent_id).where('id < ?', @log.id).last
19
+ @log.next_log = Effective::Log.order(:id).where(parent_id: @log.parent_id).where('id > ?', @log.id).first
20
+ @log.prev_log = Effective::Log.order(:id).where(parent_id: @log.parent_id).where('id < ?', @log.id).last
27
21
 
28
22
  @page_title = "Log ##{@log.to_param}"
29
23
 
30
24
  if @log.logs.present?
31
- if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
32
- @log.datatable = Effective::Datatables::Logs.new(log_id: @log.id)
33
- else
34
- @log.datatable = EffectiveLogsDatatable.new(self, log_id: @log.id)
35
- end
25
+ @log.datatable = EffectiveLogsDatatable.new(self, log_id: @log.id)
36
26
  end
37
27
 
38
- EffectiveLogging.authorized?(self, :show, @log)
39
- EffectiveLogging.authorized?(self, :admin, :effective_logging)
28
+ EffectiveLogging.authorize!(self, :show, @log)
29
+ EffectiveLogging.authorize!(self, :admin, :effective_logging)
40
30
  end
41
31
  end
42
32
  end
@@ -1,21 +1,16 @@
1
1
  module Effective
2
2
  class LogsController < ApplicationController
3
- skip_log_page_views quiet: true
4
-
5
- if respond_to?(:before_action) # Devise
6
- before_action :authenticate_user!, only: [:index, :show]
7
- else
8
- before_filter :authenticate_user!, only: [:index, :show]
9
- end
3
+ skip_log_page_views
4
+ before_action :authenticate_user!, only: [:index, :show]
10
5
 
11
6
  # This is a post from our Javascript
12
7
  def create
13
- EffectiveLogging.authorized?(self, :create, Effective::Log.new())
8
+ EffectiveLogging.authorize!(self, :create, Effective::Log.new)
14
9
 
15
- @log = Effective::Log.new().tap do |log|
10
+ @log = Effective::Log.new.tap do |log|
16
11
  log.message = log_params[:message]
17
- log.status = (EffectiveLogging.statuses.include?(log_params[:status]) ? log_params[:status] : 'info')
18
- log.user = (current_user rescue nil)
12
+ log.status = EffectiveLogging.statuses.find { |status| status == log_params[:status] } || 'info'
13
+ log.user = EffectiveLogging.current_user || current_user
19
14
 
20
15
  count = -1
21
16
  Array((JSON.parse(log_params[:details]) rescue [])).flatten(1).each do |obj|
@@ -39,38 +34,31 @@ module Effective
39
34
 
40
35
  # This is the User index event
41
36
  def index
42
- if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
43
- @datatable = Effective::Datatables::Logs.new(user_id: current_user.id)
44
- else
45
- @datatable = EffectiveLogsDatatable.new(self, user_id: current_user.id)
46
- end
37
+ EffectiveLogging.authorize!(self, :index, Effective::Log.new(user_id: current_user.id))
47
38
 
48
- EffectiveLogging.authorized?(self, :index, Effective::Log.new(user_id: current_user.id))
39
+ @datatable = EffectiveLogsDatatable.new(self, user_id: current_user.id)
49
40
  end
50
41
 
51
42
  # This is the User show event
52
43
  def show
53
44
  @log = Effective::Log.includes(:logs).find(params[:id])
45
+
46
+ EffectiveLogging.authorize!(self, :show, @log)
47
+
54
48
  @log.next_log = Effective::Log.unscoped.order(:id).where(parent_id: @log.parent_id).where('id > ?', @log.id).first
55
49
  @log.prev_log = Effective::Log.unscoped.order(:id).where(parent_id: @log.parent_id).where('id < ?', @log.id).last
56
50
 
57
51
  @page_title = "Log ##{@log.to_param}"
58
52
 
59
53
  if @log.logs.present?
60
- if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
61
- @log.datatable = Effective::Datatables::Logs.new(log_id: @log.id)
62
- else
63
- @log.datatable = EffectiveLogsDatatable.new(self, log_id: @log.id)
64
- end
54
+ @log.datatable = EffectiveLogsDatatable.new(self, log_id: @log.id)
65
55
  end
66
-
67
- EffectiveLogging.authorized?(self, :show, @log)
68
56
  end
69
57
 
70
58
  def html_part
71
59
  @log = Effective::Log.find(params[:id])
72
60
 
73
- EffectiveLogging.authorized?(self, :show, @log)
61
+ EffectiveLogging.authorize!(self, :show, @log)
74
62
 
75
63
  value = @log.details[(params[:key] || '').to_sym].to_s
76
64
 
@@ -88,11 +76,7 @@ module Effective
88
76
 
89
77
  # StrongParameters
90
78
  def log_params
91
- begin
92
- params.require(:effective_log).permit(:message, :status, :details)
93
- rescue => e
94
- params[:effective_log] || {}
95
- end
79
+ params.require(:effective_log).permit(:message, :status, :details)
96
80
  end
97
81
 
98
82
  end
@@ -1,72 +1,70 @@
1
- unless Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
2
- class EffectiveLogsDatatable < Effective::Datatable
3
- datatable do
4
- order :updated_at
1
+ class EffectiveLogsDatatable < Effective::Datatable
2
+ datatable do
3
+ order :updated_at
5
4
 
6
- col :updated_at, label: 'Date'
7
- col :id, visible: false
5
+ col :updated_at, label: 'Date'
6
+ col :id, visible: false
8
7
 
9
- if attributes[:user] == false
10
- # Do not include
11
- elsif attributes[:for]
12
- col :user, search: :string
13
- else
14
- col :user
15
- end
8
+ if attributes[:user] == false
9
+ # Do not include
10
+ elsif attributes[:for]
11
+ col :user, search: :string
12
+ else
13
+ col :user
14
+ end
16
15
 
17
- unless attributes[:status] == false
18
- col :status, search: { collection: EffectiveLogging.statuses }
19
- end
16
+ unless attributes[:status] == false
17
+ col :status, search: { collection: EffectiveLogging.statuses }
18
+ end
20
19
 
21
- unless attributes[:log_changes]
22
- col :associated_type, search: { as: :string }, visible: false
23
- col :associated_id, search: { as: :integer }, visible: false, label: 'Associated Id'
24
- col :associated_to_s, search: { as: :string }, label: 'Associated'
25
- end
20
+ unless attributes[:log_changes]
21
+ col :associated_type, search: { as: :string }, visible: false
22
+ col :associated_id, search: { as: :integer }, visible: false, label: 'Associated Id'
23
+ col :associated_to_s, search: { as: :string }, label: 'Associated'
24
+ end
26
25
 
27
- if attributes[:log_changes]
28
- col :message do |log|
29
- log.message.starts_with?("\t") ? log.message.gsub("\t", "&nbsp;&nbsp;") : log.message
30
- end
31
- else
32
- col :message
26
+ if attributes[:log_changes]
27
+ col :message do |log|
28
+ log.message.starts_with?("\t") ? log.message.gsub("\t", "&nbsp;&nbsp;") : log.message
33
29
  end
30
+ else
31
+ col :message
32
+ end
34
33
 
35
- col :logs_count, visible: false
34
+ col :logs_count, visible: false
36
35
 
37
- col :details, visible: false, sort: false do |log|
38
- tableize_hash(log.details.except(:email))
39
- end
40
-
41
- unless attributes[:actions] == false
42
- actions_col partial: 'admin/logs/actions', partial_as: :log
43
- end
36
+ col :details, visible: false, sort: false do |log|
37
+ tableize_hash(log.details.except(:email))
44
38
  end
45
39
 
46
- # A nil attributes[:log_id] means give me all the top level log entries
47
- # If we set a log_id then it's for sub logs
48
- collection do
49
- scope = Effective::Log.unscoped.where(parent_id: attributes[:log_id]).includes(:user, :associated)
40
+ unless attributes[:actions] == false
41
+ actions_col partial: 'admin/logs/actions', partial_as: :log
42
+ end
43
+ end
50
44
 
51
- if attributes[:log_changes]
52
- scope = scope.where(status: EffectiveLogging.log_changes_status)
53
- end
45
+ # A nil attributes[:log_id] means give me all the top level log entries
46
+ # If we set a log_id then it's for sub logs
47
+ collection do
48
+ scope = Effective::Log.deep.where(parent_id: attributes[:log_id])
54
49
 
55
- if attributes[:for]
56
- user_ids = Array(attributes[:for])
57
- scope = scope.where('user_id IN (?) OR (associated_id IN (?) AND associated_type = ?)', user_ids, user_ids, 'User')
58
- end
50
+ if attributes[:log_changes]
51
+ scope = scope.where(status: EffectiveLogging.log_changes_status)
52
+ end
59
53
 
60
- if attributes[:associated_id] && attributes[:associated_type]
61
- scope = scope.where(associated_id: attributes[:associated_id], associated_type: attributes[:associated_type])
62
- end
54
+ if attributes[:for]
55
+ user_ids = Array(attributes[:for])
56
+ scope = scope.where('user_id IN (?) OR (associated_id IN (?) AND associated_type = ?)', user_ids, user_ids, 'User')
57
+ end
63
58
 
64
- if attributes[:associated]
65
- scope = scope.where(associated: attributes[:associated])
66
- end
59
+ if attributes[:associated_id] && attributes[:associated_type]
60
+ scope = scope.where(associated_id: attributes[:associated_id], associated_type: attributes[:associated_type])
61
+ end
67
62
 
68
- scope
63
+ if attributes[:associated]
64
+ scope = scope.where(associated: attributes[:associated])
69
65
  end
70
66
 
67
+ scope
71
68
  end
69
+
72
70
  end
@@ -12,7 +12,7 @@ module EffectiveLoggingHelper
12
12
  end
13
13
 
14
14
  def render_log(log)
15
- render(partial: 'effective/logs/log', locals: {log: log})
15
+ render(partial: 'effective/logs/log', locals: { log: log })
16
16
  end
17
17
 
18
18
  def parents_of_log(log)
@@ -24,13 +24,11 @@ module EffectiveLoggingHelper
24
24
  # This is called on the Logs#show Admin page, and is intended for override by the application
25
25
  def effective_logging_object_link_to(obj, action = :show)
26
26
  if obj.kind_of?(User)
27
- return (
28
- if action == :show && defined?(admin_user_path)
29
- link_to('View', admin_user_path(obj))
30
- elsif action == :edit && defined?(edit_admin_user_path)
31
- link_to('Edit', edit_admin_user_path(obj))
32
- end
33
- )
27
+ if action == :show && defined?(admin_user_path)
28
+ link_to('View', admin_user_path(obj))
29
+ elsif action == :edit && defined?(edit_admin_user_path)
30
+ link_to('Edit', edit_admin_user_path(obj))
31
+ end
34
32
  end
35
33
  end
36
34
 
@@ -14,7 +14,7 @@ module ActsAsLoggable
14
14
  end
15
15
 
16
16
  included do
17
- has_many :logged_changes, -> { where(status: EffectiveLogging.log_changes_status) }, as: :associated, class_name: 'Effective::Log'
17
+ has_many :logged_changes, -> { order(:id).where(status: EffectiveLogging.log_changes_status) }, as: :associated, class_name: 'Effective::Log'
18
18
 
19
19
  around_save do |_, block|
20
20
  @acts_as_loggable_new_record = new_record?
@@ -72,11 +72,7 @@ module ActsAsLoggable
72
72
  return nil unless persisted?
73
73
 
74
74
  @log_changes_datatable ||= (
75
- if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
76
- Effective::Datatables::Logs.new(associated_id: id, associated_type: self.class.name, log_changes: true, status: false)
77
- else
78
- EffectiveLogsDatatable.new(associated_id: id, associated_type: self.class.name, log_changes: true, status: false)
79
- end
75
+ EffectiveLogsDatatable.new(associated_id: id, associated_type: self.class.name, log_changes: true, status: false)
80
76
  )
81
77
  end
82
78
 
@@ -11,15 +11,8 @@ module Effective
11
11
  belongs_to :parent, class_name: 'Effective::Log', counter_cache: true
12
12
  has_many :logs, class_name: 'Effective::Log', foreign_key: :parent_id
13
13
 
14
- # The user this log item is referring to
15
- # An associated object, if we wanna add anything extra
16
- if Gem::Version.new(Rails.version) < Gem::Version.new('5.0')
17
- belongs_to :user
18
- belongs_to :associated, polymorphic: true
19
- else
20
- belongs_to :user, optional: true
21
- belongs_to :associated, polymorphic: true, optional: true
22
- end
14
+ belongs_to :user
15
+ belongs_to :associated, polymorphic: true
23
16
 
24
17
  serialize :details, Hash
25
18
 
@@ -37,8 +30,8 @@ module Effective
37
30
  validates :message, presence: true
38
31
  validates :status, presence: true, inclusion: { in: EffectiveLogging.statuses }
39
32
 
40
- default_scope -> { order(updated_at: :desc) }
41
-
33
+ scope :deep, -> { includes(:user, :associated) }
34
+ scope :sorted, -> { order(:id) }
42
35
  scope :logged_changes, -> { where(status: EffectiveLogging.log_changes_status)}
43
36
  scope :changes, -> { where(status: EffectiveLogging.log_changes_status)}
44
37
 
@@ -58,14 +51,6 @@ module Effective
58
51
  self[:details] || {}
59
52
  end
60
53
 
61
- # def next_log
62
- # @next_log ||= Log.unscoped.order(:id).where(:parent_id => self.parent_id).where('id > ?', self.id).first
63
- # end
64
-
65
- # def prev_log
66
- # @prev_log ||= Log.unscoped.order(:id).where(:parent_id => self.parent_id).where('id < ?', self.id).last
67
- # end
68
-
69
54
  # Dynamically add logging methods based on the defined statuses
70
55
  # EffectiveLogging.info 'my message'
71
56
  (EffectiveLogging.statuses || []).each do |status|
@@ -1,15 +1,7 @@
1
- :ruby
2
- show_path =
3
- if datatable.try(:admin_namespace?)
4
- effective_logging.admin_log_path(log)
5
- else
6
- effective_logging.log_path(log)
7
- end
1
+ - show_path = (datatable.admin_namespace? ? effective_logging.admin_log_path(log) : effective_logging.log_path(log))
8
2
 
9
- - if log.logs_count.to_i > 0
10
- = link_to show_path, title: 'View' do
11
- %span.glyphicon.glyphicon-eye-open
12
- = "(#{log.logs_count})"
3
+ - if defined?(EffectiveBootstrap)
4
+ = show_icon_to(show_path)
13
5
  - else
14
6
  = link_to show_path, title: 'View' do
15
7
  %span.glyphicon.glyphicon-eye-open
@@ -1,33 +1,37 @@
1
- .panel{:class => "panel-#{bootstrap_class_for_status(log.status)}"}
2
- .panel-heading
1
+ .panel.card
2
+ .panel-heading.card-header
3
3
  .row
4
- .col-sm-10
4
+ .col-md-10
5
5
  - parents_of_log(log).each do |parent|
6
- = link_to(log.message, (request.fullpath.gsub(log.to_param, parent.to_param) rescue '#'))
6
+ = link_to(log.message, request.fullpath.sub('/' + log.to_param, '/' + parent.to_param))
7
7
  = ' > '
8
8
  %p= log.message.html_safe
9
- .col-sm-2.text-right
10
- = link_to 'Prev', request.fullpath.gsub(log.to_param, log.prev_log.try(:to_param).to_s), class: 'btn btn-default', disabled: log.prev_log.blank?
11
- = link_to 'Next', request.fullpath.gsub(log.to_param, log.next_log.try(:to_param).to_s), class: 'btn btn-default', disabled: log.next_log.blank?
9
+ .col-md-2.text-right
10
+ - if log.prev_log
11
+ = link_to 'Prev', request.fullpath.sub('/' + log.to_param, '/' + log.prev_log.to_param), class: 'btn btn-primary'
12
12
 
13
- .panel-body
13
+ - if log.next_log
14
+ = link_to 'Next', request.fullpath.sub('/' + log.to_param, '/' + log.prev_log.to_param), class: 'btn btn-primary'
15
+
16
+ .panel-body.card-body
14
17
  .row
15
- .col-lg-6
16
- %span.label{:class => "label-#{bootstrap_class_for_status(log.status)}"}= log.status
18
+ .col-md-6
19
+ - status_class = bootstrap_class_for_status(log.status)
20
+ %span.label.badge{:class => "label-#{status_class} badge-#{status_class}"}= log.status
17
21
  &nbsp;
18
- = log.created_at.strftime("%Y-%m-%d %H:%M:%S")
22
+ = log.created_at.strftime("%F %H:%M:%S")
19
23
  = '(' + time_ago_in_words(log.created_at) + ' ago)'
20
24
  %br
21
25
  %br
22
26
 
23
- .col-lg-6
27
+ .col-md-6
24
28
  - if log.user.present?
25
29
  %strong User:
26
30
  &nbsp;
27
31
  = (log.user.to_s.starts_with?('#<User:0x') ? (log.user.email rescue log.user) : log.user)
28
32
  - if (log.associated.present? rescue false)
29
33
  %br
30
- %strong Regarding:
34
+ %strong Associated:
31
35
  &nbsp;
32
36
  - if log.associated.to_s.starts_with?('#<')
33
37
  = "#{log.associated.class.name} ##{log.associated.to_param}"
@@ -37,20 +41,21 @@
37
41
  - log.details.each do |key, value|
38
42
  - next unless value.present?
39
43
  .row
40
- .col-lg-12
44
+ .col-md-12
41
45
  %p
42
46
  %strong= "#{key.to_s.titleize}:"
43
47
  = format_log_details_value(log, key)
44
48
 
45
49
  - if log.logs.present?
46
50
  .row
47
- .col-lg-12
51
+ .col-md-12
48
52
  %br
49
53
  %p
50
54
  %strong Additional Entries:
51
55
  = "this log contains #{log.logs_count} additional sub entries"
52
- - if log.datatable.nil? == false
56
+
57
+ - unless log.datatable.nil?
53
58
  %hr
54
59
  .row
55
- .col-lg-12= render_datatable(log.datatable)
60
+ .col-md-12= render_datatable(log.datatable)
56
61
 
@@ -1,6 +1,3 @@
1
1
  %h1.effective-heading= @page_title
2
2
 
3
- - if @datatable.present?
4
- = render_datatable(@datatable)
5
- - else
6
- %p You have no previous recorded activity
3
+ = render_datatable(@datatable)
@@ -23,9 +23,6 @@ EffectiveLogging.setup do |config|
23
23
  # config.authorization_method = false
24
24
  config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) } # CanCanCan
25
25
 
26
- # Register Effective::Logs with ActiveAdmin if ActiveAdmin is present
27
- config.use_active_admin = true
28
-
29
26
  # Admin Screens Layout Settings
30
27
  config.layout = 'application' # All EffectiveLogging controllers will use this layout
31
28
 
@@ -34,8 +31,9 @@ EffectiveLogging.setup do |config|
34
31
  # admin_logs: 'admin',
35
32
  # }
36
33
 
37
- # All statuses defined here, as well as 'info', 'success', and 'error' (hardcoded) will be created as
38
34
  # EffectiveLogger.info('my message') macros
35
+ # The following statuses are already present: info, success, error, view, change, email, sign_in, sign_out
36
+ # Add more here
39
37
  config.additional_statuses = []
40
38
 
41
39
  #########################################
data/config/routes.rb CHANGED
@@ -7,10 +7,8 @@ EffectiveLogging::Engine.routes.draw do
7
7
  end
8
8
  end
9
9
 
10
- if defined?(EffectiveDatatables)
11
- namespace :admin do
12
- resources :logs, only: [:index, :show]
13
- end
10
+ namespace :admin do
11
+ resources :logs, only: [:index, :show]
14
12
  end
15
13
 
16
14
  end
@@ -11,14 +11,6 @@ module EffectiveLogging
11
11
  eval File.read("#{config.root}/config/effective_logging.rb")
12
12
  end
13
13
 
14
- # ActiveAdmin (optional)
15
- # This prepends the load path so someone can override the assets.rb if they want.
16
- initializer 'effective_logging.active_admin' do
17
- if defined?(ActiveAdmin) && EffectiveLogging.use_active_admin == true
18
- ActiveAdmin.application.load_paths.unshift Dir["#{config.root}/active_admin"]
19
- end
20
- end
21
-
22
14
  # Automatically Log Emails
23
15
  initializer 'effective_logging.emails' do |app|
24
16
  if EffectiveLogging.email_enabled == true
@@ -55,11 +47,7 @@ module EffectiveLogging
55
47
  config.after_initialize do
56
48
  if EffectiveLogging.sign_in_enabled || EffectiveLogging.sign_out_enabled
57
49
  ActiveSupport.on_load :active_record do
58
- if defined?(Devise)
59
- EffectiveLogging::UserLogger.create_warden_hooks()
60
- else
61
- raise ArgumentError.new("EffectiveLogging.sign_in_enabled only works with Devise")
62
- end
50
+ EffectiveLogging::UserLogger.create_warden_hooks()
63
51
  end
64
52
  end
65
53
  end
@@ -18,25 +18,18 @@ module EffectiveLogging
18
18
  self.log_page_views_opts = logging_options
19
19
 
20
20
  # Set up the after_filter to do page logging
21
- if respond_to?(:after_action)
22
- after_action :effective_logging_log_page_view, filter_options
23
- else
24
- after_filter :effective_logging_log_page_view, filter_options
25
- end
21
+ after_action :effective_logging_log_page_view, filter_options
26
22
  end
27
23
 
28
24
  def skip_log_page_views(options = {})
29
- Rails.logger.info("WARNING EffectiveLogging: skip_log_page_views called without first having called log_page_views. Please add 'log_page_views' to your ApplicationController or this controller before using skip_log_page_views") unless options[:quiet]
25
+ # Nothing
30
26
  end
27
+
31
28
  end
32
29
 
33
30
  module ClassMethods
34
31
  def skip_log_page_views(options = {})
35
- if respond_to?(:before_action)
36
- before_action :skip_log_page_view, options
37
- else
38
- before_filter :skip_log_page_view, options
39
- end
32
+ before_action :skip_log_page_view, options
40
33
  end
41
34
  end
42
35
 
@@ -45,7 +38,7 @@ module EffectiveLogging
45
38
  return if @_effective_logging_skip_log_page_view == true
46
39
  return if (self.class.log_page_views_opts[:skip_namespace] || []).include?(self.class.parent)
47
40
 
48
- user = (current_user rescue nil)
41
+ user = EffectiveLogging.current_user || current_user
49
42
 
50
43
  if self.class.log_page_views_opts[:details] == false
51
44
  ::EffectiveLogger.view("#{request.request_method} #{request.path}", user: user)
@@ -6,15 +6,7 @@ module EffectiveLogging
6
6
  # before_action :set_effective_logging_current_user
7
7
 
8
8
  def set_effective_logging_current_user
9
- if respond_to?(:current_user)
10
- EffectiveLogging.current_user = current_user
11
- else
12
- raise "(effective_logging) set_effective_logging_current_user expects a current_user() method to be available"
13
- end
14
- end
15
-
16
- def set_log_changes_user
17
- # No longer need to call this
9
+ EffectiveLogging.current_user = current_user
18
10
  end
19
11
 
20
12
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveLogging
2
- VERSION = '1.11.5'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -6,7 +6,6 @@ module EffectiveLogging
6
6
 
7
7
  # The following are all valid config keys
8
8
  mattr_accessor :logs_table_name
9
- mattr_accessor :use_active_admin
10
9
 
11
10
  mattr_accessor :authorization_method
12
11
  mattr_accessor :layout
@@ -21,10 +20,20 @@ module EffectiveLogging
21
20
  end
22
21
 
23
22
  def self.authorized?(controller, action, resource)
24
- if authorization_method.respond_to?(:call) || authorization_method.kind_of?(Symbol)
25
- raise Effective::AccessDenied.new() unless (controller || self).instance_exec(controller, action, resource, &authorization_method)
23
+ @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
24
+
25
+ return !!authorization_method unless authorization_method.respond_to?(:call)
26
+ controller = controller.controller if controller.respond_to?(:controller)
27
+
28
+ begin
29
+ !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
30
+ rescue *@_exceptions
31
+ false
26
32
  end
27
- true
33
+ end
34
+
35
+ def self.authorize!(controller, action, resource)
36
+ raise Effective::AccessDenied unless authorized?(controller, action, resource)
28
37
  end
29
38
 
30
39
  def self.supressed(&block)
@@ -37,9 +46,8 @@ module EffectiveLogging
37
46
 
38
47
  def self.statuses
39
48
  @statuses ||= (
40
- Array(@@additional_statuses).map do |status|
41
- status.to_s.downcase
42
- end | ['info', 'success', 'error', log_changes_status, ('email' if email_enabled), ('sign_in' if sign_in_enabled), ('sign_out' if sign_out_enabled), 'view'].compact
49
+ Array(@@additional_statuses).map { |status| status.to_s.downcase } | # union
50
+ ['info', 'success', 'error', 'view', log_changes_status, ('email' if email_enabled), ('sign_in' if sign_in_enabled), ('sign_out' if sign_out_enabled)].compact
43
51
  )
44
52
  end
45
53
 
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: 1.11.5
4
+ version: 2.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: 2018-01-21 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.0
19
+ version: '4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.0
26
+ version: '4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: effective_datatables
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.0
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.0
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: effective_resources
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -98,11 +98,8 @@ files:
98
98
  - app/helpers/effective_logging_helper.rb
99
99
  - app/models/concerns/acts_as_loggable.rb
100
100
  - app/models/effective/access_denied.rb
101
- - app/models/effective/datatables/logs.rb
102
101
  - app/models/effective/log.rb
103
102
  - app/models/effective_logger.rb
104
- - app/views/active_admin/effective_logging/logs/index.html.haml
105
- - app/views/active_admin/effective_logging/logs/show.html.haml
106
103
  - app/views/admin/logs/_actions.html.haml
107
104
  - app/views/admin/logs/index.html.haml
108
105
  - app/views/admin/logs/show.html.haml
@@ -1,80 +0,0 @@
1
- if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
2
- module Effective
3
- module Datatables
4
- class Logs < Effective::Datatable
5
- include EffectiveLoggingHelper
6
-
7
- datatable do
8
- default_order :updated_at, :desc
9
-
10
- table_column :updated_at, label: 'Date'
11
- table_column :id, visible: false
12
-
13
- if attributes[:user] == false
14
- # Do not include
15
- elsif attributes[:user_id].present?
16
- table_column :user, filter: { collection: User.where(id: Array(attributes[:user_id])) }
17
- elsif attributes[:user].present?
18
- table_column :user, filter: { collection: User.where(id: Array(attributes[:user]).map { |user| user.to_param }) }
19
- else
20
- table_column :user
21
- end
22
-
23
- unless attributes[:status] == false
24
- table_column :status, filter: { type: :select, values: EffectiveLogging.statuses }
25
- end
26
-
27
- unless attributes[:log_changes]
28
- table_column :associated_type, visible: false
29
- table_column :associated_id, visible: false, label: 'Associated Id'
30
- table_column :associated_to_s, label: 'Associated'
31
- end
32
-
33
- if attributes[:log_changes]
34
- table_column :message do |log|
35
- log.message.starts_with?("\t") ? log.message.gsub("\t", "&nbsp;&nbsp;") : log.message
36
- end
37
- else
38
- table_column :message
39
- end
40
-
41
- table_column :logs_count, visible: false
42
-
43
- table_column :details, visible: false, sortable: false do |log|
44
- tableize_hash(log.details.except(:email), th: true, sub_th: false)
45
- end
46
-
47
- unless attributes[:actions] == false
48
- actions_column partial: 'admin/logs/actions', partial_local: :log
49
- end
50
- end
51
-
52
- # A nil attributes[:log_id] means give me all the top level log entries
53
- # If we set a log_id then it's for sub logs
54
- def collection
55
- collection = Effective::Log.unscoped.where(parent_id: attributes[:log_id]).includes(:user, :associated)
56
-
57
- if attributes[:log_changes]
58
- collection = collection.where(status: EffectiveLogging.log_changes_status)
59
- end
60
-
61
- if (attributes[:user] || attributes[:user_id]).present?
62
- user_ids = Array(attributes[:user].presence || attributes[:user_id]).map { |user| user.kind_of?(User) ? user.id : user.to_i }
63
- collection = collection.where('user_id IN (?) OR (associated_id IN (?) AND associated_type = ?)', user_ids, user_ids, 'User')
64
- end
65
-
66
- if attributes[:associated_id] && attributes[:associated_type]
67
- collection = collection.where(associated_id: attributes[:associated_id], associated_type: attributes[:associated_type])
68
- end
69
-
70
- if attributes[:associated]
71
- collection = collection.where(associated: attributes[:associated])
72
- end
73
-
74
- collection
75
- end
76
-
77
- end
78
- end
79
- end
80
- end
@@ -1,7 +0,0 @@
1
- .fluid-container
2
- .row
3
- .col-sm-12
4
- - if @datatable.present?
5
- = render_datatable(@datatable)
6
- - else
7
- %p There are no logs
@@ -1,4 +0,0 @@
1
- .fluid-container
2
- .row
3
- .col-sm-12
4
- = render_log(@log)