velocity_audited 5.1.4 → 6.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 442ee1a7c413fc26e6ddd02cfb1d1201fb5034cb19f54f5607d5ed0f04328012
4
- data.tar.gz: 456faa3bd554bcd65ef6277caf785f283456d3683e54d70067ec75380f618bff
3
+ metadata.gz: 7b39436e9380cd8f81939d01bd864c669d65bb033ef97d7c265165160e52809c
4
+ data.tar.gz: 761804b094627fcb2b13e991ec8eb66288f1761d3d9ba4b134811d3ed399b3b8
5
5
  SHA512:
6
- metadata.gz: bcb4961726f31f2af54ab96f3501fdc5cc1406c257c9eeb8d985d99e37f60c19112dbd366e46793b29589dd07900be3e16caf23da71f8f330f53cc4ab79c0b05
7
- data.tar.gz: b099ebb6947568e53c37799057f2e39794a13674e5ef712b4c31e6c30a1727fe7c64db7ad25135e9068daa29fd97ec4215c8a0c0673785829964710d36ad58b3
6
+ metadata.gz: ebd15ee11f7c91d2beb3c61db75d6a6c8a3795c8615423d9c9ad9ed9294d321ad5439427adba2a45238318d4e79fa1183a5401250d62ed945b36ee25f03091b6
7
+ data.tar.gz: 0621c54999850e9a6cd4cbe12642cc1e99ea0e367119aba2a503009f290ea5cc99374dab67d34e2e8c9007a4f51ee660c5429c6607ecc3917fa5bb3260f16bdf
data/README.md CHANGED
@@ -42,10 +42,10 @@ gem "audited", "~> 5.0"
42
42
  And if you're using ```require: false``` you must add initializers like this:
43
43
 
44
44
  ```ruby
45
- #./config/initializers/audited.rb
46
- require "audited"
45
+ #./config/initializers/velocity_audited.rb
46
+ require "velocity_audited"
47
47
 
48
- Audited::Railtie.initializers.each(&:run)
48
+ VelocityAudited::Railtie.initializers.each(&:run)
49
49
  ```
50
50
 
51
51
  Then, from your Rails app directory, create the `audits` table:
@@ -174,7 +174,7 @@ end
174
174
  You can limit the number of audits stored for your model. To configure limiting for all audited models, put the following in an initializer file (`config/initializers/audited.rb`):
175
175
 
176
176
  ```ruby
177
- Audited.max_audits = 10 # keep only 10 latest audits
177
+ VelocityAudited.max_audits = 10 # keep only 10 latest audits
178
178
  ```
179
179
 
180
180
  or customize per model:
@@ -213,13 +213,13 @@ end
213
213
  To use a method other than `current_user`, put the following in an initializer file (`config/initializers/audited.rb`):
214
214
 
215
215
  ```ruby
216
- Audited.current_user_method = :authenticated_user
216
+ VelocityAudited.current_user_method = :authenticated_user
217
217
  ```
218
218
 
219
219
  Outside of a request, Audited can still record the user with the `as_user` method:
220
220
 
221
221
  ```ruby
222
- Audited.audit_class.as_user(User.find(1)) do
222
+ VelocityAudited.audit_class.as_user(User.find(1)) do
223
223
  post.update!(title: "Hello, world!")
224
224
  end
225
225
  post.audits.last.user # => #<User id: 1>
@@ -246,7 +246,7 @@ end
246
246
  `as_user` also accepts a string, which can be useful for auditing updates made in a CLI environment:
247
247
 
248
248
  ```rb
249
- Audited.audit_class.as_user("console-user-#{ENV['SSH_USER']}") do
249
+ VelocityAudited.audit_class.as_user("console-user-#{ENV['SSH_USER']}") do
250
250
  post.update_attributes!(title: "Hello, world!")
251
251
  end
252
252
  post.audits.last.user # => 'console-user-username'
@@ -255,11 +255,11 @@ post.audits.last.user # => 'console-user-username'
255
255
  If you want to set a specific user as the auditor of the commands in a CLI environment, whether that is a string or an ActiveRecord object, you can use the following command:
256
256
 
257
257
  ```rb
258
- Audited.store[:audited_user] = "username"
258
+ VelocityAudited.store[:audited_user] = "username"
259
259
 
260
260
  # or
261
261
 
262
- Audited.store[:audited_user] = User.find(1)
262
+ VelocityAudited.store[:audited_user] = User.find(1)
263
263
  ```
264
264
 
265
265
  ### Associated Audits
@@ -366,7 +366,7 @@ User.auditing_enabled = false
366
366
  To disable auditing on all models:
367
367
 
368
368
  ```ruby
369
- Audited.auditing_enabled = false
369
+ VelocityAudited.auditing_enabled = false
370
370
  ```
371
371
 
372
372
  If you have auditing disabled by default on your model you can enable auditing
@@ -390,18 +390,20 @@ end
390
390
 
391
391
  If you want to extend or modify the audit model, create a new class that
392
392
  inherits from `Audited::Audit`:
393
+
393
394
  ```ruby
394
- class CustomAudit < Audited::Audit
395
+ class CustomAudit < VelocityAudited::Audit
395
396
  def some_custom_behavior
396
397
  "Hiya!"
397
398
  end
398
399
  end
399
400
  ```
400
401
  Then set it in an initializer:
402
+
401
403
  ```ruby
402
- # config/initializers/audited.rb
404
+ # config/initializers/velocity_audited.rb
403
405
 
404
- Audited.config do |config|
406
+ VelocityAudited.config do |config|
405
407
  config.audit_class = CustomAudit
406
408
  end
407
409
  ```
@@ -411,9 +413,9 @@ end
411
413
  In 4.10, the default behavior for enums changed from storing the value synthesized by Rails to the value stored in the DB. You can restore the previous behavior by setting the store_synthesized_enums configuration value:
412
414
 
413
415
  ```ruby
414
- # config/initializers/audited.rb
416
+ # config/initializers/velocity_audited.rb
415
417
 
416
- Audited.store_synthesized_enums = true
418
+ VelocityAudited.store_synthesized_enums = true
417
419
  ```
418
420
 
419
421
  ## Support
data/lib/audited/audit.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "set"
4
4
 
5
- module Audited
5
+ module VelocityAudited
6
6
  # Audit saves the changes to ActiveRecord models. It has the following attributes:
7
7
  #
8
8
  # * <tt>auditable</tt>: the ActiveRecord model that was changed
@@ -34,7 +34,7 @@ module Audited
34
34
  end
35
35
 
36
36
  def text_column?
37
- Audited.audit_class.columns_hash["audited_changes"].type.to_s == "text"
37
+ VelocityAudited.audit_class.columns_hash["audited_changes"].type.to_s == "text"
38
38
  end
39
39
  end
40
40
  end
@@ -134,11 +134,11 @@ module Audited
134
134
  # by +user+. This method is hopefully threadsafe, making it ideal
135
135
  # for background operations that require audit information.
136
136
  def self.as_user(user)
137
- last_audited_user = ::Audited.store[:audited_user]
138
- ::Audited.store[:audited_user] = user
137
+ last_audited_user = ::VelocityAudited.store[:audited_user]
138
+ ::VelocityAudited.store[:audited_user] = user
139
139
  yield
140
140
  ensure
141
- ::Audited.store[:audited_user] = last_audited_user
141
+ ::VelocityAudited.store[:audited_user] = last_audited_user
142
142
  end
143
143
 
144
144
  # @private
@@ -181,18 +181,18 @@ module Audited
181
181
  end
182
182
 
183
183
  def set_audit_user
184
- self.user ||= ::Audited.store[:audited_user] # from .as_user
185
- self.user ||= ::Audited.store[:current_user].try!(:call) # from Sweeper
184
+ self.user ||= ::VelocityAudited.store[:audited_user] # from .as_user
185
+ self.user ||= ::VelocityAudited.store[:current_user].try!(:call) # from Sweeper
186
186
  nil # prevent stopping callback chains
187
187
  end
188
188
 
189
189
  def set_request_uuid
190
- self.request_uuid ||= ::Audited.store[:current_request_uuid]
190
+ self.request_uuid ||= ::VelocityAudited.store[:current_request_uuid]
191
191
  self.request_uuid ||= SecureRandom.uuid
192
192
  end
193
193
 
194
194
  def set_remote_address
195
- self.remote_address ||= ::Audited.store[:current_remote_address]
195
+ self.remote_address ||= ::VelocityAudited.store[:current_remote_address]
196
196
  end
197
197
  end
198
198
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  # Specify this act if you want changes to your model to be saved in an
5
5
  # audit table. This assumes there is an audits table ready.
6
6
  #
@@ -60,10 +60,10 @@ module Audited
60
60
  #
61
61
  def audited(options = {})
62
62
  # don't allow multiple calls
63
- return if included_modules.include?(Audited::Auditor::AuditedInstanceMethods)
63
+ return if included_modules.include?(VelocityAudited::Auditor::AuditedInstanceMethods)
64
64
 
65
- extend Audited::Auditor::AuditedClassMethods
66
- include Audited::Auditor::AuditedInstanceMethods
65
+ extend VelocityAudited::Auditor::AuditedClassMethods
66
+ include VelocityAudited::Auditor::AuditedInstanceMethods
67
67
 
68
68
  class_attribute :audit_associated_with, instance_writer: false
69
69
  class_attribute :audited_options, instance_writer: false
@@ -79,8 +79,8 @@ module Audited
79
79
  before_destroy :require_comment if audited_options[:on].include?(:destroy)
80
80
  end
81
81
 
82
- has_many :audits, -> { order(version: :asc) }, as: :auditable, class_name: Audited.audit_class.name, inverse_of: :auditable
83
- Audited.audit_class.audited_class_names << to_s
82
+ has_many :audits, -> { order(version: :asc) }, as: :auditable, class_name: VelocityAudited.audit_class.name, inverse_of: :auditable
83
+ VelocityAudited.audit_class.audited_class_names << to_s
84
84
 
85
85
  after_create :audit_create if audited_options[:on].include?(:create)
86
86
  before_update :audit_update if audited_options[:on].include?(:update)
@@ -97,7 +97,7 @@ module Audited
97
97
  end
98
98
 
99
99
  def has_associated_audits
100
- has_many :associated_audits, as: :associated, class_name: Audited.audit_class.name
100
+ has_many :associated_audits, as: :associated, class_name: VelocityAudited.audit_class.name
101
101
  end
102
102
  end
103
103
 
@@ -159,14 +159,14 @@ module Audited
159
159
  # Returns nil for versions greater than revisions count
160
160
  def revision(version)
161
161
  if version == :previous || audits.last.version >= version
162
- revision_with Audited.audit_class.reconstruct_attributes(audits_to(version))
162
+ revision_with VelocityAudited.audit_class.reconstruct_attributes(audits_to(version))
163
163
  end
164
164
  end
165
165
 
166
166
  # Find the oldest revision recorded prior to the date/time provided.
167
167
  def revision_at(date_or_time)
168
168
  audits = self.audits.up_until(date_or_time)
169
- revision_with Audited.audit_class.reconstruct_attributes(audits) unless audits.empty?
169
+ revision_with VelocityAudited.audit_class.reconstruct_attributes(audits) unless audits.empty?
170
170
  end
171
171
 
172
172
  # List of attributes that are audited.
@@ -177,7 +177,7 @@ module Audited
177
177
 
178
178
  # Returns a list combined of record audits and associated audits.
179
179
  def own_and_associated_audits
180
- Audited.audit_class.unscoped
180
+ VelocityAudited.audit_class.unscoped
181
181
  .where("(auditable_type = :type AND auditable_id = :id) OR (associated_type = :type AND associated_id = :id)",
182
182
  type: self.class.base_class.name, id: id)
183
183
  .order(created_at: :desc)
@@ -206,7 +206,7 @@ module Audited
206
206
  revision.send :instance_variable_set, "@destroyed", false
207
207
  revision.send :instance_variable_set, "@_destroyed", false
208
208
  revision.send :instance_variable_set, "@marked_for_destruction", false
209
- Audited.audit_class.assign_revision_attributes(revision, attributes)
209
+ VelocityAudited.audit_class.assign_revision_attributes(revision, attributes)
210
210
 
211
211
  # Remove any association proxies so that they will be recreated
212
212
  # and reference the correct object for this revision. The only way
@@ -239,7 +239,7 @@ module Audited
239
239
  end
240
240
 
241
241
  def normalize_enum_changes(changes)
242
- return changes if Audited.store_synthesized_enums
242
+ return changes if VelocityAudited.store_synthesized_enums
243
243
 
244
244
  self.class.defined_enums.each do |name, values|
245
245
  if changes.has_key?(name)
@@ -310,19 +310,22 @@ module Audited
310
310
  def write_audit(attrs)
311
311
  self.audit_comment = nil
312
312
  attrs[:db_audit] = true
313
+ attrs[:record_id] = id
314
+ attrs[:model] = self.class.base_class.name
313
315
  attrs = add_metadata(attrs)
314
316
  if auditing_enabled
315
317
  attrs[:associated] = send(audit_associated_with) unless audit_associated_with.nil?
316
- logger.audit(attrs.to_json)
318
+ logger.info(attrs.to_json)
317
319
  end
318
320
  end
319
321
 
320
322
  def add_metadata(attrs)
321
- attrs[:client] = ::Audited.store[:client]
322
- attrs[:origin] = ::Audited.store[:origin]
323
- attrs[:user_agent] = ::Audited.store[:user_agent]
324
- attrs[:ip] = ::Audited.store[:ip]
325
- attrs[:uid] = ::Audited.store[:uid]
323
+ attrs[:client] = ::VelocityAudited.store[:client]
324
+ attrs[:origin] = ::VelocityAudited.store[:origin]
325
+ attrs[:user_agent] = ::VelocityAudited.store[:user_agent]
326
+ attrs[:ip] = ::VelocityAudited.store[:current_remote_address]
327
+ attrs[:uid] = ::VelocityAudited.store[:uid]
328
+ attrs[:request_id] = ::VelocityAudited.store[:request_id]
326
329
  attrs
327
330
  end
328
331
 
@@ -436,19 +439,19 @@ module Audited
436
439
  # convenience wrapper around
437
440
  # @see Audit#as_user.
438
441
  def audit_as(user, &block)
439
- Audited.audit_class.as_user(user, &block)
442
+ VelocityAudited.audit_class.as_user(user, &block)
440
443
  end
441
444
 
442
445
  def auditing_enabled
443
- Audited.store.fetch("#{table_name}_auditing_enabled", true) && Audited.auditing_enabled
446
+ VelocityAudited.store.fetch("#{table_name}_auditing_enabled", true) && VelocityAudited.auditing_enabled
444
447
  end
445
448
 
446
449
  def auditing_enabled=(val)
447
- Audited.store["#{table_name}_auditing_enabled"] = val
450
+ VelocityAudited.store["#{table_name}_auditing_enabled"] = val
448
451
  end
449
452
 
450
453
  def default_ignored_attributes
451
- [primary_key, inheritance_column] | Audited.ignored_attributes
454
+ [primary_key, inheritance_column] | VelocityAudited.ignored_attributes
452
455
  end
453
456
 
454
457
  protected
@@ -458,7 +461,7 @@ module Audited
458
461
  audited_options[:on] = [:create, :update, :destroy] if audited_options[:on].empty?
459
462
  audited_options[:only] = Array.wrap(audited_options[:only]).map(&:to_s)
460
463
  audited_options[:except] = Array.wrap(audited_options[:except]).map(&:to_s)
461
- max_audits = audited_options[:max_audits] || Audited.max_audits
464
+ max_audits = audited_options[:max_audits] || VelocityAudited.max_audits
462
465
  audited_options[:max_audits] = Integer(max_audits).abs if max_audits
463
466
  end
464
467
 
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  class Railtie < Rails::Railtie
5
5
  initializer "audited.sweeper" do
6
6
  ActiveSupport.on_load(:action_controller) do
7
7
  if defined?(ActionController::Base)
8
- ActionController::Base.around_action Audited::Sweeper.new
8
+ ActionController::Base.around_action VelocityAudited::Sweeper.new
9
9
  end
10
10
  if defined?(ActionController::API)
11
- ActionController::API.around_action Audited::Sweeper.new
11
+ ActionController::API.around_action VelocityAudited::Sweeper.new
12
12
  end
13
13
  end
14
14
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  module RspecMatchers
5
5
  # Ensure that the model is audited.
6
6
  #
@@ -221,7 +221,7 @@ module Audited
221
221
  def association_exists?
222
222
  !reflection.nil? &&
223
223
  reflection.macro == :has_many &&
224
- reflection.options[:class_name] == Audited.audit_class.name
224
+ reflection.options[:class_name] == VelocityAudited.audit_class.name
225
225
  end
226
226
  end
227
227
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  class Sweeper
5
5
  STORED_DATA = {
6
6
  current_remote_address: :remote_ip,
@@ -8,12 +8,12 @@ module Audited
8
8
  current_user: :current_user,
9
9
  origin: :origin,
10
10
  user_agent: :user_agent,
11
- ip: :ip,
12
11
  uid: :uid,
13
- client: :client
12
+ client: :client,
13
+ request_id: :request_id
14
14
  }
15
15
 
16
- delegate :store, to: ::Audited
16
+ delegate :store, to: ::VelocityAudited
17
17
 
18
18
  def around(controller)
19
19
  self.controller = controller
@@ -25,7 +25,7 @@ module Audited
25
25
  end
26
26
 
27
27
  def current_user
28
- lambda { controller.send(Audited.current_user_method) if controller.respond_to?(Audited.current_user_method, true) }
28
+ lambda { controller.send(VelocityAudited.current_user_method) if controller.respond_to?(VelocityAudited.current_user_method, true) }
29
29
  end
30
30
 
31
31
  def remote_ip
@@ -43,11 +43,7 @@ module Audited
43
43
  def user_agent
44
44
  controller.try(:request).try(:headers)['User-Agent']
45
45
  end
46
-
47
- def ip
48
- controller.try(:request).try(:headers)['HTTP_X_FORWARDED_FOR']
49
- end
50
-
46
+
51
47
  def uid
52
48
  controller.try(:request).try(:headers)['uid']
53
49
  end
@@ -56,6 +52,10 @@ module Audited
56
52
  controller.try(:request).try(:headers)['client']
57
53
  end
58
54
 
55
+ def request_id
56
+ controller.try(:request).try(:uuid)
57
+ end
58
+
59
59
  def controller
60
60
  store[:current_controller]
61
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
4
- VERSION = "5.1.4"
3
+ module VelocityAudited
4
+ VERSION = "6.0.3"
5
5
  end
data/lib/audited-rspec.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  require "audited/rspec_matchers"
4
4
  module RSpec::Matchers
5
- include Audited::RspecMatchers
5
+ include VelocityAudited::RspecMatchers
6
6
  end
@@ -7,12 +7,12 @@ require "rails/generators/active_record"
7
7
  require "generators/audited/migration"
8
8
  require "generators/audited/migration_helper"
9
9
 
10
- module Audited
10
+ module VelocityAudited
11
11
  module Generators
12
12
  class InstallGenerator < Rails::Generators::Base
13
13
  include Rails::Generators::Migration
14
- include Audited::Generators::MigrationHelper
15
- extend Audited::Generators::Migration
14
+ include VelocityAudited::Generators::MigrationHelper
15
+ extend VelocityAudited::Generators::Migration
16
16
 
17
17
  class_option :audited_changes_column_type, type: :string, default: "text", required: false
18
18
  class_option :audited_user_id_column_type, type: :string, default: "integer", required: false
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  module Generators
5
5
  module Migration
6
6
  # Implement the required interface for Rails::Generators::Migration.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  module Generators
5
5
  module MigrationHelper
6
6
  def migration_parent
@@ -7,12 +7,12 @@ require "rails/generators/active_record"
7
7
  require "generators/audited/migration"
8
8
  require "generators/audited/migration_helper"
9
9
 
10
- module Audited
10
+ module VelocityAudited
11
11
  module Generators
12
12
  class UpgradeGenerator < Rails::Generators::Base
13
13
  include Rails::Generators::Migration
14
- include Audited::Generators::MigrationHelper
15
- extend Audited::Generators::Migration
14
+ include VelocityAudited::Generators::MigrationHelper
15
+ extend VelocityAudited::Generators::Migration
16
16
 
17
17
  source_root File.expand_path("../templates", __FILE__)
18
18
 
@@ -25,9 +25,9 @@ module Audited
25
25
  private
26
26
 
27
27
  def migrations_to_be_applied
28
- Audited::Audit.reset_column_information
29
- columns = Audited::Audit.columns.map(&:name)
30
- indexes = Audited::Audit.connection.indexes(Audited::Audit.table_name)
28
+ VelocityAudited::Audit.reset_column_information
29
+ columns = VelocityAudited::Audit.columns.map(&:name)
30
+ indexes = VelocityAudited::Audit.connection.indexes(VelocityAudited::Audit.table_name)
31
31
 
32
32
  yield :add_comment_to_audits unless columns.include?("comment")
33
33
 
@@ -1,53 +1,49 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record"
2
4
 
3
5
  module VelocityAudited
4
- # frozen_string_literal: true
5
- #
6
- module Audited
7
- class << self
8
- attr_accessor \
6
+ class << self
7
+ attr_accessor \
9
8
  :auditing_enabled,
10
9
  :current_user_method,
11
10
  :ignored_attributes,
12
11
  :max_audits,
13
12
  :store_synthesized_enums
14
- attr_writer :audit_class
15
-
16
- def audit_class
17
- @audit_class ||= Audit
18
- end
13
+ attr_writer :audit_class
19
14
 
20
- def store
21
- current_store_value = Thread.current.thread_variable_get(:audited_store)
15
+ def audit_class
16
+ @audit_class ||= Audit
17
+ end
22
18
 
23
- if current_store_value.nil?
24
- Thread.current.thread_variable_set(:audited_store, {})
25
- else
26
- current_store_value
27
- end
28
- end
19
+ def store
20
+ current_store_value = Thread.current.thread_variable_get(:audited_store)
29
21
 
30
- def config
31
- yield(self)
22
+ if current_store_value.nil?
23
+ Thread.current.thread_variable_set(:audited_store, {})
24
+ else
25
+ current_store_value
32
26
  end
33
27
  end
34
28
 
35
- @ignored_attributes = %w[lock_version created_at updated_at created_on updated_on]
36
-
37
- @current_user_method = :current_user
38
- @auditing_enabled = true
39
- @store_synthesized_enums = false
29
+ def config
30
+ yield(self)
31
+ end
40
32
  end
41
33
 
42
- require "audited/auditor"
34
+ @ignored_attributes = %w[lock_version created_at updated_at created_on updated_on]
43
35
 
44
- ActiveSupport.on_load :active_record do
45
- require "audited/audit"
46
- include Audited::Auditor
47
- end
36
+ @current_user_method = :current_user
37
+ @auditing_enabled = true
38
+ @store_synthesized_enums = false
39
+ end
48
40
 
49
- require "audited/sweeper"
50
- require "audited/railtie"
41
+ require "audited/auditor"
51
42
 
43
+ ActiveSupport.on_load :active_record do
44
+ require "audited/audit"
45
+ include VelocityAudited::Auditor
46
+ end
52
47
 
53
- end
48
+ require "audited/sweeper"
49
+ require "audited/railtie"