loggable_activity 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/GETTING-STARTED.md +1 -0
- data/docker-compose.yml +27 -0
- data/docs/CHANGELOG_md.html +318 -0
- data/docs/CHEAT_SHEET_md.html +168 -0
- data/docs/CODE_OF_CONDUCT_md.html +250 -0
- data/docs/CreateLoggableActivities.html +175 -0
- data/docs/CreateLoggableActivityTables.html +173 -0
- data/docs/GETTING-STARTED_md.html +211 -0
- data/docs/Gemfile.html +153 -0
- data/docs/Gemfile_lock.html +438 -0
- data/docs/LoggableActivity/ActivitiesController.html +160 -0
- data/docs/LoggableActivity/ActivitiesHelper.html +158 -0
- data/docs/LoggableActivity/Activity.html +565 -0
- data/docs/LoggableActivity/ApplicationController.html +97 -0
- data/docs/LoggableActivity/ApplicationHelper.html +91 -0
- data/docs/LoggableActivity/ApplicationJob.html +97 -0
- data/docs/LoggableActivity/ApplicationMailer.html +97 -0
- data/docs/LoggableActivity/ApplicationRecord.html +97 -0
- data/docs/LoggableActivity/Configuration.html +237 -0
- data/docs/LoggableActivity/ConfigurationError.html +142 -0
- data/docs/LoggableActivity/CurrentActor.html +166 -0
- data/docs/LoggableActivity/DataOwner.html +138 -0
- data/docs/LoggableActivity/Encryption.html +321 -0
- data/docs/LoggableActivity/EncryptionError.html +142 -0
- data/docs/LoggableActivity/EncryptionKey.html +399 -0
- data/docs/LoggableActivity/Engine.html +108 -0
- data/docs/LoggableActivity/Error.html +142 -0
- data/docs/LoggableActivity/Generators/InstallGenerator.html +212 -0
- data/docs/LoggableActivity/Generators.html +91 -0
- data/docs/LoggableActivity/Hooks.html +841 -0
- data/docs/LoggableActivity/Payload.html +430 -0
- data/docs/LoggableActivity/Sanitizer.html +134 -0
- data/docs/LoggableActivity/Services/BasePayloadsBuilder.html +472 -0
- data/docs/LoggableActivity/Services/CustomPayloadsBuilder.html +225 -0
- data/docs/LoggableActivity/Services/DestroyPayloadsBuilder.html +396 -0
- data/docs/LoggableActivity/Services/PayloadsBuilder.html +348 -0
- data/docs/LoggableActivity/Services/UpdatePayloadsBuilder.html +540 -0
- data/docs/LoggableActivity/Services.html +93 -0
- data/docs/LoggableActivity.html +173 -0
- data/docs/MIT-LICENSE.html +132 -0
- data/docs/Object.html +110 -0
- data/docs/README_md.html +186 -0
- data/docs/Rakefile.html +134 -0
- data/docs/app/assets/config/loggable_activity_manifest_js.html +126 -0
- data/docs/app/assets/javascripts/loggable_activity/application_js.html +124 -0
- data/docs/app/assets/stylesheets/loggable_activity/activities_scss.html +154 -0
- data/docs/app/assets/stylesheets/loggable_activity/application_scss.html +142 -0
- data/docs/app/views/layouts/loggable_activity/application_html_slim.html +145 -0
- data/docs/app/views/loggable_activity/activities/_activities_html_slim.html +159 -0
- data/docs/created.rid +74 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +687 -0
- data/docs/fonts/Lato-Light.ttf +0 -0
- data/docs/fonts/Lato-LightItalic.ttf +0 -0
- data/docs/fonts/Lato-Regular.ttf +0 -0
- data/docs/fonts/Lato-RegularItalic.ttf +0 -0
- data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
- data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
- data/docs/git-org/HEAD.html +126 -0
- data/docs/git-org/config.html +128 -0
- data/docs/git-org/description.html +126 -0
- data/docs/git-org/hooks/applypatch-msg_sample.html +128 -0
- data/docs/git-org/hooks/commit-msg_sample.html +138 -0
- data/docs/git-org/hooks/fsmonitor-watchman_sample.html +302 -0
- data/docs/git-org/hooks/post-update_sample.html +128 -0
- data/docs/git-org/hooks/pre-applypatch_sample.html +128 -0
- data/docs/git-org/hooks/pre-commit_sample.html +174 -0
- data/docs/git-org/hooks/pre-merge-commit_sample.html +133 -0
- data/docs/git-org/hooks/pre-push_sample.html +161 -0
- data/docs/git-org/hooks/pre-rebase_sample.html +282 -0
- data/docs/git-org/hooks/pre-receive_sample.html +144 -0
- data/docs/git-org/hooks/prepare-commit-msg_sample.html +136 -0
- data/docs/git-org/hooks/push-to-checkout_sample.html +178 -0
- data/docs/git-org/hooks/update_sample.html +226 -0
- data/docs/git-org/info/exclude.html +126 -0
- data/docs/images/add.png +0 -0
- data/docs/images/arrow_up.png +0 -0
- data/docs/images/brick.png +0 -0
- data/docs/images/brick_link.png +0 -0
- data/docs/images/bug.png +0 -0
- data/docs/images/bullet_black.png +0 -0
- data/docs/images/bullet_toggle_minus.png +0 -0
- data/docs/images/bullet_toggle_plus.png +0 -0
- data/docs/images/date.png +0 -0
- data/docs/images/delete.png +0 -0
- data/docs/images/find.png +0 -0
- data/docs/images/loadingAnimation.gif +0 -0
- data/docs/images/macFFBgHack.png +0 -0
- data/docs/images/package.png +0 -0
- data/docs/images/page_green.png +0 -0
- data/docs/images/page_white_text.png +0 -0
- data/docs/images/page_white_width.png +0 -0
- data/docs/images/plugin.png +0 -0
- data/docs/images/ruby.png +0 -0
- data/docs/images/tag_blue.png +0 -0
- data/docs/images/tag_green.png +0 -0
- data/docs/images/transparent.png +0 -0
- data/docs/images/wrench.png +0 -0
- data/docs/images/wrench_orange.png +0 -0
- data/docs/images/zoom.png +0 -0
- data/docs/index.html +166 -0
- data/docs/js/darkfish.js +97 -0
- data/docs/js/navigation.js +105 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +110 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js +229 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/lib/loggable_activity/config_schema_json.html +205 -0
- data/docs/lib/tasks/loggable_activity_tasks_rake.html +128 -0
- data/docs/table_of_contents.html +954 -0
- data/lib/loggable_activity/concerns/current_actor.rb +25 -0
- data/lib/loggable_activity/hooks.rb +41 -19
- data/lib/loggable_activity/version.rb +1 -1
- data/lib/loggable_activity.rb +1 -1
- metadata +114 -3
- data/lib/loggable_activity/concerns/current_user.rb +0 -26
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LoggableActivity
|
4
|
+
# Stores current user in a thread variable so is can be accessed from the LoggableActivity::Hook model
|
5
|
+
module CurrentActor
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
before_action :set_current_actor
|
10
|
+
after_action :clear_current_actor
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def set_current_actor
|
16
|
+
return unless current_user
|
17
|
+
|
18
|
+
Thread.current[:current_actor] = current_user
|
19
|
+
end
|
20
|
+
|
21
|
+
def clear_current_actor
|
22
|
+
Thread.current[:current_actor] = nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -18,17 +18,17 @@ module LoggableActivity
|
|
18
18
|
included do
|
19
19
|
config = ::LoggableActivity::Configuration.for_class(name)
|
20
20
|
|
21
|
-
if config.nil?
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
# if config.nil?
|
22
|
+
# # logg all attributes by default.
|
23
|
+
# self.loggable_attrs = attribute_names
|
24
|
+
# end
|
25
25
|
# Initializes attributes based on configuration.
|
26
|
-
self.loggable_attrs = config&.fetch('loggable_attrs', []) ||
|
26
|
+
self.loggable_attrs = config&.fetch('loggable_attrs', []) || attribute_names
|
27
27
|
self.public_attrs = config&.fetch('public_attrs', []) || []
|
28
28
|
self.relations = config&.fetch('relations', []) || []
|
29
|
-
self.auto_log = config&.fetch('auto_log', []) || []
|
30
|
-
self.fetch_record_name_from = config&.fetch('fetch_record_name_from', nil)
|
29
|
+
self.auto_log = config&.fetch('auto_log', []) || %w[create update destroy]
|
31
30
|
self.route = config&.fetch('route', nil)
|
31
|
+
self.fetch_record_name_from = config&.fetch('fetch_record_name_from', nil)
|
32
32
|
|
33
33
|
after_create :log_create_activity
|
34
34
|
after_update :log_update_activity
|
@@ -42,7 +42,7 @@ module LoggableActivity
|
|
42
42
|
# @param params [Hash] Additional parameters for the activity.
|
43
43
|
def log(action, actor: nil, params: {})
|
44
44
|
@action = action
|
45
|
-
@actor = actor || Thread.current[:
|
45
|
+
@actor = actor || Thread.current[:current_actor]
|
46
46
|
return nil if @actor.nil?
|
47
47
|
|
48
48
|
@record = self
|
@@ -50,8 +50,10 @@ module LoggableActivity
|
|
50
50
|
@payloads = []
|
51
51
|
|
52
52
|
case action
|
53
|
-
when :create
|
54
|
-
|
53
|
+
when :create
|
54
|
+
log_create
|
55
|
+
when :show
|
56
|
+
log_show
|
55
57
|
when :destroy
|
56
58
|
log_destroy
|
57
59
|
when :update
|
@@ -73,18 +75,17 @@ module LoggableActivity
|
|
73
75
|
|
74
76
|
private
|
75
77
|
|
76
|
-
#
|
77
|
-
|
78
|
-
|
79
|
-
return
|
78
|
+
# Logs an activity for the show action.
|
79
|
+
def log_show
|
80
|
+
return nil if just_created?
|
81
|
+
return nil if just_updated?
|
80
82
|
|
81
|
-
|
82
|
-
self
|
83
|
+
log_activity
|
83
84
|
end
|
84
85
|
|
85
|
-
# Logs an activity for the
|
86
|
-
def
|
87
|
-
|
86
|
+
# Logs an activity for the create action.
|
87
|
+
def log_create
|
88
|
+
log_activity
|
88
89
|
end
|
89
90
|
|
90
91
|
# Logs an activity for the update action.
|
@@ -97,6 +98,27 @@ module LoggableActivity
|
|
97
98
|
create_activity(build_destroy_payload)
|
98
99
|
end
|
99
100
|
|
101
|
+
# Logs an activity for the current action.
|
102
|
+
def log_activity
|
103
|
+
create_activity(build_payloads)
|
104
|
+
end
|
105
|
+
|
106
|
+
def just_created?
|
107
|
+
action = "#{self.class.base_action}.create"
|
108
|
+
activity = LoggableActivity::Activity.where(record: self, actor: @actor).last
|
109
|
+
return false unless activity && activity.action == action && activity.created_at > 5.seconds.ago
|
110
|
+
|
111
|
+
true
|
112
|
+
end
|
113
|
+
|
114
|
+
def just_updated?
|
115
|
+
action = "#{self.class.base_action}.update"
|
116
|
+
activity = LoggableActivity::Activity.where(record: self, actor: @actor).last
|
117
|
+
return false unless activity && activity.action == action && activity.created_at > 5.seconds.ago
|
118
|
+
|
119
|
+
true
|
120
|
+
end
|
121
|
+
|
100
122
|
# Creates an activity with the specified payloads.
|
101
123
|
def create_activity(payloads)
|
102
124
|
return nil if nothing_to_log?(payloads)
|
data/lib/loggable_activity.rb
CHANGED
@@ -16,7 +16,7 @@ require 'loggable_activity/services/custom_payloads_builder'
|
|
16
16
|
require 'loggable_activity/services/payloads_builder'
|
17
17
|
require 'loggable_activity/services/update_payloads_builder'
|
18
18
|
require 'loggable_activity/services/destroy_payloads_builder'
|
19
|
-
require 'loggable_activity/concerns/
|
19
|
+
require 'loggable_activity/concerns/current_actor'
|
20
20
|
require 'kaminari'
|
21
21
|
|
22
22
|
# LoggableActivity
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loggable_activity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Groenlund
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -174,6 +174,117 @@ files:
|
|
174
174
|
- config/initializers/kaminari_config.rb
|
175
175
|
- config/routes.rb
|
176
176
|
- db/migrate/20240702092648_create_loggable_activity_tables.rb
|
177
|
+
- docker-compose.yml
|
178
|
+
- docs/CHANGELOG_md.html
|
179
|
+
- docs/CHEAT_SHEET_md.html
|
180
|
+
- docs/CODE_OF_CONDUCT_md.html
|
181
|
+
- docs/CreateLoggableActivities.html
|
182
|
+
- docs/CreateLoggableActivityTables.html
|
183
|
+
- docs/GETTING-STARTED_md.html
|
184
|
+
- docs/Gemfile.html
|
185
|
+
- docs/Gemfile_lock.html
|
186
|
+
- docs/LoggableActivity.html
|
187
|
+
- docs/LoggableActivity/ActivitiesController.html
|
188
|
+
- docs/LoggableActivity/ActivitiesHelper.html
|
189
|
+
- docs/LoggableActivity/Activity.html
|
190
|
+
- docs/LoggableActivity/ApplicationController.html
|
191
|
+
- docs/LoggableActivity/ApplicationHelper.html
|
192
|
+
- docs/LoggableActivity/ApplicationJob.html
|
193
|
+
- docs/LoggableActivity/ApplicationMailer.html
|
194
|
+
- docs/LoggableActivity/ApplicationRecord.html
|
195
|
+
- docs/LoggableActivity/Configuration.html
|
196
|
+
- docs/LoggableActivity/ConfigurationError.html
|
197
|
+
- docs/LoggableActivity/CurrentActor.html
|
198
|
+
- docs/LoggableActivity/DataOwner.html
|
199
|
+
- docs/LoggableActivity/Encryption.html
|
200
|
+
- docs/LoggableActivity/EncryptionError.html
|
201
|
+
- docs/LoggableActivity/EncryptionKey.html
|
202
|
+
- docs/LoggableActivity/Engine.html
|
203
|
+
- docs/LoggableActivity/Error.html
|
204
|
+
- docs/LoggableActivity/Generators.html
|
205
|
+
- docs/LoggableActivity/Generators/InstallGenerator.html
|
206
|
+
- docs/LoggableActivity/Hooks.html
|
207
|
+
- docs/LoggableActivity/Payload.html
|
208
|
+
- docs/LoggableActivity/Sanitizer.html
|
209
|
+
- docs/LoggableActivity/Services.html
|
210
|
+
- docs/LoggableActivity/Services/BasePayloadsBuilder.html
|
211
|
+
- docs/LoggableActivity/Services/CustomPayloadsBuilder.html
|
212
|
+
- docs/LoggableActivity/Services/DestroyPayloadsBuilder.html
|
213
|
+
- docs/LoggableActivity/Services/PayloadsBuilder.html
|
214
|
+
- docs/LoggableActivity/Services/UpdatePayloadsBuilder.html
|
215
|
+
- docs/MIT-LICENSE.html
|
216
|
+
- docs/Object.html
|
217
|
+
- docs/README_md.html
|
218
|
+
- docs/Rakefile.html
|
219
|
+
- docs/app/assets/config/loggable_activity_manifest_js.html
|
220
|
+
- docs/app/assets/javascripts/loggable_activity/application_js.html
|
221
|
+
- docs/app/assets/stylesheets/loggable_activity/activities_scss.html
|
222
|
+
- docs/app/assets/stylesheets/loggable_activity/application_scss.html
|
223
|
+
- docs/app/views/layouts/loggable_activity/application_html_slim.html
|
224
|
+
- docs/app/views/loggable_activity/activities/_activities_html_slim.html
|
225
|
+
- docs/created.rid
|
226
|
+
- docs/css/fonts.css
|
227
|
+
- docs/css/rdoc.css
|
228
|
+
- docs/fonts/Lato-Light.ttf
|
229
|
+
- docs/fonts/Lato-LightItalic.ttf
|
230
|
+
- docs/fonts/Lato-Regular.ttf
|
231
|
+
- docs/fonts/Lato-RegularItalic.ttf
|
232
|
+
- docs/fonts/SourceCodePro-Bold.ttf
|
233
|
+
- docs/fonts/SourceCodePro-Regular.ttf
|
234
|
+
- docs/git-org/HEAD.html
|
235
|
+
- docs/git-org/config.html
|
236
|
+
- docs/git-org/description.html
|
237
|
+
- docs/git-org/hooks/applypatch-msg_sample.html
|
238
|
+
- docs/git-org/hooks/commit-msg_sample.html
|
239
|
+
- docs/git-org/hooks/fsmonitor-watchman_sample.html
|
240
|
+
- docs/git-org/hooks/post-update_sample.html
|
241
|
+
- docs/git-org/hooks/pre-applypatch_sample.html
|
242
|
+
- docs/git-org/hooks/pre-commit_sample.html
|
243
|
+
- docs/git-org/hooks/pre-merge-commit_sample.html
|
244
|
+
- docs/git-org/hooks/pre-push_sample.html
|
245
|
+
- docs/git-org/hooks/pre-rebase_sample.html
|
246
|
+
- docs/git-org/hooks/pre-receive_sample.html
|
247
|
+
- docs/git-org/hooks/prepare-commit-msg_sample.html
|
248
|
+
- docs/git-org/hooks/push-to-checkout_sample.html
|
249
|
+
- docs/git-org/hooks/update_sample.html
|
250
|
+
- docs/git-org/info/exclude.html
|
251
|
+
- docs/images/add.png
|
252
|
+
- docs/images/arrow_up.png
|
253
|
+
- docs/images/brick.png
|
254
|
+
- docs/images/brick_link.png
|
255
|
+
- docs/images/bug.png
|
256
|
+
- docs/images/bullet_black.png
|
257
|
+
- docs/images/bullet_toggle_minus.png
|
258
|
+
- docs/images/bullet_toggle_plus.png
|
259
|
+
- docs/images/date.png
|
260
|
+
- docs/images/delete.png
|
261
|
+
- docs/images/find.png
|
262
|
+
- docs/images/loadingAnimation.gif
|
263
|
+
- docs/images/macFFBgHack.png
|
264
|
+
- docs/images/package.png
|
265
|
+
- docs/images/page_green.png
|
266
|
+
- docs/images/page_white_text.png
|
267
|
+
- docs/images/page_white_width.png
|
268
|
+
- docs/images/plugin.png
|
269
|
+
- docs/images/ruby.png
|
270
|
+
- docs/images/tag_blue.png
|
271
|
+
- docs/images/tag_green.png
|
272
|
+
- docs/images/transparent.png
|
273
|
+
- docs/images/wrench.png
|
274
|
+
- docs/images/wrench_orange.png
|
275
|
+
- docs/images/zoom.png
|
276
|
+
- docs/index.html
|
277
|
+
- docs/js/darkfish.js
|
278
|
+
- docs/js/navigation.js
|
279
|
+
- docs/js/navigation.js.gz
|
280
|
+
- docs/js/search.js
|
281
|
+
- docs/js/search_index.js
|
282
|
+
- docs/js/search_index.js.gz
|
283
|
+
- docs/js/searcher.js
|
284
|
+
- docs/js/searcher.js.gz
|
285
|
+
- docs/lib/loggable_activity/config_schema_json.html
|
286
|
+
- docs/lib/tasks/loggable_activity_tasks_rake.html
|
287
|
+
- docs/table_of_contents.html
|
177
288
|
- git-org/HEAD
|
178
289
|
- git-org/config
|
179
290
|
- git-org/description
|
@@ -199,7 +310,7 @@ files:
|
|
199
310
|
- lib/loggable_activity.rb
|
200
311
|
- lib/loggable_activity/.DS_Store
|
201
312
|
- lib/loggable_activity/activity.rb
|
202
|
-
- lib/loggable_activity/concerns/
|
313
|
+
- lib/loggable_activity/concerns/current_actor.rb
|
203
314
|
- lib/loggable_activity/config_schema.json
|
204
315
|
- lib/loggable_activity/configuration.rb
|
205
316
|
- lib/loggable_activity/data_owner.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module LoggableActivity
|
4
|
-
# Stores current user in a thread variable so is can be accessed from the LoggableActivity::Hook model
|
5
|
-
module CurrentUser
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
before_action :set_current_user
|
10
|
-
after_action :clear_current_user
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def set_current_user
|
16
|
-
# return if request.path == "/users/sign_out"
|
17
|
-
return unless current_user
|
18
|
-
|
19
|
-
Thread.current[:current_user] = current_user
|
20
|
-
end
|
21
|
-
|
22
|
-
def clear_current_user
|
23
|
-
Thread.current[:current_user] = nil
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|