From 7a16534511de98517fd1fb02e695336c9a30557c Mon Sep 17 00:00:00 2001 From: Adrien Dessy Date: Wed, 18 Dec 2024 17:30:38 +0100 Subject: [PATCH 1/8] [TAN-3184] Eliminate new_framework_defaults_7_0.rb --- back/config/application.rb | 3 +++ back/config/initializers/new_framework_defaults_7_0.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/back/config/application.rb b/back/config/application.rb index f3fb9b9f1ff3..a79ebe90a66d 100644 --- a/back/config/application.rb +++ b/back/config/application.rb @@ -32,6 +32,9 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 6.1 + # TODO: Delete the following settings once we move to config.load_defaults 7.0 + config.active_support.disable_to_s_conversion = true + # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files diff --git a/back/config/initializers/new_framework_defaults_7_0.rb b/back/config/initializers/new_framework_defaults_7_0.rb index fdc4999fccbf..98f61e019ddb 100644 --- a/back/config/initializers/new_framework_defaults_7_0.rb +++ b/back/config/initializers/new_framework_defaults_7_0.rb @@ -25,7 +25,7 @@ # # See upgrading guide for more information on how to build a rotator. # https://guides.rubyonrails.org/v7.0/upgrading_ruby_on_rails.html -# Rails.application.config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256 +Rails.application.config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256 # Change the digest class for ActiveSupport::Digest. # Changing this default means that for example Etags change and From e73899cd825eab81c808f81d6de7955698bc463f Mon Sep 17 00:00:00 2001 From: Adrien Dessy Date: Thu, 19 Dec 2024 13:47:11 +0100 Subject: [PATCH 2/8] [TAN-3184] Use `wrap_parameters_by_default` to replace initializer --- .../initializers/new_framework_defaults_7_0.rb | 2 +- back/config/initializers/wrap_parameters.rb | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 back/config/initializers/wrap_parameters.rb diff --git a/back/config/initializers/new_framework_defaults_7_0.rb b/back/config/initializers/new_framework_defaults_7_0.rb index 98f61e019ddb..4281ed58b5aa 100644 --- a/back/config/initializers/new_framework_defaults_7_0.rb +++ b/back/config/initializers/new_framework_defaults_7_0.rb @@ -67,7 +67,7 @@ # Enable parameter wrapping for JSON. # Previously this was set in an initializer. It's fine to keep using that initializer if you've customized it. # To disable parameter wrapping entirely, set this config to `false`. -# Rails.application.config.action_controller.wrap_parameters_by_default = true +Rails.application.config.action_controller.wrap_parameters_by_default = true # Specifies whether generated namespaced UUIDs follow the RFC 4122 standard for namespace IDs provided as a # `String` to `Digest::UUID.uuid_v3` or `Digest::UUID.uuid_v5` method calls. diff --git a/back/config/initializers/wrap_parameters.rb b/back/config/initializers/wrap_parameters.rb deleted file mode 100644 index 2f3c0db471c0..000000000000 --- a/back/config/initializers/wrap_parameters.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. - -# This file contains settings for ActionController::ParamsWrapper which -# is enabled by default. - -# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. -ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] -end - -# To enable root element in JSON for ActiveRecord objects. -# ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true -# end From 6f7d3ab50b0449f995cad10dc65ec34b97b1616b Mon Sep 17 00:00:00 2001 From: Adrien Dessy Date: Thu, 19 Dec 2024 13:51:28 +0100 Subject: [PATCH 3/8] [TAN-3184] Update to Rails 7 cache format --- back/config/application.rb | 1 + .../initializers/new_framework_defaults_7_0.rb | 14 -------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/back/config/application.rb b/back/config/application.rb index a79ebe90a66d..399143dd1504 100644 --- a/back/config/application.rb +++ b/back/config/application.rb @@ -34,6 +34,7 @@ class Application < Rails::Application # TODO: Delete the following settings once we move to config.load_defaults 7.0 config.active_support.disable_to_s_conversion = true + config.active_support.cache_format_version = 7.0 # Configuration for the application, engines, and railties goes here. # diff --git a/back/config/initializers/new_framework_defaults_7_0.rb b/back/config/initializers/new_framework_defaults_7_0.rb index 4281ed58b5aa..13a1e5377979 100644 --- a/back/config/initializers/new_framework_defaults_7_0.rb +++ b/back/config/initializers/new_framework_defaults_7_0.rb @@ -86,15 +86,6 @@ 'Referrer-Policy' => 'strict-origin-when-cross-origin' } -# ** Please read carefully, this must be configured in config/application.rb ** -# Change the format of the cache entry. -# Changing this default means that all new cache entries added to the cache -# will have a different format that is not supported by Rails 6.1 applications. -# Only change this value after your application is fully deployed to Rails 7.0 -# and you have no plans to rollback. -# When you're ready to change format, add this to `config/application.rb` (NOT this file): -# config.active_support.cache_format_version = 7.0 - # Cookie serializer: 2 options # # If you're upgrading and haven't set `cookies_serializer` previously, your cookie serializer @@ -123,8 +114,3 @@ # Change the return value of `ActionDispatch::Request#content_type` to the Content-Type header without modification. Rails.application.config.action_dispatch.return_only_request_media_type_on_content_type = false - -# ** Please read carefully, this must be configured in config/application.rb (NOT this file) ** -# Disables the deprecated #to_s override in some Ruby core classes -# See https://guides.rubyonrails.org/configuring.html#config-active-support-disable-to-s-conversion for more information. -# config.active_support.disable_to_s_conversion = true From d3bb3f41f89d8bf92436d491aae5e45d0ca6485f Mon Sep 17 00:00:00 2001 From: Adrien Dessy Date: Thu, 19 Dec 2024 15:11:15 +0100 Subject: [PATCH 4/8] [TAN-3184] Set cookie serializer to :json It should not have any impact since we only store strings in cookies --- .../new_framework_defaults_7_0.rb | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/back/config/initializers/new_framework_defaults_7_0.rb b/back/config/initializers/new_framework_defaults_7_0.rb index 13a1e5377979..a9c03ed11cb0 100644 --- a/back/config/initializers/new_framework_defaults_7_0.rb +++ b/back/config/initializers/new_framework_defaults_7_0.rb @@ -90,27 +90,7 @@ # # If you're upgrading and haven't set `cookies_serializer` previously, your cookie serializer # is `:marshal`. The default for new apps is `:json`. -# -# Rails.application.config.action_dispatch.cookies_serializer = :json -# -# -# To migrate an existing application to the `:json` serializer, use the `:hybrid` option. -# -# Rails transparently deserializes existing (Marshal-serialized) cookies on read and -# re-writes them in the JSON format. -# -# It is fine to use `:hybrid` long term; you should do that until you're confident *all* your cookies -# have been converted to JSON. To keep using `:hybrid` long term, move this config to its own -# initializer or to `config/application.rb`. -# -# Rails.application.config.action_dispatch.cookies_serializer = :hybrid -# -# -# If your cookies can't yet be serialized to JSON, keep using `:marshal` for backward-compatibility. -# -# If you have configured the serializer elsewhere, you can remove this section of the file. -# -# See https://guides.rubyonrails.org/action_controller_overview.html#cookies for more information. +Rails.application.config.action_dispatch.cookies_serializer = :json # Change the return value of `ActionDispatch::Request#content_type` to the Content-Type header without modification. Rails.application.config.action_dispatch.return_only_request_media_type_on_content_type = false From a289003fd556e419013632b3f4e98328a898c96f Mon Sep 17 00:00:00 2001 From: Adrien Dessy Date: Thu, 19 Dec 2024 16:00:31 +0100 Subject: [PATCH 5/8] [TAN-3184] Use the 7.0 default for active_support.use_rfc4122_namespaced_uuids --- back/config/initializers/new_framework_defaults_7_0.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/config/initializers/new_framework_defaults_7_0.rb b/back/config/initializers/new_framework_defaults_7_0.rb index a9c03ed11cb0..9bd536aa25e0 100644 --- a/back/config/initializers/new_framework_defaults_7_0.rb +++ b/back/config/initializers/new_framework_defaults_7_0.rb @@ -74,7 +74,7 @@ # # See https://guides.rubyonrails.org/configuring.html#config-active-support-use-rfc4122-namespaced-uuids for # more information. -# Rails.application.config.active_support.use_rfc4122_namespaced_uuids = true +Rails.application.config.active_support.use_rfc4122_namespaced_uuids = true # Change the default headers to disable browsers' flawed legacy XSS protection. Rails.application.config.action_dispatch.default_headers = { From 816047ecacc2b6531316d672b8d0541b1791f144 Mon Sep 17 00:00:00 2001 From: Adrien Dessy Date: Fri, 20 Dec 2024 00:39:30 +0100 Subject: [PATCH 6/8] [TAN-3184] Disable partial writes when creating new records --- back/config/application.rb | 1 + back/config/initializers/new_framework_defaults_7_0.rb | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/back/config/application.rb b/back/config/application.rb index 399143dd1504..22e64cd7b143 100644 --- a/back/config/application.rb +++ b/back/config/application.rb @@ -35,6 +35,7 @@ class Application < Rails::Application # TODO: Delete the following settings once we move to config.load_defaults 7.0 config.active_support.disable_to_s_conversion = true config.active_support.cache_format_version = 7.0 + config.active_record.partial_inserts = false # Configuration for the application, engines, and railties goes here. # diff --git a/back/config/initializers/new_framework_defaults_7_0.rb b/back/config/initializers/new_framework_defaults_7_0.rb index 9bd536aa25e0..ac9ade0c20b6 100644 --- a/back/config/initializers/new_framework_defaults_7_0.rb +++ b/back/config/initializers/new_framework_defaults_7_0.rb @@ -56,11 +56,6 @@ # Raise when running tests if fixtures contained foreign key violations Rails.application.config.active_record.verify_foreign_keys_for_fixtures = true -# Disable partial inserts. -# This default means that all columns will be referenced in INSERT queries -# regardless of whether they have a default or not. -# Rails.application.config.active_record.partial_inserts = false - # Protect from open redirect attacks in `redirect_back_or_to` and `redirect_to`. Rails.application.config.action_controller.raise_on_open_redirects = true From c87030f9e5e13271b0daa78911c2b9ba03294acc Mon Sep 17 00:00:00 2001 From: Adrien Dessy Date: Fri, 20 Dec 2024 15:08:20 +0100 Subject: [PATCH 7/8] [TAN-3184] Delete new_framework_defaults_7_0.rb and load Rails 7.0 defaults --- back/config/application.rb | 8 +- .../new_framework_defaults_7_0.rb | 91 ------------------- 2 files changed, 1 insertion(+), 98 deletions(-) delete mode 100644 back/config/initializers/new_framework_defaults_7_0.rb diff --git a/back/config/application.rb b/back/config/application.rb index 22e64cd7b143..4d378033b68f 100644 --- a/back/config/application.rb +++ b/back/config/application.rb @@ -29,13 +29,7 @@ module Cl2Back class Application < Rails::Application require_dependency Rails.root.join('lib/citizen_lab') - # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 6.1 - - # TODO: Delete the following settings once we move to config.load_defaults 7.0 - config.active_support.disable_to_s_conversion = true - config.active_support.cache_format_version = 7.0 - config.active_record.partial_inserts = false + config.load_defaults 7.0 # Configuration for the application, engines, and railties goes here. # diff --git a/back/config/initializers/new_framework_defaults_7_0.rb b/back/config/initializers/new_framework_defaults_7_0.rb deleted file mode 100644 index ac9ade0c20b6..000000000000 --- a/back/config/initializers/new_framework_defaults_7_0.rb +++ /dev/null @@ -1,91 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. -# -# This file eases your Rails 7.0 framework defaults upgrade. -# -# Uncomment each configuration one by one to switch to the new default. -# Once your application is ready to run with all new defaults, you can remove -# this file and set the `config.load_defaults` to `7.0`. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. -# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html - -# `button_to` view helper will render `