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.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/GETTING-STARTED.md +1 -0
  4. data/docker-compose.yml +27 -0
  5. data/docs/CHANGELOG_md.html +318 -0
  6. data/docs/CHEAT_SHEET_md.html +168 -0
  7. data/docs/CODE_OF_CONDUCT_md.html +250 -0
  8. data/docs/CreateLoggableActivities.html +175 -0
  9. data/docs/CreateLoggableActivityTables.html +173 -0
  10. data/docs/GETTING-STARTED_md.html +211 -0
  11. data/docs/Gemfile.html +153 -0
  12. data/docs/Gemfile_lock.html +438 -0
  13. data/docs/LoggableActivity/ActivitiesController.html +160 -0
  14. data/docs/LoggableActivity/ActivitiesHelper.html +158 -0
  15. data/docs/LoggableActivity/Activity.html +565 -0
  16. data/docs/LoggableActivity/ApplicationController.html +97 -0
  17. data/docs/LoggableActivity/ApplicationHelper.html +91 -0
  18. data/docs/LoggableActivity/ApplicationJob.html +97 -0
  19. data/docs/LoggableActivity/ApplicationMailer.html +97 -0
  20. data/docs/LoggableActivity/ApplicationRecord.html +97 -0
  21. data/docs/LoggableActivity/Configuration.html +237 -0
  22. data/docs/LoggableActivity/ConfigurationError.html +142 -0
  23. data/docs/LoggableActivity/CurrentActor.html +166 -0
  24. data/docs/LoggableActivity/DataOwner.html +138 -0
  25. data/docs/LoggableActivity/Encryption.html +321 -0
  26. data/docs/LoggableActivity/EncryptionError.html +142 -0
  27. data/docs/LoggableActivity/EncryptionKey.html +399 -0
  28. data/docs/LoggableActivity/Engine.html +108 -0
  29. data/docs/LoggableActivity/Error.html +142 -0
  30. data/docs/LoggableActivity/Generators/InstallGenerator.html +212 -0
  31. data/docs/LoggableActivity/Generators.html +91 -0
  32. data/docs/LoggableActivity/Hooks.html +841 -0
  33. data/docs/LoggableActivity/Payload.html +430 -0
  34. data/docs/LoggableActivity/Sanitizer.html +134 -0
  35. data/docs/LoggableActivity/Services/BasePayloadsBuilder.html +472 -0
  36. data/docs/LoggableActivity/Services/CustomPayloadsBuilder.html +225 -0
  37. data/docs/LoggableActivity/Services/DestroyPayloadsBuilder.html +396 -0
  38. data/docs/LoggableActivity/Services/PayloadsBuilder.html +348 -0
  39. data/docs/LoggableActivity/Services/UpdatePayloadsBuilder.html +540 -0
  40. data/docs/LoggableActivity/Services.html +93 -0
  41. data/docs/LoggableActivity.html +173 -0
  42. data/docs/MIT-LICENSE.html +132 -0
  43. data/docs/Object.html +110 -0
  44. data/docs/README_md.html +186 -0
  45. data/docs/Rakefile.html +134 -0
  46. data/docs/app/assets/config/loggable_activity_manifest_js.html +126 -0
  47. data/docs/app/assets/javascripts/loggable_activity/application_js.html +124 -0
  48. data/docs/app/assets/stylesheets/loggable_activity/activities_scss.html +154 -0
  49. data/docs/app/assets/stylesheets/loggable_activity/application_scss.html +142 -0
  50. data/docs/app/views/layouts/loggable_activity/application_html_slim.html +145 -0
  51. data/docs/app/views/loggable_activity/activities/_activities_html_slim.html +159 -0
  52. data/docs/created.rid +74 -0
  53. data/docs/css/fonts.css +167 -0
  54. data/docs/css/rdoc.css +687 -0
  55. data/docs/fonts/Lato-Light.ttf +0 -0
  56. data/docs/fonts/Lato-LightItalic.ttf +0 -0
  57. data/docs/fonts/Lato-Regular.ttf +0 -0
  58. data/docs/fonts/Lato-RegularItalic.ttf +0 -0
  59. data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
  60. data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
  61. data/docs/git-org/HEAD.html +126 -0
  62. data/docs/git-org/config.html +128 -0
  63. data/docs/git-org/description.html +126 -0
  64. data/docs/git-org/hooks/applypatch-msg_sample.html +128 -0
  65. data/docs/git-org/hooks/commit-msg_sample.html +138 -0
  66. data/docs/git-org/hooks/fsmonitor-watchman_sample.html +302 -0
  67. data/docs/git-org/hooks/post-update_sample.html +128 -0
  68. data/docs/git-org/hooks/pre-applypatch_sample.html +128 -0
  69. data/docs/git-org/hooks/pre-commit_sample.html +174 -0
  70. data/docs/git-org/hooks/pre-merge-commit_sample.html +133 -0
  71. data/docs/git-org/hooks/pre-push_sample.html +161 -0
  72. data/docs/git-org/hooks/pre-rebase_sample.html +282 -0
  73. data/docs/git-org/hooks/pre-receive_sample.html +144 -0
  74. data/docs/git-org/hooks/prepare-commit-msg_sample.html +136 -0
  75. data/docs/git-org/hooks/push-to-checkout_sample.html +178 -0
  76. data/docs/git-org/hooks/update_sample.html +226 -0
  77. data/docs/git-org/info/exclude.html +126 -0
  78. data/docs/images/add.png +0 -0
  79. data/docs/images/arrow_up.png +0 -0
  80. data/docs/images/brick.png +0 -0
  81. data/docs/images/brick_link.png +0 -0
  82. data/docs/images/bug.png +0 -0
  83. data/docs/images/bullet_black.png +0 -0
  84. data/docs/images/bullet_toggle_minus.png +0 -0
  85. data/docs/images/bullet_toggle_plus.png +0 -0
  86. data/docs/images/date.png +0 -0
  87. data/docs/images/delete.png +0 -0
  88. data/docs/images/find.png +0 -0
  89. data/docs/images/loadingAnimation.gif +0 -0
  90. data/docs/images/macFFBgHack.png +0 -0
  91. data/docs/images/package.png +0 -0
  92. data/docs/images/page_green.png +0 -0
  93. data/docs/images/page_white_text.png +0 -0
  94. data/docs/images/page_white_width.png +0 -0
  95. data/docs/images/plugin.png +0 -0
  96. data/docs/images/ruby.png +0 -0
  97. data/docs/images/tag_blue.png +0 -0
  98. data/docs/images/tag_green.png +0 -0
  99. data/docs/images/transparent.png +0 -0
  100. data/docs/images/wrench.png +0 -0
  101. data/docs/images/wrench_orange.png +0 -0
  102. data/docs/images/zoom.png +0 -0
  103. data/docs/index.html +166 -0
  104. data/docs/js/darkfish.js +97 -0
  105. data/docs/js/navigation.js +105 -0
  106. data/docs/js/navigation.js.gz +0 -0
  107. data/docs/js/search.js +110 -0
  108. data/docs/js/search_index.js +1 -0
  109. data/docs/js/search_index.js.gz +0 -0
  110. data/docs/js/searcher.js +229 -0
  111. data/docs/js/searcher.js.gz +0 -0
  112. data/docs/lib/loggable_activity/config_schema_json.html +205 -0
  113. data/docs/lib/tasks/loggable_activity_tasks_rake.html +128 -0
  114. data/docs/table_of_contents.html +954 -0
  115. data/lib/loggable_activity/concerns/current_actor.rb +25 -0
  116. data/lib/loggable_activity/hooks.rb +41 -19
  117. data/lib/loggable_activity/version.rb +1 -1
  118. data/lib/loggable_activity.rb +1 -1
  119. metadata +114 -3
  120. 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
- raise LoggableActivity::Error, "Configuration not found for #{name}, Please add it to 'config/loggable_activity.yaml"
23
- end
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[:current_user] || created_by_self
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, :show
54
- log_activity
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
- # If the actor is the same as the record, it is created by the actor.
77
- # This assumes it is a sign_up action.
78
- def created_by_self
79
- return unless LoggableActivity.actor_model_name == self.class.name
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
- @action = :sign_up
82
- self
83
+ log_activity
83
84
  end
84
85
 
85
- # Logs an activity for the current action.
86
- def log_activity
87
- create_activity(build_payloads)
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)
@@ -3,5 +3,5 @@
3
3
  # Version of the gem
4
4
  module LoggableActivity
5
5
  # Version
6
- VERSION = '0.5.6'
6
+ VERSION = '0.5.7'
7
7
  end
@@ -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/current_user'
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.6
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-18 00:00:00.000000000 Z
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/current_user.rb
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