effective_logging 3.5.4 → 4.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
  SHA256:
3
- metadata.gz: 5b0d07832764f1aca2982e520809195ae26b36c947b04b15f4ae5318ec74b4f7
4
- data.tar.gz: 507ff8215257de3ce69a6ded010f18ec123469b111b8cb74f426263cec3e43ac
3
+ metadata.gz: 07b93fb924886c7eb67bebfa52af0ebba0955dcf70f882631b20b6c8d1ad4561
4
+ data.tar.gz: af822e66e051e26100da80e9edab36e0c3665922924fadae8d2d8a9f0a34eed4
5
5
  SHA512:
6
- metadata.gz: d11842ba982615466b169a5415bed591f7e025cd912a94c0dc1ee4f105ea15b191833a73e78e6e406206c57de9456c5e12c6bc62961c5cb106fd24b4a5677446
7
- data.tar.gz: 7f270c7159f350a5de6db15f30e42665a541dd060747a967078212dc4f39b2036ff21b218c209c3d72f14667d26db62c6825fbd7a0493ca0ac2240166935b95f
6
+ metadata.gz: 39fca8a1eb4fe170a48c4e588d711cdee34cbd5999f05220a905e308e346ce80c2ece0bb840b480d67c11f43cd7f5215c009e32f1e13bf15c3526dab20a790f8
7
+ data.tar.gz: aff176f1e23569d3f91a6e3b9c59bf3d8636efb753ae32dee906937db304769230762f85df3ef986cfc6b461c3251233e2affe8c6cd5887fd249b7167a0656fc
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2021 Code and Effect Inc.
1
+ Copyright 2023 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
@@ -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, Effective::Log
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, Effective::Log
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, Effective::Log.new)
16
+ EffectiveResources.authorize!(self, :create, resource_scope.new)
15
17
 
16
- @log = Effective::Log.new.tap do |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, Effective::Log.new(user_id: current_user.id))
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 = Effective::Log.find(params[:id])
50
+ @log = resource_scope.find(params[:id])
49
51
 
50
52
  EffectiveResources.authorize!(self, :show, @log)
51
53
 
@@ -0,0 +1,2 @@
1
+ class Admin::EffectiveLogsDatatable < EffectiveLogsDatatable
2
+ end
@@ -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
- Effective::Log.logged_changes.deep
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 = Effective::Log.deep.all
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, class_name: 'Effective::Log'
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
@@ -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
- belongs_to :user, polymorphic: true, optional: true
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
@@ -24,7 +24,7 @@ class EffectiveLogger
24
24
  options[:user_agent] ||= request.user_agent
25
25
  end
26
26
 
27
- log = Effective::Log.new(
27
+ log = EffectiveLogging.Log.new(
28
28
  message: message,
29
29
  status: status,
30
30
  user_id: options.delete(:user_id),
@@ -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
 
@@ -43,7 +43,7 @@ module EffectiveLogging
43
43
  end
44
44
 
45
45
  def log(message, details)
46
- Effective::Log.create!(
46
+ EffectiveLogging.Log.create!(
47
47
  changes_to: log_changes_to,
48
48
  associated: object,
49
49
  associated_to_s: (object.to_s rescue nil),
@@ -28,6 +28,7 @@ module EffectiveLogging
28
28
  app.config.to_prepare do
29
29
  ActiveSupport.on_load :active_record do
30
30
  ActiveRecord::Base.extend(ActsAsLoggable::Base)
31
+ ActiveRecord::Base.extend(EffectiveLoggingLog::Base)
31
32
  end
32
33
  end
33
34
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveLogging
2
- VERSION = '3.5.4'.freeze
2
+ VERSION = '4.0.0'.freeze
3
3
  end
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.4
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
@@ -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