effective_logging 4.2.0 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/admin/tracks_controller.rb +8 -0
- data/app/datatables/admin/effective_tracks_datatable.rb +29 -0
- data/app/models/concerns/acts_as_trackable.rb +28 -0
- data/app/models/effective/track.rb +50 -0
- data/config/routes.rb +1 -0
- data/db/migrate/101_create_effective_logging.rb +17 -0
- data/lib/effective_logging/engine.rb +1 -0
- data/lib/effective_logging/version.rb +1 -1
- data/lib/effective_logging.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e35081e813792fcd9865ba3eba02cea731a1b51f4a5c011c97af9f3f25e0fc55
|
4
|
+
data.tar.gz: a1d4917f498c069796790aa020154f6d2b8b7b6f74a7d4185345277351c00de8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30a6e493e44048f188b01ec46b143f1a95f0bd05b350ed9749f53ce656e50f198f40a093f6d36051efab553f51f4d8f224c24951cf55e5db3b65614d66413080
|
7
|
+
data.tar.gz: db74e4b23a36e85c7a7a67e5ff1a48a1c4229db6593b6bf01c725bd8c66e8a79ed2bfa885e8f3945d5f97680587d01d1d539d1fc974d82081d4038ceec0b6eae
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Admin
|
2
|
+
class EffectiveTracksDatatable < Effective::Datatable
|
3
|
+
filters do
|
4
|
+
filter_date_range
|
5
|
+
|
6
|
+
scope :all
|
7
|
+
scope :signed_in
|
8
|
+
scope :signed_out
|
9
|
+
end
|
10
|
+
|
11
|
+
datatable do
|
12
|
+
col :id, visible: false
|
13
|
+
|
14
|
+
col :created_at
|
15
|
+
|
16
|
+
col :action
|
17
|
+
col :owner, label: 'Resource'
|
18
|
+
col :user
|
19
|
+
|
20
|
+
col :title
|
21
|
+
col :details, visible: false
|
22
|
+
end
|
23
|
+
|
24
|
+
collection do
|
25
|
+
Effective::Track.deep.all.where(created_at: date_range)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Just works with effective_resources controller to track views on show action
|
4
|
+
# Add acts_as_trackable to your model
|
5
|
+
# add_column :things, :tracks_count, :integer, default: 0
|
6
|
+
module ActsAsTrackable
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module Base
|
10
|
+
def acts_as_trackable(*options)
|
11
|
+
@acts_as_trackable = options || []
|
12
|
+
include ::ActsAsTrackable
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
included do
|
17
|
+
has_many :tracks, -> { order(:id) }, as: :owner, class_name: 'Effective::Track'
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def acts_as_trackable?; true; end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Instance Methods
|
25
|
+
def track!(action: 'view', user: nil, details: nil)
|
26
|
+
tracks.create!(action: action, user: user, details: details)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Effective
|
3
|
+
class Track < ActiveRecord::Base
|
4
|
+
self.table_name = (EffectiveLogging.tracks_table_name || :tracks).to_s
|
5
|
+
|
6
|
+
# The owner resource of this tracked thing
|
7
|
+
belongs_to :owner, polymorphic: true, counter_cache: true
|
8
|
+
|
9
|
+
# Present when the user is signed in
|
10
|
+
belongs_to :user, polymorphic: true, optional: true
|
11
|
+
|
12
|
+
ACTIONS = ['view']
|
13
|
+
|
14
|
+
effective_resource do
|
15
|
+
action :string
|
16
|
+
|
17
|
+
title :string
|
18
|
+
details :text
|
19
|
+
|
20
|
+
timestamps
|
21
|
+
end
|
22
|
+
|
23
|
+
if EffectiveResources.serialize_with_coder?
|
24
|
+
serialize :details, type: Hash, coder: YAML
|
25
|
+
else
|
26
|
+
serialize :details, Hash
|
27
|
+
end
|
28
|
+
|
29
|
+
validates :action, presence: true
|
30
|
+
before_save :assign_title # Assign computed title always
|
31
|
+
|
32
|
+
scope :sorted, -> { order(:id) }
|
33
|
+
scope :deep, -> { includes(:owner, :user) }
|
34
|
+
|
35
|
+
scope :signed_in, -> { where.not(user_id: nil) }
|
36
|
+
scope :signed_out, -> { where(user_id: nil) }
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
title.presence || model_name.human
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def assign_title
|
45
|
+
title = [action, 'of', "#{owner}", ("by #{user || 'guest user'}")].compact.join(' ')
|
46
|
+
assign_attributes(title: title)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/config/routes.rb
CHANGED
@@ -30,5 +30,22 @@ class CreateEffectiveLogging < ActiveRecord::Migration[6.0]
|
|
30
30
|
enable_extension('pg_trgm')
|
31
31
|
add_index :logs, :message, using: :gin, opclass: :gin_trgm_ops
|
32
32
|
add_index :logs, :details, using: :gin, opclass: :gin_trgm_ops
|
33
|
+
|
34
|
+
create_table :tracks do |t|
|
35
|
+
t.string :owner_type
|
36
|
+
t.integer :owner_id
|
37
|
+
|
38
|
+
t.string :user_type
|
39
|
+
t.integer :user_id
|
40
|
+
|
41
|
+
t.string :action
|
42
|
+
t.string :title
|
43
|
+
t.text :details
|
44
|
+
|
45
|
+
t.timestamps
|
46
|
+
end
|
47
|
+
|
48
|
+
add_index :tracks, :owner_id
|
49
|
+
add_index :tracks, :user_id
|
33
50
|
end
|
34
51
|
end
|
@@ -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(ActsAsTrackable::Base)
|
31
32
|
ActiveRecord::Base.extend(EffectiveLoggingLog::Base)
|
32
33
|
end
|
33
34
|
end
|
data/lib/effective_logging.rb
CHANGED
@@ -5,7 +5,7 @@ require 'effective_logging/version'
|
|
5
5
|
module EffectiveLogging
|
6
6
|
def self.config_keys
|
7
7
|
[
|
8
|
-
:logs_table_name, :layout, :additional_statuses,
|
8
|
+
:logs_table_name, :tracks_table_name, :layout, :additional_statuses,
|
9
9
|
:log_class_name,
|
10
10
|
:active_storage_enabled, :email_enabled, :sign_in_enabled, :sign_out_enabled
|
11
11
|
]
|
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.
|
4
|
+
version: 4.3.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: 2024-
|
11
|
+
date: 2024-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -177,14 +177,18 @@ files:
|
|
177
177
|
- app/assets/javascripts/effective_logging.js
|
178
178
|
- app/assets/javascripts/effective_logging/effective_logger.js.coffee.erb
|
179
179
|
- app/controllers/admin/logs_controller.rb
|
180
|
+
- app/controllers/admin/tracks_controller.rb
|
180
181
|
- app/controllers/effective/logs_controller.rb
|
181
182
|
- app/datatables/admin/effective_logs_datatable.rb
|
183
|
+
- app/datatables/admin/effective_tracks_datatable.rb
|
182
184
|
- app/datatables/effective_log_changes_datatable.rb
|
183
185
|
- app/datatables/effective_logs_datatable.rb
|
184
186
|
- app/helpers/effective_logging_helper.rb
|
185
187
|
- app/models/concerns/acts_as_loggable.rb
|
188
|
+
- app/models/concerns/acts_as_trackable.rb
|
186
189
|
- app/models/concerns/effective_logging_log.rb
|
187
190
|
- app/models/effective/log.rb
|
191
|
+
- app/models/effective/track.rb
|
188
192
|
- app/models/effective_logger.rb
|
189
193
|
- app/views/admin/logs/_layout.html.haml
|
190
194
|
- app/views/admin/logs/index.html.haml
|