Skip to content

Commit

Permalink
run rails app:update
Browse files Browse the repository at this point in the history
As per the rails upgrade guide[1] I ran

    rails app:update

and then

    rubocop -A

to bring the code generated by rails app:update into line with our
style guide.

I discarded any changes that removed code we'd explicitly added to,
for example, config/application.rb.

[1] https://guides.rubyonrails.org/upgrading_ruby_on_rails.html

We hadn't set the `config.force_ssl` option to true back when the app
was created in 2b09a14. It feels like the kind of thing that might
cause an issue, so I've decided to leave it unset with this upgrade too.
  • Loading branch information
chrislo committed Jun 12, 2024
1 parent 651e62f commit 87ea135
Show file tree
Hide file tree
Showing 15 changed files with 448 additions and 44 deletions.
Empty file modified bin/docker-entrypoint.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require 'fileutils'
APP_ROOT = File.expand_path('..', __dir__)

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
system(*args, exception: true)
end

FileUtils.chdir APP_ROOT do
Expand Down
11 changes: 6 additions & 5 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
require 'active_record/railtie'
require 'active_storage/engine'
require 'action_controller/railtie'
# require 'action_mailer/railtie'
# require 'action_mailbox/engine'
# require 'action_text/engine'
# require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action_text/engine"
require 'action_view/railtie'
# require 'action_cable/engine'
# require "action_cable/engine"
# require "rails/test_unit/railtie"
require_relative '../lib/corp_middleware'

Expand All @@ -29,6 +29,7 @@ class Application < Rails::Application
config.autoload_paths << "#{root}/lib"
config.autoload_paths << "#{root}/lib/concepts"
Rails.autoloaders.main.collapse('lib/concepts/*/operations')
config.autoload_lib(ignore: %w[assets tasks])

# Configuration for the application, engines, and railties goes here.
#
Expand All @@ -37,7 +38,6 @@ class Application < Rails::Application
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
# config.autoload_paths += %W["#{config.root}/lib"]

config.generators do |g|
g.orm :active_record, primary_key_type: :uuid
Expand All @@ -55,5 +55,6 @@ class Application < Rails::Application
config.api_only = false

config.middleware.insert_before 0, CORPMiddleware
config.generators.system_tests = nil
end
end
10 changes: 9 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# 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
config.enable_reloading = true

# Do not eager load code on boot.
config.eager_load = false
Expand Down Expand Up @@ -54,6 +54,12 @@
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true

# Highlight code that enqueued background job in logs.
config.active_job.verbose_enqueue_logs = true

# Suppress logger output for asset requests.
config.assets.quiet = true

# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true

Expand All @@ -71,4 +77,6 @@
# may need toggling off if too aggressive
Bullet.raise = false # raise an error if n+1 query occurs
end
# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = true
end
47 changes: 35 additions & 12 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
config.cache_classes = true
config.enable_reloading = false

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
Expand All @@ -15,20 +15,25 @@
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment
# key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files).
# config.require_master_key = true

# 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?
# Disable serving static files from `public/`, relying on NGINX/Apache to do so instead.
# config.public_file_server.enabled = false

# Do not fallback to assets pipeline if a precompiled asset is missed.
# Compress CSS using a preprocessor.
# config.assets.css_compressor = :sass

# Do not fall back to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# 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
Expand All @@ -39,21 +44,31 @@
"https://#{ENV.fetch('HEROKU_APP_NAME', '')}.herokuapp.com")
}

# Assume all access to the app is happening through a SSL-terminating reverse proxy.
# Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
# config.assume_ssl = true

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true

# 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
# Log to STDOUT by default
config.logger = ActiveSupport::Logger.new($stdout)
.tap { |logger| logger.formatter = Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }

# Prepend all log lines with the following tags.
config.log_tags = [:request_id]

# "info" includes generic and useful information about system operation, but avoids logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII). If you
# want to log everything, set the level to "debug".
config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info')

# 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_adapter = :resque
# config.active_job.queue_name_prefix = "app_production"

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
Expand All @@ -78,4 +93,12 @@

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

# Enable DNS rebinding protection and other `Host` header attacks.
# config.hosts = [
# "example.com", # Allow requests from example.com
# /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
# ]
# Skip DNS rebinding protection for the default health check endpoint.
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
end
19 changes: 11 additions & 8 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
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
# While tests run files are not watched, reloading is not necessary.
config.enable_reloading = 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.
# Eager loading loads your entire application. When running a single test locally,
# this is usually not necessary, and can slow down your test suite. However, it's
# recommended that you enable it in continuous integration systems to ensure eager
# loading is working properly before deploying your code.
config.eager_load = ENV['CI'].present?

# Configure public file server for tests with Cache-Control for performance.
Expand All @@ -25,12 +26,12 @@
}

# Show full error reports and disable caching.
config.consider_all_requests_local = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store

# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Render exception templates for rescuable exceptions and raise for other exceptions.
config.action_dispatch.show_exceptions = :rescuable

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
Expand Down Expand Up @@ -61,4 +62,6 @@
# may need toggling off if too aggressive
Bullet.raise = true # raise an error if n+1 query occurs
end
# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = true
end
14 changes: 14 additions & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'

# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path

# Precompile additional assets.
# 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 )
13 changes: 6 additions & 7 deletions config/initializers/content_security_policy.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 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.configure do
# config.content_security_policy do |policy|
Expand All @@ -17,11 +17,10 @@
# # policy.report_uri "/csp-violation-report-endpoint"
# end
#
# # Generate session nonces for permitted importmap and inline scripts
# # Generate session nonces for permitted importmap, inline scripts, and inline styles.
# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
# config.content_security_policy_nonce_directives = %w(script-src)
# config.content_security_policy_nonce_directives = %w(script-src style-src)
#
# # Report CSP violations to a specified URI. See:
# # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
# # Report violations without enforcing the policy.
# # config.content_security_policy_report_only = true
# end
14 changes: 14 additions & 0 deletions config/initializers/cors.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

origins_array = ENV['ALLOWED_ORIGINS']&.split(',')&.map(&:strip) || []
# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin Ajax requests.

Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins origins_array
resource '*', headers: :any, methods: %i[get post patch put delete], expose: ['Link']
end
end
# Read more: https://github.com/cyu/rack-cors

# Rails.application.config.middleware.insert_before 0, Rack::Cors do
# allow do
# origins "example.com"
#
# resource "*",
# headers: :any,
# methods: [:get, :post, :put, :patch, :delete, :options, :head]
# end
# end
4 changes: 3 additions & 1 deletion config/initializers/filter_parameter_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

# Be sure to restart your server when you modify this file.

# Configure sensitive parameters which will be filtered from the log file.
# Configure parameters to be partially matched (e.g. passw matches password) and 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 += %i[
passw secret token _key crypt salt certificate otp ssn
]
Loading

0 comments on commit 87ea135

Please sign in to comment.