Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App and specs working under Ruby 3.1.4 #1138 #1139

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
1138 upgrade PaperTrail, Ruby to 3.1
  • Loading branch information
ferrisoxide committed Aug 7, 2023
commit a72ea81e07b1450b50223b7d46c1114295802b44
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.6
3.1.4
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ GEM
mini_mime (1.1.2)
mini_racer (0.6.4)
libv8-node (~> 16.19.0.0)
minitest (5.18.1)
minitest (5.19.0)
msgpack (1.6.0)
nenv (0.3.0)
net-imap (0.3.6)
Expand All @@ -253,9 +253,9 @@ GEM
nenv (~> 0.1)
shellany (~> 0.0)
orm_adapter (0.5.0)
paper_trail (12.0.0)
activerecord (>= 5.2)
request_store (~> 1.1)
paper_trail (15.0.0)
activerecord (>= 6.1)
request_store (~> 1.4)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
Expand All @@ -275,7 +275,7 @@ GEM
puma (6.3.0)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.7)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
rails (6.1.7.4)
Expand Down Expand Up @@ -341,7 +341,7 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.8.1)
request_store (1.5.0)
request_store (1.5.1)
rack (>= 1.4)
responders (3.1.0)
actionpack (>= 5.2)
Expand Down Expand Up @@ -447,7 +447,7 @@ GEM
will_paginate (4.0.0)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.8)
zeitwerk (2.6.11)
zeus (0.15.14)
method_source (>= 0.6.7)

Expand Down Expand Up @@ -495,7 +495,7 @@ DEPENDENCIES
mini_magick
mini_racer
nokogiri (>= 1.8.1)
paper_trail (~> 12.0.0)
paper_trail (~> 15.0.0)
pg
premailer
pry-rails
Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class Application < Rails::Application

# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += %i[password encrypted_password password_salt password_confirmation]

# Enable support for loading via Psych, required by PaperTrail
config.active_record.use_yaml_unsafe_load = true
Copy link
Member

@CloCkWeRX CloCkWeRX Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
config.active_record.use_yaml_unsafe_load = true
config.active_record.use_yaml_unsafe_load = false
config.active_record.yaml_column_permitted_classes = [
::ActiveRecord::Type::Time::Value,
::ActiveSupport::TimeWithZone,
::ActiveSupport::TimeZone,
::BigDecimal,
::Date,
::Symbol,
::Time
]

https://github.com/paper-trail-gem/paper_trail/blob/master/doc/pt_13_yaml_safe_load.md#to-continue-using-the-yaml-serializer might be worth looking through, so that people upgrading don't have any issues with legacy data (but also no security issues)

not sure if we just need to add a bunch of internal models (Account, Lead, Opportunity etc) as well

Copy link
Contributor Author

@ferrisoxide ferrisoxide Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we just need to add a bunch of internal models (Account, Lead, Opportunity etc) as well

Allowing all classes to be serialized/deserialized via Psych isn't great, but you can't specify the model classes in application.rb (they haven't been loaded at this point). Naively moving the configuration to an initializer breaks, with some Active Support classes being marked as a disallowed class in specs. I'm not sure why just yet.

I'm also a bit worried about serialization of associated objects - I suspect we'd have to declare all possible compositions, not just the base model classes.

Fixing this might be tricky. I'd suggest that we look at securing serialization in a separate ticket as I've no idea how far down the rabbit hole this is going to go. Right now, leaving use_yaml_unsafe_load set to true is no more unsafe than what is present in the app - and only appears to impact Paper Trail versions records that can't be directly manipulated by users.

In a perfect world we wouldn't be using YAML serialization for Paper Trail, but I think JSON-based serialization is only available on Postgres. I see you've already identified this as an issue per #1146.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ Actually, scrap that. The proposed change seems to be working without adding models - at least in specs. I'll be more comfortable making this change after I've given the front end a manual test - will look at doing that tomorrow.

end
end

Expand Down
2 changes: 1 addition & 1 deletion fat_free_crm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |gem|
gem.add_dependency 'select2-rails'
gem.add_dependency 'simple_form'
gem.add_dependency 'will_paginate'
gem.add_dependency 'paper_trail', '~> 12.0.0'
gem.add_dependency 'paper_trail', '~> 15.0.0'
gem.add_dependency 'devise', '~> 4.6'
gem.add_dependency 'devise-encryptable', '~> 0.2.0'
gem.add_dependency 'acts_as_commentable', '~> 6.0.0'
Expand Down