From b54a8458d5029b3494165b7430e21b3ae34ecc0c Mon Sep 17 00:00:00 2001 From: hellekin Date: Fri, 22 Jan 2021 05:32:15 +0100 Subject: Upgrade Rails and add StimulusJS support --- config/application.rb | 20 ++++++------- config/boot.rb | 4 +-- config/environment.rb | 2 +- config/environments/development.rb | 26 ++++++++++++---- config/environments/production.rb | 18 +++++++---- config/environments/test.rb | 13 +++++++- config/initializers/assets.rb | 1 + config/initializers/backtrace_silencers.rb | 7 +++-- config/initializers/content_security_policy.rb | 4 +++ config/initializers/filter_parameter_logging.rb | 4 ++- config/initializers/meta_tags.rb | 40 +++++++++++++++++++++++++ config/initializers/permissions_policy.rb | 11 +++++++ config/routes.rb | 3 +- config/webpack/environment.js | 1 + config/webpacker.yml | 4 +-- 15 files changed, 126 insertions(+), 32 deletions(-) create mode 100644 config/initializers/meta_tags.rb create mode 100644 config/initializers/permissions_policy.rb (limited to 'config') diff --git a/config/application.rb b/config/application.rb index 0ca42d8..8752f57 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,4 @@ -require_relative 'boot' +require_relative "boot" require "rails" # Pick the frameworks you want: @@ -13,7 +13,7 @@ require "action_text/engine" require "action_view/railtie" # require "action_cable/engine" require "sprockets/railtie" -# require "rails/test_unit/railtie" +require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. @@ -22,14 +22,14 @@ Bundler.require(*Rails.groups) module IncommonMap class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 6.0 + config.load_defaults 6.1 - # Settings in config/environments/* take precedence over those specified here. - # Application configuration can go into files in config/initializers - # -- all .rb files in that directory are automatically loaded after loading - # the framework and any gems in your application. - - # Don't generate system test files. - config.generators.system_tests = nil + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") end end diff --git a/config/boot.rb b/config/boot.rb index b9e460c..3cda23b 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,4 @@ 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 426333b..cac5315 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # 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 3ae395e..7a9f6c3 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 @@ -29,16 +31,22 @@ Rails.application.configure do end # Store uploaded files on the local file system (see config/storage.yml for options). - # config.active_storage.service = :local + config.active_storage.service = :local # Don't care if the mailer can't send. - # config.action_mailer.raise_delivery_errors = false + config.action_mailer.raise_delivery_errors = false - # config.action_mailer.perform_caching = false + config.action_mailer.perform_caching = false # 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 @@ -54,9 +62,15 @@ Rails.application.configure do config.assets.quiet = true # 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 # 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 diff --git a/config/environments/production.rb b/config/environments/production.rb index c7d2778..8602e0b 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. @@ -29,7 +31,7 @@ Rails.application.configure do 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 @@ -41,9 +43,9 @@ Rails.application.configure do # 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. - config.log_level = :debug + # 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. config.log_tags = [ :request_id ] @@ -68,11 +70,17 @@ Rails.application.configure do # 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 # Use a different logger for distributed setups. - # require 'syslog/logger' + # require "syslog/logger" # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? diff --git a/config/environments/test.rb b/config/environments/test.rb index 0cb2424..93ed4f1 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 @@ -44,6 +46,15 @@ Rails.application.configure do # 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 = [] + # 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 end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 4b828e8..20d4046 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -12,3 +12,4 @@ Rails.application.config.assets.paths << Rails.root.join('node_modules') # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css ) +Rails.application.config.assets.precompile += %w(leaflet.markercluster.js leaflet.markercluster.css leaflet.markercluster-default.css) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cd..33699c3 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/content_security_policy.rb b/config/initializers/content_security_policy.rb index 35d0f26..9cd7f6a 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -28,3 +28,7 @@ # 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 + +Rails.application.config.content_security_policy do |policy| + policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development? +end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1..4b34a03 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] +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/config/initializers/meta_tags.rb b/config/initializers/meta_tags.rb new file mode 100644 index 0000000..464d964 --- /dev/null +++ b/config/initializers/meta_tags.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# Use this setup block to configure all options available in MetaTags. +MetaTags.configure do |config| + # How many characters should the title meta tag have at most. Default is 70. + # Set to nil or 0 to remove limits. + # config.title_limit = 70 + + # When true, site title will be truncated instead of title. Default is false. + # config.truncate_site_title_first = false + + # Maximum length of the page description. Default is 300. + # Set to nil or 0 to remove limits. + # config.description_limit = 300 + + # Maximum length of the keywords meta tag. Default is 255. + # config.keywords_limit = 255 + + # Default separator for keywords meta tag (used when an Array passed with + # the list of keywords). Default is ", ". + # config.keywords_separator = ', ' + + # When true, keywords will be converted to lowercase, otherwise they will + # appear on the page as is. Default is true. + # config.keywords_lowercase = true + + # When true, the output will not include new line characters between meta tags. + # Default is false. + # config.minify_output = false + + # When false, generated meta tags will be self-closing () instead + # of open (``). Default is true. + # config.open_meta_tags = true + + # List of additional meta tags that should use "property" attribute instead + # of "name" attribute in tags. + # config.property_tags.push( + # 'x-hearthstone:deck', + # ) +end diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb new file mode 100644 index 0000000..00f64d7 --- /dev/null +++ b/config/initializers/permissions_policy.rb @@ -0,0 +1,11 @@ +# Define an application-wide HTTP permissions policy. For further +# information see https://developers.google.com/web/updates/2018/06/feature-policy +# +# Rails.application.config.permissions_policy do |f| +# f.camera :none +# f.gyroscope :none +# f.microphone :none +# f.usb :none +# f.fullscreen :self +# f.payment :self, "https://secure.example.com" +# end diff --git a/config/routes.rb b/config/routes.rb index f5c6194..9be4a4e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,7 @@ # SPDX-License-Identifier: AGPL-3.0-or-later Rails.application.routes.draw do + get 'sections/show' # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html root to: 'welcome#index' @@ -27,7 +28,7 @@ Rails.application.routes.draw do get '/my/account', to: 'users#show', as: 'account' patch '/my/current_agent', to: 'my/agent#switch', as: 'agent_switch' get '/my/dashboard', to: 'welcome#dashboard' - get 'my/users', to: 'users#index', as: 'users' + get 'my/peers', to: 'users#index', as: 'users' # Discourse SSO get 'authenticate(/:token)', to: 'welcome#authenticate' diff --git a/config/webpack/environment.js b/config/webpack/environment.js index d16d9af..6a6b545 100644 --- a/config/webpack/environment.js +++ b/config/webpack/environment.js @@ -1,3 +1,4 @@ const { environment } = require('@rails/webpacker') module.exports = environment + diff --git a/config/webpacker.yml b/config/webpacker.yml index 8581ac0..38c15d2 100644 --- a/config/webpacker.yml +++ b/config/webpacker.yml @@ -6,12 +6,12 @@ default: &default public_root_path: public public_output_path: packs cache_path: tmp/cache/webpacker - check_yarn_integrity: false + check_yarn_integrity: true webpack_compile_output: true # Additional paths webpack should lookup modules # ['app/assets', 'engine/foo/app/assets'] - resolved_paths: [] + resolved_paths: ['app/assets'] # Reload manifest.json on all requests so we reload latest compiled packs cache_manifest: false -- cgit v1.2.3