activitylog 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/activitylog.gemspec +3 -2
- data/lib/activity_log/controller_activity_logger.rb +24 -0
- data/lib/activity_log/model_activity_logger.rb +19 -0
- data/lib/activitylog.rb +2 -2
- metadata +3 -2
- data/lib/activity_log/activity_logger.rb +0 -41
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDg3OGU1NGY0OTQ0NTk1ZWFiMjNkNjJlYTJkMDQ3ZGRkMWEyYjQ1ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2UxOWNmNmIyMGNiMjY2NTg3MGMxYTM1YzNhNDFkZmQxYTkxNTgyMg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzMyOGQ0ZDdkZTE4NzNiMGRlZGQ0M2M5NTQ1Y2FiYzc3ZjQ3NjJlODFiOWZi
|
10
|
+
MWIxNTYyMzEwZmJkYjQ0OWJjZjliYzJlOWU1NDZlMTU5YmZjYjM1ZGM4Mzhi
|
11
|
+
Zjg5NTA1MDg5NTdkYjM4ZjRlYmY1Y2FlMjQwMmQ0NmZjMDAxM2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGUyMWIwMmVhNjQ1ODQ1NTMxYTU4NDkxNmFiNTMyZGFkMzQ5YzMxMDRjYTQ4
|
14
|
+
MDEwMTcxMmRlZmU5NGU4Njk1MzliNjJkMjRlMzlhN2U0MmQ4NDE4MzMyYTg4
|
15
|
+
OTQ1NjUzNGY3MDJhMDdjNDEyZjYwZGE5MGRhYjYwZjUwMDZmMzg=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/activitylog.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "activitylog"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jon Erik Suero", "Elan Dubrofsky"]
|
@@ -27,7 +27,8 @@ Gem::Specification.new do |s|
|
|
27
27
|
"activitylog.gemspec",
|
28
28
|
"init.rb",
|
29
29
|
"lib/activity_log/activity_log.rb",
|
30
|
-
"lib/activity_log/
|
30
|
+
"lib/activity_log/controller_activity_logger.rb",
|
31
|
+
"lib/activity_log/model_activity_logger.rb",
|
31
32
|
"lib/activitylog.rb",
|
32
33
|
"lib/generators/activity_log/activity_log_generator.rb",
|
33
34
|
"lib/generators/activity_log/templates/create_activity_logs.rb",
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ControllerActivityLogger
|
2
|
+
include ModelActivityLogger
|
3
|
+
|
4
|
+
def clear_parent_activity_id
|
5
|
+
ModelActivityLogger.current_parent_activity_id = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def record_activity_log
|
9
|
+
return unless params[:id].present?
|
10
|
+
return if request.get? #exit if it's a get
|
11
|
+
object = controller_name.classify.constantize.find_by_id(params[:id])
|
12
|
+
return unless object.present?
|
13
|
+
return unless object.respond_to? :activity_logs
|
14
|
+
ModelActivityLogger.current_parent_activity_id = object.activity_logs.create(user_id: current_user.try(:id), action: "#{params[:controller]}/#{params[:action]}", data: params, action_type: 'controller').id
|
15
|
+
end
|
16
|
+
|
17
|
+
# CLASS METHODS (self.)
|
18
|
+
module ClassMethods
|
19
|
+
def log_activity(options = {})
|
20
|
+
send :before_filter, :record_controller_activity_log, options
|
21
|
+
send :after_filter, :clear_parent_activity_id, options
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ModelActivityLogger
|
2
|
+
|
3
|
+
mattr_accessor :current_parent_activity_id
|
4
|
+
|
5
|
+
def record_activity_log(action)
|
6
|
+
# if current_user_id == nil, then the User is in the process of Logging In
|
7
|
+
current_id = defined?(current_user_id) ? current_user_id : nil
|
8
|
+
activity_logs.create user_id: current_id, action: action, data: changes, action_type: 'model', parent_activity_id: current_parent_activity_id
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def log_activity
|
13
|
+
self.has_many :activity_logs, as: :loggable
|
14
|
+
self.after_create {record_activity_log("create")}
|
15
|
+
self.after_update {record_activity_log("update")}
|
16
|
+
self.before_destroy {record_activity_log("destroy")}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/activitylog.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
require 'activity_log/activity_log'
|
2
2
|
require 'activity_log/activity_logger.rb'
|
3
|
-
ActiveRecord::Base.send(:include,
|
4
|
-
ActionController::Base.send(:include,
|
3
|
+
ActiveRecord::Base.send(:include, ModelActivityLogger)
|
4
|
+
ActionController::Base.send(:include, ControllerActivityLogger)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activitylog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Erik Suero
|
@@ -71,7 +71,8 @@ files:
|
|
71
71
|
- activitylog.gemspec
|
72
72
|
- init.rb
|
73
73
|
- lib/activity_log/activity_log.rb
|
74
|
-
- lib/activity_log/
|
74
|
+
- lib/activity_log/controller_activity_logger.rb
|
75
|
+
- lib/activity_log/model_activity_logger.rb
|
75
76
|
- lib/activitylog.rb
|
76
77
|
- lib/generators/activity_log/activity_log_generator.rb
|
77
78
|
- lib/generators/activity_log/templates/create_activity_logs.rb
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module ActivityLogger
|
2
|
-
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
mattr_accessor :stored_parent_activity_id
|
6
|
-
|
7
|
-
# INSTANCE METHODS
|
8
|
-
def clear_parent_activity_id
|
9
|
-
self.stored_parent_activity_id = nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def record_model_activity_log(action)
|
13
|
-
# if current_user_id == nil, then the User is in the process of Logging In
|
14
|
-
current_id = defined?(current_user_id) ? current_user_id : nil
|
15
|
-
activity_logs.create user_id: current_id, action: action, data: changes, action_type: 'model', stored_parent_activity_id: self.stored_parent_activity_id
|
16
|
-
end
|
17
|
-
|
18
|
-
def record_controller_activity_log
|
19
|
-
return unless params[:id].present?
|
20
|
-
return if request.get? #exit if it's a get
|
21
|
-
object = controller_name.classify.constantize.find_by_id(params[:id])
|
22
|
-
return unless object.present?
|
23
|
-
return unless object.respond_to? :activity_logs
|
24
|
-
self.stored_parent_activity_id = object.activity_logs.create(user_id: current_user.try(:id), action: "#{params[:controller]}/#{params[:action]}", data: params, action_type: 'controller').id
|
25
|
-
end
|
26
|
-
|
27
|
-
# CLASS METHODS (self.)
|
28
|
-
module ClassMethods
|
29
|
-
def log_model_activity
|
30
|
-
self.has_many :activity_logs, as: :loggable
|
31
|
-
self.after_create {record_model_activity_log("create")}
|
32
|
-
self.after_update {record_model_activity_log("update")}
|
33
|
-
self.before_destroy {record_model_activity_log("destroy")}
|
34
|
-
end
|
35
|
-
|
36
|
-
def log_controller_activity(options = {})
|
37
|
-
send :before_filter, :record_controller_activity_log, options
|
38
|
-
send :after_filter, :clear_parent_activity_id, options
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|