From b59f6547feb654d649f8f9f27e3d8e128e4b8b68 Mon Sep 17 00:00:00 2001 From: Danyil Shkoropad <31440971+anko20094@users.noreply.github.com> Date: Thu, 27 Oct 2022 22:52:19 +0300 Subject: [PATCH] Migration to rails 7 + update gems (#15) --- Gemfile | 15 +- Gemfile.lock | 248 +++---- app/javascript/scripts/select2.js | 62 -- app/models/user.rb | 10 +- app/packs/scripts/select.js | 11 +- app/validators/email_validator.rb | 12 + bin/rails | 4 +- bin/rake | 2 +- bin/setup | 23 +- config/application.rb | 2 +- config/boot.rb | 8 +- config/environment.rb | 4 +- config/environments/development.rb | 18 +- config/environments/production.rb | 58 +- config/environments/test.rb | 15 +- .../initializers/content_security_policy.rb | 48 +- .../initializers/filter_parameter_logging.rb | 10 +- config/initializers/inflections.rb | 9 +- .../new_framework_defaults_7_0.rb | 135 ++++ config/initializers/permissions_policy.rb | 1 - ..._to_active_storage_blobs.active_storage.rb | 22 + ..._storage_variant_records.active_storage.rb | 27 + ...e_storage_blobs_checksum.active_storage.rb | 8 + db/schema.rb | 37 +- package.json | 4 +- yarn.lock | 674 +++++++++--------- 26 files changed, 799 insertions(+), 668 deletions(-) delete mode 100644 app/javascript/scripts/select2.js create mode 100644 app/validators/email_validator.rb create mode 100644 config/initializers/new_framework_defaults_7_0.rb create mode 100644 db/migrate/20221027190626_add_service_name_to_active_storage_blobs.active_storage.rb create mode 100644 db/migrate/20221027190627_create_active_storage_variant_records.active_storage.rb create mode 100644 db/migrate/20221027190628_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb diff --git a/Gemfile b/Gemfile index 0e86b81..9b57751 100644 --- a/Gemfile +++ b/Gemfile @@ -6,11 +6,11 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '3.0.3' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' -gem 'rails', '~> 6.1.3', '>= 6.1.3.2' +gem 'rails', '~> 7.0', '>= 7.0.4' # Use sqlite3 as the database for Active Record gem 'sqlite3', '~> 1.4' # Use Puma as the app server -gem 'puma', '~> 5.0' +gem 'puma', '~> 6.0' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem 'webpacker', '6.0.0.rc.6' @@ -28,15 +28,14 @@ gem 'caxlsx', '~> 3.1' gem 'caxlsx_rails', '~> 0.6' gem 'dotenv-rails', '~> 2.7' gem 'draper', '~> 4.0' -gem 'i18n-tasks', '~> 0.9.34' -gem 'lokalise_rails', '~> 3' +gem 'i18n-tasks', '~> 1.0', '>= 1.0.12' +gem 'lokalise_rails', '~> 5.1' gem 'pagy', '~> 5.0' gem 'pundit', '~> 2.1' -gem 'rails-i18n', '~> 6' +gem 'rails-i18n', '~> 7.0', '>= 7.0.5' gem 'rubyXL', '~> 3.4' gem 'rubyzip', '~> 2' -gem 'sidekiq', '~> 6.5', '>= 6.5.7' -gem 'valid_email2', '~> 4.0' +gem 'sidekiq', '~> 7.0' # Use Active Storage variant # gem 'image_processing', '~> 1.2' @@ -58,7 +57,7 @@ group :development do # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md gem 'bullet' gem 'letter_opener' - gem 'rack-mini-profiler', '~> 2.0' + gem 'rack-mini-profiler', '~> 3.0' gem 'rubocop', '~> 1.18', require: false gem 'rubocop-i18n', '~> 3', require: false gem 'rubocop-performance', '~> 1.11', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 270a0e7..170b745 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,75 +1,88 @@ GEM remote: https://rubygems.org/ specs: - actioncable (6.1.7) - actionpack (= 6.1.7) - activesupport (= 6.1.7) + actioncable (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7) - actionpack (= 6.1.7) - activejob (= 6.1.7) - activerecord (= 6.1.7) - activestorage (= 6.1.7) - activesupport (= 6.1.7) + actionmailbox (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) mail (>= 2.7.1) - actionmailer (6.1.7) - actionpack (= 6.1.7) - actionview (= 6.1.7) - activejob (= 6.1.7) - activesupport (= 6.1.7) + net-imap + net-pop + net-smtp + actionmailer (7.0.4) + actionpack (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activesupport (= 7.0.4) mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp rails-dom-testing (~> 2.0) - actionpack (6.1.7) - actionview (= 6.1.7) - activesupport (= 6.1.7) - rack (~> 2.0, >= 2.0.9) + actionpack (7.0.4) + actionview (= 7.0.4) + activesupport (= 7.0.4) + rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.7) - actionpack (= 6.1.7) - activerecord (= 6.1.7) - activestorage (= 6.1.7) - activesupport (= 6.1.7) + actiontext (7.0.4) + actionpack (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.7) - activesupport (= 6.1.7) + actionview (7.0.4) + activesupport (= 7.0.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.7) - activesupport (= 6.1.7) + activejob (7.0.4) + activesupport (= 7.0.4) globalid (>= 0.3.6) - activemodel (6.1.7) - activesupport (= 6.1.7) + activemodel (7.0.4) + activesupport (= 7.0.4) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (6.1.7) - activemodel (= 6.1.7) - activesupport (= 6.1.7) + activerecord (7.0.4) + activemodel (= 7.0.4) + activesupport (= 7.0.4) activerecord-import (1.4.1) activerecord (>= 4.2) - activestorage (6.1.7) - actionpack (= 6.1.7) - activejob (= 6.1.7) - activerecord (= 6.1.7) - activesupport (= 6.1.7) + activestorage (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activesupport (= 7.0.4) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.7) + activesupport (7.0.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) ast (2.4.2) bcrypt (3.1.18) + better_html (2.0.1) + actionview (>= 6.0) + activesupport (>= 6.0) + ast (~> 2.0) + erubi (~> 1.4) + parser (>= 2.4) + smart_properties bindex (0.8.1) blueprinter (0.25.3) bootsnap (1.13.0) @@ -79,7 +92,7 @@ GEM activesupport (>= 3.0.0) uniform_notifier (~> 1.11) byebug (11.1.3) - caxlsx (3.2.0) + caxlsx (3.3.0) htmlentities (~> 4.3, >= 4.3.4) marcel (~> 1.0) nokogiri (~> 1.10, >= 1.10.4) @@ -105,40 +118,23 @@ GEM erubi (1.11.0) faker (2.23.0) i18n (>= 1.8.11, < 2) - faraday (1.10.2) - faraday-em_http (~> 1.0) - faraday-em_synchrony (~> 1.0) - faraday-excon (~> 1.1) - faraday-httpclient (~> 1.0) - faraday-multipart (~> 1.0) - faraday-net_http (~> 1.0) - faraday-net_http_persistent (~> 1.0) - faraday-patron (~> 1.0) - faraday-rack (~> 1.0) - faraday-retry (~> 1.0) + faraday (2.6.0) + faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) - faraday-em_http (1.0.0) - faraday-em_synchrony (1.0.0) - faraday-excon (1.1.0) - faraday-httpclient (1.0.1) - faraday-multipart (1.0.4) - multipart-post (~> 2) - faraday-net_http (1.0.1) - faraday-net_http_persistent (1.2.0) - faraday-patron (1.0.0) - faraday-rack (1.0.0) - faraday-retry (1.0.3) - faraday_middleware (1.2.0) - faraday (~> 1.0) + faraday-gzip (0.1.0) + faraday (>= 1.0) + zlib (~> 2.1) + faraday-net_http (3.0.1) globalid (1.0.0) activesupport (>= 5.0) highline (2.0.3) htmlentities (4.3.4) i18n (1.12.0) concurrent-ruby (~> 1.0) - i18n-tasks (0.9.37) + i18n-tasks (1.0.12) activesupport (>= 4.0.2) ast (>= 2.1.0) + better_html (>= 1.0, < 3.0) erubi highline (>= 2.0.0) i18n @@ -151,11 +147,13 @@ GEM addressable (~> 2.7) letter_opener (1.8.1) launchy (>= 2.2, < 3) - lokalise_manager (1.2.1) - ruby-lokalise-api (~> 4.0) + lokalise_manager (3.2.0) + ruby-lokalise-api (~> 6.0) rubyzip (~> 2.3) - lokalise_rails (3.0.0) - lokalise_manager (~> 1.0) + zeitwerk (~> 2.4) + lokalise_rails (5.1.0) + lokalise_manager (~> 3.2) + zeitwerk (~> 2.4) loofah (2.19.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -166,11 +164,18 @@ GEM mini_mime (1.1.2) minitest (5.16.3) msgpack (1.6.0) - multipart-post (2.2.3) + net-imap (0.3.1) + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.1.3) + timeout + net-smtp (0.3.2) + net-protocol nio4r (2.5.8) - nokogiri (1.13.8-x64-mingw32) + nokogiri (1.13.9-x64-mingw32) racc (~> 1.4) - nokogiri (1.13.8-x86_64-linux) + nokogiri (1.13.9-x86_64-linux) racc (~> 1.4) pagy (5.10.1) activesupport @@ -183,80 +188,82 @@ GEM pry-rails (0.3.9) pry (>= 0.10.4) public_suffix (5.0.0) - puma (5.6.5) + puma (6.0.0) nio4r (~> 2.0) pundit (2.2.0) activesupport (>= 3.0.0) racc (1.6.0) rack (2.2.4) - rack-mini-profiler (2.3.4) + rack-mini-profiler (3.0.0) rack (>= 1.2.0) rack-proxy (0.7.4) rack rack-test (2.0.2) rack (>= 1.3) - rails (6.1.7) - actioncable (= 6.1.7) - actionmailbox (= 6.1.7) - actionmailer (= 6.1.7) - actionpack (= 6.1.7) - actiontext (= 6.1.7) - actionview (= 6.1.7) - activejob (= 6.1.7) - activemodel (= 6.1.7) - activerecord (= 6.1.7) - activestorage (= 6.1.7) - activesupport (= 6.1.7) + rails (7.0.4) + actioncable (= 7.0.4) + actionmailbox (= 7.0.4) + actionmailer (= 7.0.4) + actionpack (= 7.0.4) + actiontext (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activemodel (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) bundler (>= 1.15.0) - railties (= 6.1.7) - sprockets-rails (>= 2.0.0) + railties (= 7.0.4) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.4.3) loofah (~> 2.3) - rails-i18n (6.0.0) + rails-i18n (7.0.5) i18n (>= 0.7, < 2) - railties (>= 6.0.0, < 7) - railties (6.1.7) - actionpack (= 6.1.7) - activesupport (= 6.1.7) + railties (>= 6.0.0, < 8) + railties (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) method_source rake (>= 12.2) thor (~> 1.0) + zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) - redis (4.8.0) + redis-client (0.10.0) + connection_pool regexp_parser (2.6.0) request_store (1.5.1) rack (>= 1.4) rexml (3.2.5) - rubocop (1.36.0) + rubocop (1.37.1) json (~> 2.3) parallel (~> 1.10) parser (>= 3.1.2.1) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.20.1, < 2.0) + rubocop-ast (>= 1.23.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.22.0) + rubocop-ast (1.23.0) parser (>= 3.1.1.0) rubocop-i18n (3.0.0) rubocop (~> 1.0) rubocop-performance (1.15.0) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) - rubocop-rails (2.16.1) + rubocop-rails (2.17.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) - ruby-lokalise-api (4.5.1) + ruby-lokalise-api (6.2.0) addressable (~> 2.5) - faraday (~> 1.0) - faraday_middleware (~> 1.0) - json (>= 1.8.0) + faraday (~> 2.0) + faraday-gzip (~> 0.1) + json (~> 2) + zeitwerk (~> 2.4) ruby-progressbar (1.11.0) ruby2_keywords (0.0.5) rubyXL (3.4.25) @@ -264,31 +271,24 @@ GEM rubyzip (>= 1.3.0) rubyzip (2.3.2) semantic_range (3.0.0) - sidekiq (6.5.7) - connection_pool (>= 2.2.5) - rack (~> 2.0) - redis (>= 4.5.0, < 5) - sprockets (4.1.1) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) + sidekiq (7.0.0) + concurrent-ruby (< 2) + connection_pool (>= 2.3.0) + rack (>= 2.2.4) + redis-client (>= 0.9.0) + smart_properties (1.17.0) sqlite3 (1.5.3-x64-mingw32) sqlite3 (1.5.3-x86_64-linux) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) thor (1.2.1) + timeout (0.3.0) tzinfo (2.0.5) concurrent-ruby (~> 1.0) tzinfo-data (1.2022.5) tzinfo (>= 1.0.0) unicode-display_width (2.3.0) uniform_notifier (1.16.0) - valid_email2 (4.0.4) - activemodel (>= 3.2) - mail (~> 2.5) web-console (4.2.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -303,6 +303,7 @@ GEM websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) zeitwerk (2.6.1) + zlib (2.1.1) PLATFORMS x64-mingw32 @@ -320,26 +321,25 @@ DEPENDENCIES dotenv-rails (~> 2.7) draper (~> 4.0) faker (~> 2) - i18n-tasks (~> 0.9.34) + i18n-tasks (~> 1.0, >= 1.0.12) letter_opener - lokalise_rails (~> 3) + lokalise_rails (~> 5.1) pagy (~> 5.0) pry-rails - puma (~> 5.0) + puma (~> 6.0) pundit (~> 2.1) - rack-mini-profiler (~> 2.0) - rails (~> 6.1.3, >= 6.1.3.2) - rails-i18n (~> 6) + rack-mini-profiler (~> 3.0) + rails (~> 7.0, >= 7.0.4) + rails-i18n (~> 7.0, >= 7.0.5) rubocop (~> 1.18) rubocop-i18n (~> 3) rubocop-performance (~> 1.11) rubocop-rails (~> 2.11) rubyXL (~> 3.4) rubyzip (~> 2) - sidekiq (~> 6.5, >= 6.5.7) + sidekiq (~> 7.0) sqlite3 (~> 1.4) tzinfo-data - valid_email2 (~> 4.0) web-console (>= 4.1.0) webpacker (= 6.0.0.rc.6) diff --git a/app/javascript/scripts/select2.js b/app/javascript/scripts/select2.js deleted file mode 100644 index cee35e2..0000000 --- a/app/javascript/scripts/select2.js +++ /dev/null @@ -1,62 +0,0 @@ -import $ from 'jquery' -import 'select2/dist/js/select2' -import * as Select2Uk from 'select2/src/js/select2/i18n/uk' -import * as Select2En from 'select2/src/js/select2/i18n/en' - -const select2_langs = { - ru: Select2Uk, - en: Select2En -} - -$(document).on("turbolinks:before-cache", function() { - $('.js-multiple-select').each(function () { - $(this).select2('destroy'); - }) -}) - - -$(document).on("turbolinks:load", function() { - $('#js-multiple-select').each(function () { - const $this = $(this) - - let opts = { - theme: 'bootstrap-5', - width: $this.data("width") ? $this.data("width") : $this.hasClass("w-100") ? "100%" : "style", - placeholder: $this.data("placeholder"), - allowClear: Boolean($this.data("allow-clear")), - language: select2_langs[$('body').data('lang')] - } - - if($this.hasClass('js-ajax-select')) { - const ajax_opts = { - ajax: { - url: $this.data('ajax-url'), - data: function (params) { - return { - term: params.term - } - }, - dataType: 'json', - delay: 1000, - processResults: function (data, params) { - const arr = $.map(data, function(value, index){ - return { - id: value.id, - text: value.title - } - }) - return { - results: arr - } - }, - cache: true - }, - minimumInputLength: 2 - } - - opts = Object.assign(opts, ajax_opts) - } - - $this.select2(opts) - }) -}) \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index fef837c..d45d2c4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,10 +15,9 @@ class User < ApplicationRecord validate :password_presence validate :correct_old_password, on: :update, if: -> { password.present? && !admin_edit } - validates :password, confirmation: true, allow_blank: true, - length: { minimum: 8, maximum: 70 } + validates :password, confirmation: true, allow_blank: true, length: { minimum: 8, maximum: 70 } - validates :email, presence: true, uniqueness: true, 'valid_email_2/email': true + validates :email, presence: true, uniqueness: true, email: true validate :password_complexity validates :role, presence: true @@ -42,8 +41,7 @@ def set_gravatar_hash end def digest(string) - cost = if ActiveModel::SecurePassword - .min_cost + cost = if ActiveModel::SecurePassword.min_cost BCrypt::Engine::MIN_COST else BCrypt::Engine.cost @@ -69,4 +67,4 @@ def password_complexity def password_presence errors.add(:password, :blank) if password_digest.blank? end -end +end \ No newline at end of file diff --git a/app/packs/scripts/select.js b/app/packs/scripts/select.js index 62780ba..2f18bb5 100644 --- a/app/packs/scripts/select.js +++ b/app/packs/scripts/select.js @@ -1,6 +1,14 @@ import TomSelect from 'tom-select/dist/js/tom-select.popular' import Translations from './i18n/select.json' +let selects = [] + +document.addEventListener("turbolinks:before-cache", function() { + selects.forEach((select) => { + select.destroy() + }) +}) + document.addEventListener("turbolinks:load", function() { const i18n = Translations[document.querySelector('body').dataset.lang] @@ -35,6 +43,7 @@ document.addEventListener("turbolinks:load", function() { } } - new TomSelect(element, opts) + const el = new TomSelect(element, opts) + selects.push(el) }) }) \ No newline at end of file diff --git a/app/validators/email_validator.rb b/app/validators/email_validator.rb new file mode 100644 index 0000000..cf11a9d --- /dev/null +++ b/app/validators/email_validator.rb @@ -0,0 +1,12 @@ +class EmailValidator < ActiveModel::EachValidator + def validate_each(rec, att, val) + msg = I18n.t 'global.errors.invalid_format' + rec.errors.add(att, (options[:message] || msg)) unless valid_email?(val) + end + + private + + def valid_email?(value) + URI::MailTo::EMAIL_REGEXP.match? value + end +end \ No newline at end of file diff --git a/bin/rails b/bin/rails index 94c7e6d..efc0377 100644 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby.exe -APP_PATH = File.expand_path('../config/application', __dir__) +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) require_relative "../config/boot" require "rails/commands" diff --git a/bin/rake b/bin/rake index 01f7fc0..4fbf10b 100644 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby.exe +#!/usr/bin/env ruby require_relative "../config/boot" require "rake" Rake.application.run diff --git a/bin/setup b/bin/setup index 69a1bda..ec47b79 100644 --- a/bin/setup +++ b/bin/setup @@ -1,8 +1,8 @@ -#!/usr/bin/env ruby.exe +#!/usr/bin/env ruby require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -13,24 +13,21 @@ FileUtils.chdir APP_ROOT do # 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 ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') - - # Install JavaScript dependencies - system! 'bin/yarn' + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") # puts "\n== Copying sample files ==" - # unless File.exist?('config/database.yml') - # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" # end puts "\n== Preparing database ==" - system! 'bin/rails db:prepare' + system! "bin/rails db:prepare" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/config/application.rb b/config/application.rb index 001ee3b..5f918b0 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,7 +23,7 @@ module AskIt class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 6.1 + config.load_defaults 7.0 config.i18n.available_locales = %i[en uk] config.i18n.default_locale = :uk diff --git a/config/boot.rb b/config/boot.rb index c04863f..988a5dd 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,4 @@ -# frozen_string_literal: true +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) - -require 'bundler/setup' # Set up gems listed in the Gemfile. -require 'bootsnap/setup' # Speed up boot time by caching expensive operations. +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/config/environment.rb b/config/environment.rb index d5abe55..cac5315 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,7 +1,5 @@ -# frozen_string_literal: true - # Load the Rails application. -require_relative 'application' +require_relative "application" # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 39d0d77..81b08b6 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_support/core_ext/integer/time' +require "active_support/core_ext/integer/time" # rubocop:disable Metrics/BlockLength Rails.application.configure do @@ -13,7 +13,6 @@ Bullet.rails_logger = true Bullet.add_footer = true end - # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded any time @@ -27,15 +26,18 @@ # Show full error reports. config.consider_all_requests_local = true + # Enable server timing + config.server_timing = true + # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? + if Rails.root.join("tmp/caching-dev.txt").exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" + "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -53,6 +55,7 @@ config.action_mailer.delivery_method = :letter_opener config.action_mailer.perform_deliveries = true config.action_mailer.default_url_options = { host: 'localhost:3000' } + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -68,17 +71,14 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true + # Raises error for missing translations. # config.i18n.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 end -# rubocop:enable Metrics/BlockLength \ No newline at end of file +# rubocop:enable Metrics/BlockLength diff --git a/config/environments/production.rb b/config/environments/production.rb index 9304c89..70e0577 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,6 +1,4 @@ -# frozen_string_literal: true - -require 'active_support/core_ext/integer/time' +require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -24,19 +22,22 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # 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 - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache + # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil - # config.action_cable.url = 'wss://example.com/cable' - # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # config.action_cable.url = "wss://example.com/cable" + # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -46,14 +47,14 @@ config.log_level = :info # Prepend all log lines with the following tags. - config.log_tags = [:request_id] + config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "AskIt_production" + # config.active_job.queue_name_prefix = "ask_it_production" config.action_mailer.perform_caching = false @@ -65,49 +66,22 @@ # 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 = [] + # Don't log any deprecations. + config.active_support.report_deprecations = false # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require "syslog/logger" - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") - if ENV['RAILS_LOG_TO_STDOUT'].present? - logger = ActiveSupport::Logger.new($stdout) + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - - # Inserts middleware to perform automatic connection switching. - # The `database_selector` hash is used to pass options to the DatabaseSelector - # middleware. The `delay` is used to determine how long to wait after a write - # to send a subsequent read to the primary. - # - # The `database_resolver` class is used by the middleware to determine which - # database is appropriate to use based on the time delay. - # - # The `database_resolver_context` class is used by the middleware to set - # timestamps for the last write to the primary. The resolver uses the context - # class timestamps to determine how long to wait before reading from the - # replica. - # - # By default Rails will store a last write timestamp in the session. The - # DatabaseSelector middleware is designed as such you can define your own - # strategy for connection switching and pass that into the middleware through - # these configuration options. - # config.active_record.database_selector = { delay: 2.seconds } - # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver - # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session end diff --git a/config/environments/test.rb b/config/environments/test.rb index 2e8a7a0..6ea4d1e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,6 +1,4 @@ -# frozen_string_literal: true - -require 'active_support/core_ext/integer/time' +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 @@ -10,17 +8,18 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. + # Turn false under Spring and add config.action_view.cache_template_loading = true. config.cache_classes = true - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. + config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index f3bcce5..54f47cf 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,31 +1,25 @@ -# frozen_string_literal: true # Be sure to restart your server when you modify this file. -# Define an application-wide content security policy -# For further information see the following documentation -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy +# Define an application-wide content security policy. +# See the Securing Rails Applications Guide for more information: +# https://guides.rubyonrails.org/security.html#content-security-policy-header -# Rails.application.config.content_security_policy do |policy| -# policy.default_src :self, :https -# policy.font_src :self, :https, :data -# policy.img_src :self, :https, :data -# policy.object_src :none -# policy.script_src :self, :https -# policy.style_src :self, :https -# # If you are using webpack-dev-server then specify webpack-dev-server host -# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? - -# # Specify URI for violation reports -# # policy.report_uri "/csp-violation-report-endpoint" +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap and inline scripts +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src) +# +# # Report violations without enforcing the policy. +# # config.content_security_policy_report_only = true # end - -# If you are using UJS then enable automatic nonce generation -# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } - -# Set the nonce only to specific directives -# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) - -# Report CSP violations to a specified URI -# For further information see the following documentation: -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only -# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 3babc73..adc6568 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,8 +1,8 @@ -# frozen_string_literal: true - # 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 += %i[ - passw secret token _key crypt salt certificate otp ssn +# Configure parameters to be filtered from the log file. Use this to limit dissemination of +# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported +# notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index aa7435f..3860f65 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,17 +1,16 @@ -# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' +# inflect.acronym "RESTful" # end diff --git a/config/initializers/new_framework_defaults_7_0.rb b/config/initializers/new_framework_defaults_7_0.rb new file mode 100644 index 0000000..4d58024 --- /dev/null +++ b/config/initializers/new_framework_defaults_7_0.rb @@ -0,0 +1,135 @@ +# 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 `