From a71b8af4d1bded364c0ba7f05c8dd851a4a19859 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 10 Dec 2020 14:44:37 +0000 Subject: [PATCH 1/3] Update to rails 6.1.3.2 --- Gemfile | 4 +- Gemfile.lock | 133 +++++++++--------- bin/setup | 6 +- bin/yarn | 18 ++- config.ru | 1 + config/cable.yml | 2 +- config/environments/development.rb | 18 ++- config/environments/production.rb | 18 ++- config/environments/test.rb | 11 ++ config/initializers/backtrace_silencers.rb | 7 +- .../initializers/filter_parameter_logging.rb | 4 +- .../new_framework_defaults_6_1.rb | 67 +++++++++ ..._to_active_storage_blobs.active_storage.rb | 13 ++ ..._storage_variant_records.active_storage.rb | 12 ++ db/structure.sql | 96 ++++++++++--- test/helpers/user_helper_test.rb | 2 +- 16 files changed, 309 insertions(+), 103 deletions(-) create mode 100644 config/initializers/new_framework_defaults_6_1.rb create mode 100644 db/migrate/20210510083027_add_service_name_to_active_storage_blobs.active_storage.rb create mode 100644 db/migrate/20210510083028_create_active_storage_variant_records.active_storage.rb diff --git a/Gemfile b/Gemfile index 69a97f3702..2802fe3ad9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" # Require rails -gem "rails", "6.0.3.7" +gem "rails", "6.1.3.2" # Require json for multi_json gem "json" @@ -40,7 +40,7 @@ gem "active_record_union" gem "bootstrap", "~> 4.5.0" gem "bootstrap_form", "~> 4.0" gem "cancancan" -gem "composite_primary_keys", "~> 12.0.0" +gem "composite_primary_keys", "~> 13.0.0" gem "config" gem "delayed_job_active_record" gem "http_accept_language", "~> 2.1.1" diff --git a/Gemfile.lock b/Gemfile.lock index fb345ac72e..fb3ac9cb92 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,67 +3,71 @@ GEM specs: aasm (5.2.0) concurrent-ruby (~> 1.0) - actioncable (6.0.3.7) - actionpack (= 6.0.3.7) + actioncable (6.1.3.2) + actionpack (= 6.1.3.2) + activesupport (= 6.1.3.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.0.3.7) - actionpack (= 6.0.3.7) - activejob (= 6.0.3.7) - activerecord (= 6.0.3.7) - activestorage (= 6.0.3.7) - activesupport (= 6.0.3.7) + actionmailbox (6.1.3.2) + actionpack (= 6.1.3.2) + activejob (= 6.1.3.2) + activerecord (= 6.1.3.2) + activestorage (= 6.1.3.2) + activesupport (= 6.1.3.2) mail (>= 2.7.1) - actionmailer (6.0.3.7) - actionpack (= 6.0.3.7) - actionview (= 6.0.3.7) - activejob (= 6.0.3.7) + actionmailer (6.1.3.2) + actionpack (= 6.1.3.2) + actionview (= 6.1.3.2) + activejob (= 6.1.3.2) + activesupport (= 6.1.3.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.0.3.7) - actionview (= 6.0.3.7) - activesupport (= 6.0.3.7) - rack (~> 2.0, >= 2.0.8) + actionpack (6.1.3.2) + actionview (= 6.1.3.2) + activesupport (= 6.1.3.2) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) actionpack-page_caching (1.2.3) actionpack (>= 5.0.0) - actiontext (6.0.3.7) - actionpack (= 6.0.3.7) - activerecord (= 6.0.3.7) - activestorage (= 6.0.3.7) - activesupport (= 6.0.3.7) + actiontext (6.1.3.2) + actionpack (= 6.1.3.2) + activerecord (= 6.1.3.2) + activestorage (= 6.1.3.2) + activesupport (= 6.1.3.2) nokogiri (>= 1.8.5) - actionview (6.0.3.7) - activesupport (= 6.0.3.7) + actionview (6.1.3.2) + activesupport (= 6.1.3.2) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) active_record_union (1.3.0) activerecord (>= 4.0) - activejob (6.0.3.7) - activesupport (= 6.0.3.7) + activejob (6.1.3.2) + activesupport (= 6.1.3.2) globalid (>= 0.3.6) - activemodel (6.0.3.7) - activesupport (= 6.0.3.7) - activerecord (6.0.3.7) - activemodel (= 6.0.3.7) - activesupport (= 6.0.3.7) + activemodel (6.1.3.2) + activesupport (= 6.1.3.2) + activerecord (6.1.3.2) + activemodel (= 6.1.3.2) + activesupport (= 6.1.3.2) activerecord-import (1.0.8) activerecord (>= 3.2) - activestorage (6.0.3.7) - actionpack (= 6.0.3.7) - activejob (= 6.0.3.7) - activerecord (= 6.0.3.7) + activestorage (6.1.3.2) + actionpack (= 6.1.3.2) + activejob (= 6.1.3.2) + activerecord (= 6.1.3.2) + activesupport (= 6.1.3.2) marcel (~> 1.0.0) - activesupport (6.0.3.7) + mini_mime (~> 1.0.2) + activesupport (6.1.3.2) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) annotate (3.1.1) @@ -129,8 +133,8 @@ GEM xpath (~> 3.2) childprocess (3.0.0) coderay (1.1.3) - composite_primary_keys (12.0.10) - activerecord (~> 6.0.0) + composite_primary_keys (13.0.0) + activerecord (~> 6.1.0) concurrent-ruby (1.1.8) config (3.1.0) deep_merge (~> 1.2, >= 1.2.1) @@ -263,7 +267,7 @@ GEM maxminddb (0.1.22) method_source (1.0.0) mini_magick (4.11.0) - mini_mime (1.1.0) + mini_mime (1.0.3) mini_portile2 (2.5.1) minitest (5.14.4) msgpack (1.4.2) @@ -344,20 +348,20 @@ GEM rack-test (1.1.0) rack (>= 1.0, < 3) rack-uri_sanitizer (0.0.2) - rails (6.0.3.7) - actioncable (= 6.0.3.7) - actionmailbox (= 6.0.3.7) - actionmailer (= 6.0.3.7) - actionpack (= 6.0.3.7) - actiontext (= 6.0.3.7) - actionview (= 6.0.3.7) - activejob (= 6.0.3.7) - activemodel (= 6.0.3.7) - activerecord (= 6.0.3.7) - activestorage (= 6.0.3.7) - activesupport (= 6.0.3.7) - bundler (>= 1.3.0) - railties (= 6.0.3.7) + rails (6.1.3.2) + actioncable (= 6.1.3.2) + actionmailbox (= 6.1.3.2) + actionmailer (= 6.1.3.2) + actionpack (= 6.1.3.2) + actiontext (= 6.1.3.2) + actionview (= 6.1.3.2) + activejob (= 6.1.3.2) + activemodel (= 6.1.3.2) + activerecord (= 6.1.3.2) + activestorage (= 6.1.3.2) + activesupport (= 6.1.3.2) + bundler (>= 1.15.0) + railties (= 6.1.3.2) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -371,12 +375,12 @@ GEM rails-i18n (6.0.0) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 7) - railties (6.0.3.7) - actionpack (= 6.0.3.7) - activesupport (= 6.0.3.7) + railties (6.1.3.2) + actionpack (= 6.1.3.2) + activesupport (= 6.1.3.2) method_source rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) + thor (~> 1.0) rainbow (3.0.0) rake (13.0.3) rb-fsevent (0.11.0) @@ -448,10 +452,9 @@ GEM strong_migrations (0.7.6) activerecord (>= 5) thor (1.1.0) - thread_safe (0.3.6) tilt (2.0.10) - tzinfo (1.2.9) - thread_safe (~> 0.1) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) unicode-display_width (2.0.0) @@ -491,7 +494,7 @@ DEPENDENCIES cancancan canonical-rails capybara (>= 2.15) - composite_primary_keys (~> 12.0.0) + composite_primary_keys (~> 13.0.0) config dalli debug_inspector @@ -533,7 +536,7 @@ DEPENDENCIES r2 (~> 0.2.7) rack-cors rack-uri_sanitizer - rails (= 6.0.3.7) + rails (= 6.1.3.2) rails-controller-testing rails-i18n (~> 6.0.0) rinku (>= 2.0.6) diff --git a/bin/setup b/bin/setup index 9944e82a33..d0b0fbd57e 100755 --- a/bin/setup +++ b/bin/setup @@ -9,8 +9,8 @@ def system!(*args) end FileUtils.chdir APP_ROOT do - # This script is a way to setup or update your development environment automatically. - # This script is idempotent, so that you can run it at anytime and get an expectable outcome. + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. puts "== Installing dependencies ==" @@ -18,7 +18,7 @@ FileUtils.chdir APP_ROOT do system("bundle check") || system!("bundle install") # Install JavaScript dependencies - # system('bin/yarn') + system! "bin/yarn" # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') diff --git a/bin/yarn b/bin/yarn index 99e5e77285..be76eec945 100755 --- a/bin/yarn +++ b/bin/yarn @@ -1,9 +1,17 @@ #!/usr/bin/env ruby APP_ROOT = File.expand_path("..", __dir__) Dir.chdir(APP_ROOT) do - exec "yarnpkg", *ARGV -rescue Errno::ENOENT - warn "Yarn executable was not detected in the system." - warn "Download Yarn at https://yarnpkg.com/en/docs/install" - exit 1 + yarn = ENV["PATH"].split(File::PATH_SEPARATOR) + .reject { |dir| File.expand_path(dir) == __dir__ } + .product(["yarnpkg", "yarn", "yarn.cmd", "yarn.ps1"]) + .map { |dir, file| File.expand_path(file, dir) } + .find { |file| File.executable?(file) } + + if yarn + exec yarn, *ARGV + else + warn "Yarn executable was not detected in the system." + warn "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end end diff --git a/config.ru b/config.ru index 441e6ff0c3..4a3c09a688 100644 --- a/config.ru +++ b/config.ru @@ -3,3 +3,4 @@ require_relative "config/environment" run Rails.application +Rails.application.load_server diff --git a/config/cable.yml b/config/cable.yml index c1ae78f925..5f693d66dc 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -2,7 +2,7 @@ development: adapter: async test: - adapter: async + adapter: test production: adapter: redis diff --git a/config/environments/development.rb b/config/environments/development.rb index 778e629eb4..ebdc959e9f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,8 +1,10 @@ +require "active_support/core_ext/integer/time" + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false @@ -39,6 +41,12 @@ # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load unless Settings.status == "database_offline" @@ -59,10 +67,16 @@ # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true + # Disable host validation. config.hosts = [] end diff --git a/config/environments/production.rb b/config/environments/production.rb index c0729067d6..fb0c53b974 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +require "active_support/core_ext/integer/time" + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -30,7 +32,7 @@ config.assets.compile = false # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' + # config.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache @@ -47,8 +49,8 @@ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. + # Include generic and useful information about system operation, but avoid logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). config.log_level = :info # Prepend all log lines with the following tags. @@ -73,9 +75,19 @@ # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify + # Log disallowed deprecations. + config.active_support.disallowed_deprecation = :log + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new diff --git a/config/environments/test.rb b/config/environments/test.rb index fad06fe51c..085381780f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +require "active_support/core_ext/integer/time" + # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped @@ -43,12 +45,21 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + # Export translations automatically. config.middleware.use I18n::JS::Middleware # Raises error for missing translations. config.action_view.raise_on_missing_translations = true + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + # Use the test adapter for ActiveJob during testing. config.active_job.queue_adapter = :test end diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cdf37..33699c3091 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,7 +1,8 @@ # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } +# Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) } -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. -# Rails.backtrace_cleaner.remove_silencers! +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code +# by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". +Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 8eb234f431..58aa62573f 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,6 @@ # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password, :pass_crypt, :pass_crypt_confirmation] +Rails.application.config.filter_parameters += [ + :password, :pass_crypt, :pass_crypt_confirmation +] diff --git a/config/initializers/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb new file mode 100644 index 0000000000..9526b835ab --- /dev/null +++ b/config/initializers/new_framework_defaults_6_1.rb @@ -0,0 +1,67 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 6.1 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Support for inversing belongs_to -> has_many Active Record associations. +# Rails.application.config.active_record.has_many_inversing = true + +# Track Active Storage variants in the database. +# Rails.application.config.active_storage.track_variants = true + +# Apply random variation to the delay when retrying failed jobs. +# Rails.application.config.active_job.retry_jitter = 0.15 + +# Stop executing `after_enqueue`/`after_perform` callbacks if +# `before_enqueue`/`before_perform` respectively halts with `throw :abort`. +# Rails.application.config.active_job.skip_after_callbacks_if_terminated = true + +# Specify cookies SameSite protection level: either :none, :lax, or :strict. +# +# This change is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.1. +# Rails.application.config.action_dispatch.cookies_same_site_protection = :lax + +# Generate CSRF tokens that are encoded in URL-safe Base64. +# +# This change is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.1. +# Rails.application.config.action_controller.urlsafe_csrf_tokens = true + +# Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an +# UTC offset or a UTC time. +# ActiveSupport.utc_to_local_returns_utc_offset_times = true + +# Change the default HTTP status code to `308` when redirecting non-GET/HEAD +# requests to HTTPS in `ActionDispatch::SSL` middleware. +# Rails.application.config.action_dispatch.ssl_default_redirect_status = 308 + +# Use new connection handling API. For most applications this won't have any +# effect. For applications using multiple databases, this new API provides +# support for granular connection swapping. +# Rails.application.config.active_record.legacy_connection_handling = false + +# Make `form_with` generate non-remote forms by default. +# Rails.application.config.action_view.form_with_generates_remote_forms = false + +# Set the default queue name for the analysis job to the queue adapter default. +# Rails.application.config.active_storage.queues.analysis = nil + +# Set the default queue name for the purge job to the queue adapter default. +# Rails.application.config.active_storage.queues.purge = nil + +# Set the default queue name for the incineration job to the queue adapter default. +# Rails.application.config.action_mailbox.queues.incineration = nil + +# Set the default queue name for the routing job to the queue adapter default. +# Rails.application.config.action_mailbox.queues.routing = nil + +# Set the default queue name for the mail deliver job to the queue adapter default. +# Rails.application.config.action_mailer.deliver_later_queue_name = nil + +# Generate a `Link` header that gives a hint to modern browsers about +# preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`. +# Rails.application.config.action_view.preload_links_header = true diff --git a/db/migrate/20210510083027_add_service_name_to_active_storage_blobs.active_storage.rb b/db/migrate/20210510083027_add_service_name_to_active_storage_blobs.active_storage.rb new file mode 100644 index 0000000000..97a1ff2b67 --- /dev/null +++ b/db/migrate/20210510083027_add_service_name_to_active_storage_blobs.active_storage.rb @@ -0,0 +1,13 @@ +# This migration comes from active_storage (originally 20190112182829) +class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0] + def up + unless column_exists?(:active_storage_blobs, :service_name) + add_column :active_storage_blobs, :service_name, :string, :null => false, :default => ActiveStorage::Blob.service.name + change_column :active_storage_blobs, :service_name, :string, :null => false, :default => nil + end + end + + def down + remove_column :active_storage_blobs, :service_name + end +end diff --git a/db/migrate/20210510083028_create_active_storage_variant_records.active_storage.rb b/db/migrate/20210510083028_create_active_storage_variant_records.active_storage.rb new file mode 100644 index 0000000000..07b2cd5ebf --- /dev/null +++ b/db/migrate/20210510083028_create_active_storage_variant_records.active_storage.rb @@ -0,0 +1,12 @@ +# This migration comes from active_storage (originally 20191206030411) +class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0] + def change + create_table :active_storage_variant_records do |t| + t.belongs_to :blob, :null => false, :index => false + t.string :variation_digest, :null => false + + t.index [:blob_id, :variation_digest], :name => "index_active_storage_variant_records_uniqueness", :unique => true + t.foreign_key :active_storage_blobs, :column => :blob_id + end + end +end diff --git a/db/structure.sql b/db/structure.sql index 957dee817f..53202f2d8f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1,5 +1,6 @@ SET statement_timeout = 0; SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SELECT pg_catalog.set_config('search_path', '', false); @@ -8,20 +9,6 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; --- --- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; - - --- --- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; - - -- -- Name: btree_gist; Type: EXTENSION; Schema: -; Owner: - -- @@ -165,7 +152,7 @@ $$; -- CREATE FUNCTION public.xid_to_int4(t xid) RETURNS integer - LANGUAGE plpgsql STRICT + LANGUAGE plpgsql IMMUTABLE STRICT AS $$ DECLARE tl bigint; @@ -186,7 +173,7 @@ $$; SET default_tablespace = ''; -SET default_with_oids = false; +SET default_table_access_method = heap; -- -- Name: acls; Type: TABLE; Schema: public; Owner: - @@ -266,7 +253,8 @@ CREATE TABLE public.active_storage_blobs ( metadata text, byte_size bigint NOT NULL, checksum character varying NOT NULL, - created_at timestamp without time zone NOT NULL + created_at timestamp without time zone NOT NULL, + service_name character varying NOT NULL ); @@ -289,6 +277,36 @@ CREATE SEQUENCE public.active_storage_blobs_id_seq ALTER SEQUENCE public.active_storage_blobs_id_seq OWNED BY public.active_storage_blobs.id; +-- +-- Name: active_storage_variant_records; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.active_storage_variant_records ( + id bigint NOT NULL, + blob_id bigint NOT NULL, + variation_digest character varying NOT NULL +); + + +-- +-- Name: active_storage_variant_records_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.active_storage_variant_records_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: active_storage_variant_records_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.active_storage_variant_records_id_seq OWNED BY public.active_storage_variant_records.id; + + -- -- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: - -- @@ -320,6 +338,7 @@ CREATE TABLE public.changeset_comments ( -- CREATE SEQUENCE public.changeset_comments_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -421,6 +440,7 @@ CREATE TABLE public.client_applications ( -- CREATE SEQUENCE public.client_applications_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -846,6 +866,7 @@ CREATE TABLE public.issue_comments ( -- CREATE SEQUENCE public.issue_comments_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -885,6 +906,7 @@ CREATE TABLE public.issues ( -- CREATE SEQUENCE public.issues_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -997,6 +1019,7 @@ CREATE TABLE public.note_comments ( -- CREATE SEQUENCE public.note_comments_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1032,6 +1055,7 @@ CREATE TABLE public.notes ( -- CREATE SEQUENCE public.notes_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1064,6 +1088,7 @@ CREATE TABLE public.oauth_nonces ( -- CREATE SEQUENCE public.oauth_nonces_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1112,6 +1137,7 @@ CREATE TABLE public.oauth_tokens ( -- CREATE SEQUENCE public.oauth_tokens_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1146,6 +1172,7 @@ CREATE TABLE public.redactions ( -- CREATE SEQUENCE public.redactions_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1220,6 +1247,7 @@ CREATE TABLE public.reports ( -- CREATE SEQUENCE public.reports_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1266,6 +1294,7 @@ CREATE TABLE public.user_blocks ( -- CREATE SEQUENCE public.user_blocks_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1310,6 +1339,7 @@ CREATE TABLE public.user_roles ( -- CREATE SEQUENCE public.user_roles_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1471,6 +1501,13 @@ ALTER TABLE ONLY public.active_storage_attachments ALTER COLUMN id SET DEFAULT n ALTER TABLE ONLY public.active_storage_blobs ALTER COLUMN id SET DEFAULT nextval('public.active_storage_blobs_id_seq'::regclass); +-- +-- Name: active_storage_variant_records id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.active_storage_variant_records ALTER COLUMN id SET DEFAULT nextval('public.active_storage_variant_records_id_seq'::regclass); + + -- -- Name: changeset_comments id; Type: DEFAULT; Schema: public; Owner: - -- @@ -1670,6 +1707,14 @@ ALTER TABLE ONLY public.active_storage_blobs ADD CONSTRAINT active_storage_blobs_pkey PRIMARY KEY (id); +-- +-- Name: active_storage_variant_records active_storage_variant_records_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.active_storage_variant_records + ADD CONSTRAINT active_storage_variant_records_pkey PRIMARY KEY (id); + + -- -- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2224,6 +2269,13 @@ CREATE UNIQUE INDEX index_active_storage_attachments_uniqueness ON public.active CREATE UNIQUE INDEX index_active_storage_blobs_on_key ON public.active_storage_blobs USING btree (key); +-- +-- Name: index_active_storage_variant_records_uniqueness; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_active_storage_variant_records_uniqueness ON public.active_storage_variant_records USING btree (blob_id, variation_digest); + + -- -- Name: index_changeset_comments_on_changeset_id_and_created_at; Type: INDEX; Schema: public; Owner: - -- @@ -2750,6 +2802,14 @@ ALTER TABLE ONLY public.diary_entry_subscriptions ADD CONSTRAINT diary_entry_subscriptions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id); +-- +-- Name: active_storage_variant_records fk_rails_993965df05; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.active_storage_variant_records + ADD CONSTRAINT fk_rails_993965df05 FOREIGN KEY (blob_id) REFERENCES public.active_storage_blobs(id); + + -- -- Name: active_storage_attachments fk_rails_c3b3935057; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -3124,6 +3184,8 @@ INSERT INTO "schema_migrations" (version) VALUES ('20201006213836'), ('20201006220807'), ('20201214144017'), +('20210510083027'), +('20210510083028'), ('20210511104518'), ('21'), ('22'), diff --git a/test/helpers/user_helper_test.rb b/test/helpers/user_helper_test.rb index 6170e3a489..a378ad5b0f 100644 --- a/test/helpers/user_helper_test.rb +++ b/test/helpers/user_helper_test.rb @@ -60,7 +60,7 @@ def test_user_image_url gravatar_user = create(:user, :image_use_gravatar => true) url = user_image_url(user) - assert_match %r{^http://test.host/rails/active_storage/representations/[^/]+/[^/]+/a.gif$}, url + assert_match %r{^http://test.host/rails/active_storage/representations/redirect/[^/]+/[^/]+/a.gif$}, url url = user_image_url(gravatar_user) assert_match %r{^http://www.gravatar.com/avatar/}, url From bf851691bf3eb9999e5624a04eef00db5800f5f0 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 29 Dec 2020 22:36:26 +0000 Subject: [PATCH 2/3] Fix deprecation warnings --- app/controllers/application_controller.rb | 2 +- config/environments/development.rb | 2 +- config/environments/test.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d571535d35..b4c0fbc23f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -208,7 +208,7 @@ def api_call_handle_error report_error e.message, :bad_request rescue ActiveRecord::RecordInvalid => e message = "#{e.record.class} #{e.record.id}: " - e.record.errors.each { |attr, msg| message << "#{attr}: #{msg} (#{e.record[attr].inspect})" } + e.record.errors.each { |error| message << "#{error.attribute}: #{error.message} (#{e.record[error.attribute].inspect})" } report_error message, :bad_request rescue OSM::APIError => e report_error e.message, e.status diff --git a/config/environments/development.rb b/config/environments/development.rb index ebdc959e9f..ab4f002200 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -65,7 +65,7 @@ config.middleware.use I18n::JS::Middleware # Raises error for missing translations. - # config.action_view.raise_on_missing_translations = true + # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true diff --git a/config/environments/test.rb b/config/environments/test.rb index 085381780f..007f2a3b4f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -55,7 +55,7 @@ config.middleware.use I18n::JS::Middleware # Raises error for missing translations. - config.action_view.raise_on_missing_translations = true + config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true From cd5d54ce4e65629facc964c3d6f870ced244f797 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 11 May 2021 20:28:20 +0100 Subject: [PATCH 3/3] Use image_processing macros to resize images --- Gemfile | 2 +- Gemfile.lock | 7 ++++++- app/helpers/user_helper.rb | 8 ++++---- app/mailers/user_mailer.rb | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 2802fe3ad9..fd1df513cc 100644 --- a/Gemfile +++ b/Gemfile @@ -117,7 +117,7 @@ gem "browser" gem "aws-sdk-s3" # Used to resize user images -gem "mini_magick" +gem "image_processing" # Gems useful for development group :development do diff --git a/Gemfile.lock b/Gemfile.lock index fb3ac9cb92..af52b2d01e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -237,6 +237,9 @@ GEM image_optim (~> 0.24) rails sprockets + image_processing (1.12.1) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) image_size (2.1.0) in_threads (1.5.4) jbuilder (2.11.2) @@ -416,6 +419,8 @@ GEM rubocop ruby-openid (2.9.2) ruby-progressbar (1.11.0) + ruby-vips (2.1.2) + ffi (~> 1.12) ruby2_keywords (0.0.4) rubyzip (2.3.0) sanitize (5.2.3) @@ -508,6 +513,7 @@ DEPENDENCIES http_accept_language (~> 2.1.1) i18n-js (>= 3.0.0) image_optim_rails + image_processing jbuilder (~> 2.7) jquery-rails json @@ -518,7 +524,6 @@ DEPENDENCIES logstasher marcel maxminddb - mini_magick minitest (~> 5.1) oauth-plugin (>= 0.5.1) omniauth (~> 2.0.2) diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index e9e8f6bfb1..69b0f6d6bc 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -8,7 +8,7 @@ def user_image(user, options = {}) if user.image_use_gravatar user_gravatar_tag(user, options) elsif user.avatar.attached? - image_tag user_avatar_variant(user, :resize => "100x100>"), options + image_tag user_avatar_variant(user, :resize_to_limit => [100, 100]), options else image_tag "avatar_large.png", options end @@ -21,7 +21,7 @@ def user_thumbnail(user, options = {}) if user.image_use_gravatar user_gravatar_tag(user, options) elsif user.avatar.attached? - image_tag user_avatar_variant(user, :resize => "50x50>"), options + image_tag user_avatar_variant(user, :resize_to_limit => [50, 50]), options else image_tag "avatar_small.png", options end @@ -34,7 +34,7 @@ def user_thumbnail_tiny(user, options = {}) if user.image_use_gravatar user_gravatar_tag(user, options) elsif user.avatar.attached? - image_tag user_avatar_variant(user, :resize => "50x50>"), options + image_tag user_avatar_variant(user, :resize_to_limit => [50, 50]), options else image_tag "avatar_small.png", options end @@ -44,7 +44,7 @@ def user_image_url(user, options = {}) if user.image_use_gravatar user_gravatar_url(user, options) elsif user.avatar.attached? - polymorphic_url(user_avatar_variant(user, :resize => "100x100>"), :host => Settings.server_url) + polymorphic_url(user_avatar_variant(user, :resize_to_limit => [100, 100]), :host => Settings.server_url) else image_url("avatar_large.png") end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 0664b8475e..ae176c321e 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -194,7 +194,7 @@ def user_avatar_file(user) avatar = user&.avatar if avatar&.attached? if avatar.variable? - image = avatar.variant(:resize => "50x50>").processed + image = avatar.variant(:resize_to_limit => [50, 50]).processed image.service.download(image.key) else avatar.blob.download