paper_trail 14.0.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/paper_trail/install/install_generator.rb +11 -1
- data/lib/generators/paper_trail/install/templates/create_versions.rb.erb +1 -1
- data/lib/paper_trail/attribute_serializers/cast_attribute_serializer.rb +1 -5
- data/lib/paper_trail/attribute_serializers/object_attribute.rb +13 -3
- data/lib/paper_trail/attribute_serializers/object_changes_attribute.rb +13 -3
- data/lib/paper_trail/compatibility.rb +1 -1
- data/lib/paper_trail/has_paper_trail.rb +4 -0
- data/lib/paper_trail/model_config.rb +3 -2
- data/lib/paper_trail/record_trail.rb +2 -1
- data/lib/paper_trail/version_number.rb +1 -1
- data/lib/paper_trail.rb +4 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a343a4be31774100a8713280696dcfad46cd119b04de6884de7b6a1b34acd13
|
4
|
+
data.tar.gz: 120dfe293f08004ee33bb09a0db23d3004ea2dadfaff56e8992283564458df28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8401d4f39db71320590dab474b8782a4f52843394869d12aa3cb5270d25170df8435af7a1c97cdcb3b1acbd8841eacdfd0c905c681b6e1173b2e6c0a69e37af9
|
7
|
+
data.tar.gz: 0ec02b4a9ab72e45741ba79c8c4b09c524a02dc01de35b7763322eea5612112ae0be36e4a6dcf50c297b8bf8f0c5b96d78719d2f7839352b8d57c383d6fd250a
|
@@ -35,7 +35,8 @@ module PaperTrail
|
|
35
35
|
"create_versions",
|
36
36
|
item_type_options: item_type_options,
|
37
37
|
versions_table_options: versions_table_options,
|
38
|
-
item_id_type_options: item_id_type_options
|
38
|
+
item_id_type_options: item_id_type_options,
|
39
|
+
version_table_primary_key_type: version_table_primary_key_type
|
39
40
|
)
|
40
41
|
if options.with_changes?
|
41
42
|
add_paper_trail_migration("add_object_changes_to_versions")
|
@@ -49,6 +50,15 @@ module PaperTrail
|
|
49
50
|
options.uuid? ? "string" : "bigint"
|
50
51
|
end
|
51
52
|
|
53
|
+
# To use uuid for version table primary key
|
54
|
+
def version_table_primary_key_type
|
55
|
+
if options.uuid?
|
56
|
+
", id: :uuid"
|
57
|
+
else
|
58
|
+
""
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
52
62
|
# MySQL 5.6 utf8mb4 limit is 191 chars for keys used in indexes.
|
53
63
|
# See https://github.com/paper-trail-gem/paper_trail/issues/651
|
54
64
|
def item_type_options
|
@@ -9,7 +9,7 @@ class CreateVersions < ActiveRecord::Migration<%= migration_version %>
|
|
9
9
|
TEXT_BYTES = 1_073_741_823
|
10
10
|
|
11
11
|
def change
|
12
|
-
create_table :versions<%= versions_table_options %> do |t|
|
12
|
+
create_table :versions<%= versions_table_options %><%= version_table_primary_key_type %> do |t|
|
13
13
|
t.string :item_type<%= item_type_options %>
|
14
14
|
t.<%= item_id_type_options %> :item_id, null: false
|
15
15
|
t.string :event, null: false
|
@@ -32,7 +32,7 @@ module PaperTrail
|
|
32
32
|
if defined_enums[attr] && val.is_a?(::String)
|
33
33
|
# Because PT 4 used to save the string version of enums to `object_changes`
|
34
34
|
val
|
35
|
-
elsif
|
35
|
+
elsif PaperTrail.active_record_gte_7_0? && val.is_a?(ActiveRecord::Type::Time::Value)
|
36
36
|
# Because Rails 7 time attribute throws a delegation error when you deserialize
|
37
37
|
# it with the factory.
|
38
38
|
# See ActiveRecord::Type::Time::Value crashes when loaded from YAML on rails 7.0
|
@@ -43,10 +43,6 @@ module PaperTrail
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def rails_gte_7_0?
|
47
|
-
::ActiveRecord.gem_version >= ::Gem::Version.new("7.0.0")
|
48
|
-
end
|
49
|
-
|
50
46
|
def serialize(attr, val)
|
51
47
|
AttributeSerializerFactory.for(@klass, attr).serialize(val)
|
52
48
|
end
|
@@ -8,6 +8,12 @@ module PaperTrail
|
|
8
8
|
class ObjectAttribute
|
9
9
|
def initialize(model_class)
|
10
10
|
@model_class = model_class
|
11
|
+
|
12
|
+
# ActiveRecord since 7.0 has a built-in encryption mechanism
|
13
|
+
@encrypted_attributes =
|
14
|
+
if PaperTrail.active_record_gte_7_0?
|
15
|
+
@model_class.encrypted_attributes&.map(&:to_s)
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
def serialize(attributes)
|
@@ -23,14 +29,18 @@ module PaperTrail
|
|
23
29
|
# Modifies `attributes` in place.
|
24
30
|
# TODO: Return a new hash instead.
|
25
31
|
def alter(attributes, serialization_method)
|
26
|
-
# Don't serialize before values before inserting into columns of type
|
32
|
+
# Don't serialize non-encrypted before values before inserting into columns of type
|
27
33
|
# `JSON` on `PostgreSQL` databases.
|
28
|
-
|
34
|
+
attributes_to_serialize =
|
35
|
+
object_col_is_json? ? attributes.slice(*@encrypted_attributes) : attributes
|
36
|
+
return attributes if attributes_to_serialize.blank?
|
29
37
|
|
30
38
|
serializer = CastAttributeSerializer.new(@model_class)
|
31
|
-
|
39
|
+
attributes_to_serialize.each do |key, value|
|
32
40
|
attributes[key] = serializer.send(serialization_method, key, value)
|
33
41
|
end
|
42
|
+
|
43
|
+
attributes
|
34
44
|
end
|
35
45
|
|
36
46
|
def object_col_is_json?
|
@@ -8,6 +8,12 @@ module PaperTrail
|
|
8
8
|
class ObjectChangesAttribute
|
9
9
|
def initialize(item_class)
|
10
10
|
@item_class = item_class
|
11
|
+
|
12
|
+
# ActiveRecord since 7.0 has a built-in encryption mechanism
|
13
|
+
@encrypted_attributes =
|
14
|
+
if PaperTrail.active_record_gte_7_0?
|
15
|
+
@item_class.encrypted_attributes&.map(&:to_s)
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
def serialize(changes)
|
@@ -23,17 +29,21 @@ module PaperTrail
|
|
23
29
|
# Modifies `changes` in place.
|
24
30
|
# TODO: Return a new hash instead.
|
25
31
|
def alter(changes, serialization_method)
|
26
|
-
# Don't serialize before values before inserting into columns of type
|
32
|
+
# Don't serialize non-encrypted before values before inserting into columns of type
|
27
33
|
# `JSON` on `PostgreSQL` databases.
|
28
|
-
|
34
|
+
changes_to_serialize =
|
35
|
+
object_changes_col_is_json? ? changes.slice(*@encrypted_attributes) : changes.clone
|
36
|
+
return changes if changes_to_serialize.blank?
|
29
37
|
|
30
38
|
serializer = CastAttributeSerializer.new(@item_class)
|
31
|
-
|
39
|
+
changes_to_serialize.each do |key, change|
|
32
40
|
# `change` is an Array with two elements, representing before and after.
|
33
41
|
changes[key] = Array(change).map do |value|
|
34
42
|
serializer.send(serialization_method, key, value)
|
35
43
|
end
|
36
44
|
end
|
45
|
+
|
46
|
+
changes
|
37
47
|
end
|
38
48
|
|
39
49
|
def object_changes_col_is_json?
|
@@ -17,7 +17,7 @@ module PaperTrail
|
|
17
17
|
# newer rails versions. Most PT users should avoid incompatible rails
|
18
18
|
# versions.
|
19
19
|
module Compatibility
|
20
|
-
ACTIVERECORD_GTE = ">= 6.
|
20
|
+
ACTIVERECORD_GTE = ">= 6.1" # enforced in gemspec
|
21
21
|
ACTIVERECORD_LT = "< 7.1" # not enforced in gemspec
|
22
22
|
|
23
23
|
E_INCOMPATIBLE_AR = <<-EOS
|
@@ -53,6 +53,10 @@ module PaperTrail
|
|
53
53
|
# - A Hash - options passed to `has_many`, plus `name:` and `scope:`.
|
54
54
|
# - :version - The name to use for the method which returns the version
|
55
55
|
# the instance was reified from. Default is `:version`.
|
56
|
+
# - :synchronize_version_creation_timestamp - By default, paper trail
|
57
|
+
# sets the `created_at` field for a new Version equal to the `updated_at`
|
58
|
+
# column of the model being updated. If you instead want `created_at` to
|
59
|
+
# populate with the current timestamp, set this option to `false`.
|
56
60
|
#
|
57
61
|
# Plugins like the experimental `paper_trail-association_tracking` gem
|
58
62
|
# may accept additional options.
|
@@ -82,8 +82,9 @@ module PaperTrail
|
|
82
82
|
|
83
83
|
# Adds a callback that records a version after a "touch" event.
|
84
84
|
#
|
85
|
-
# Rails < 6.0
|
86
|
-
# a `touch`.
|
85
|
+
# Rails < 6.0 (no longer supported by PT) had a bug where dirty-tracking
|
86
|
+
# did not occur during a `touch`.
|
87
|
+
# (https://github.com/rails/rails/issues/33429) See also:
|
87
88
|
# https://github.com/paper-trail-gem/paper_trail/issues/1121
|
88
89
|
# https://github.com/paper-trail-gem/paper_trail/issues/1161
|
89
90
|
# https://github.com/paper-trail-gem/paper_trail/pull/1285
|
@@ -226,7 +226,8 @@ module PaperTrail
|
|
226
226
|
# unnatural to tamper with creation timestamps in this way. But, this
|
227
227
|
# feature has existed for a long time, almost a decade now, and some users
|
228
228
|
# may rely on it now.
|
229
|
-
if @record.respond_to?(:updated_at)
|
229
|
+
if @record.respond_to?(:updated_at) &&
|
230
|
+
@record.paper_trail_options[:synchronize_version_creation_timestamp] != false
|
230
231
|
data[:created_at] = @record.updated_at
|
231
232
|
end
|
232
233
|
|
data/lib/paper_trail.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paper_trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 15.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Stewart
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-08-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '6.
|
21
|
+
version: '6.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '6.
|
28
|
+
version: '6.1'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: request_store
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,14 +116,14 @@ dependencies:
|
|
116
116
|
requirements:
|
117
117
|
- - ">="
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
version: '6.
|
119
|
+
version: '6.1'
|
120
120
|
type: :development
|
121
121
|
prerelease: false
|
122
122
|
version_requirements: !ruby/object:Gem::Requirement
|
123
123
|
requirements:
|
124
124
|
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
version: '6.
|
126
|
+
version: '6.1'
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: rake
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
@@ -360,7 +360,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
360
360
|
requirements:
|
361
361
|
- - ">="
|
362
362
|
- !ruby/object:Gem::Version
|
363
|
-
version:
|
363
|
+
version: 3.0.0
|
364
364
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
365
365
|
requirements:
|
366
366
|
- - ">="
|