From 718656ad59bc02a73409bec5ddcdb2de3443dd96 Mon Sep 17 00:00:00 2001 From: Jacob Michalskie Date: Sat, 10 Dec 2022 01:53:30 +0100 Subject: [PATCH 1/2] Upgrade to Rails 5.2 --- Gemfile | 5 +- Gemfile.lock | 157 +++++++++--------- app/models/travel_expense_report.rb | 12 +- bin/bundle | 2 +- bin/setup | 4 +- bin/update | 6 +- bin/yarn | 6 +- config/application.rb | 45 +---- config/boot.rb | 1 + config/cable.yml | 10 -- config/environments/development.rb | 11 +- config/environments/production.rb | 11 +- config/environments/test.rb | 6 +- config/initializers/config.rb | 13 +- .../initializers/content_security_policy.rb | 25 +++ .../new_framework_defaults_5_2.rb | 38 +++++ config/initializers/theme.rb | 8 + config/puma.rb | 27 +-- config/storage.yml | 34 ++++ 19 files changed, 239 insertions(+), 182 deletions(-) delete mode 100644 config/cable.yml create mode 100644 config/initializers/content_security_policy.rb create mode 100644 config/initializers/new_framework_defaults_5_2.rb create mode 100644 config/initializers/theme.rb create mode 100644 config/storage.yml diff --git a/Gemfile b/Gemfile index 31243d2a..324abeb6 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' -gem 'rails', '>= 5.1.7', '< 5.1.99' +gem 'rails', '>= 5.2.0', '< 5.2.99' gem 'rails-i18n' gem 'responders' @@ -41,6 +41,9 @@ end gem 'listen' +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', require: false + # Debugger gem 'byebug', group: %i[development test] diff --git a/Gemfile.lock b/Gemfile.lock index 1abcfa96..e9c152ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,41 +2,45 @@ GEM remote: https://rubygems.org/ specs: Ascii85 (1.0.3) - actioncable (5.1.7) - actionpack (= 5.1.7) + actioncable (5.2.8.1) + actionpack (= 5.2.8.1) nio4r (~> 2.0) - websocket-driver (~> 0.6.1) - actionmailer (5.1.7) - actionpack (= 5.1.7) - actionview (= 5.1.7) - activejob (= 5.1.7) + websocket-driver (>= 0.6.1) + actionmailer (5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.7) - actionview (= 5.1.7) - activesupport (= 5.1.7) - rack (~> 2.0) + actionpack (5.2.8.1) + actionview (= 5.2.8.1) + activesupport (= 5.2.8.1) + rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.7) - activesupport (= 5.1.7) + actionview (5.2.8.1) + activesupport (= 5.2.8.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) active_hash (3.1.1) activesupport (>= 5.0.0) - activejob (5.1.7) - activesupport (= 5.1.7) + activejob (5.2.8.1) + activesupport (= 5.2.8.1) globalid (>= 0.3.6) - activemodel (5.1.7) - activesupport (= 5.1.7) - activerecord (5.1.7) - activemodel (= 5.1.7) - activesupport (= 5.1.7) - arel (~> 8.0) - activesupport (5.1.7) + activemodel (5.2.8.1) + activesupport (= 5.2.8.1) + activerecord (5.2.8.1) + activemodel (= 5.2.8.1) + activesupport (= 5.2.8.1) + arel (>= 9.0) + activestorage (5.2.8.1) + actionpack (= 5.2.8.1) + activerecord (= 5.2.8.1) + marcel (~> 1.0.0) + activesupport (5.2.8.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -44,13 +48,15 @@ GEM addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) afm (0.2.2) - arel (8.0.0) + arel (9.0.0) ast (2.4.2) audited (5.0.2) activerecord (>= 5.0, < 7.1) autoprefixer-rails (10.4.7.0) execjs (~> 2) bcrypt (3.1.18) + bootsnap (1.15.0) + msgpack (~> 1.2) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) @@ -89,9 +95,9 @@ GEM activesupport tzinfo cocoon (1.2.15) - coffee-rails (4.2.2) + coffee-rails (5.0.0) coffee-script (>= 2.2.0) - railties (>= 4.0.0) + railties (>= 5.2.0) coffee-script (2.4.1) coffee-script-source execjs @@ -128,9 +134,9 @@ GEM diff-lcs (1.5.0) docile (1.4.0) erubi (1.11.0) - exception_notification (4.4.3) - actionmailer (>= 4.0, < 7) - activesupport (>= 4.0, < 7) + exception_notification (4.5.0) + actionmailer (>= 5.2, < 8) + activesupport (>= 5.2, < 8) execjs (2.8.1) ffi (1.15.5) git (1.13.1) @@ -147,9 +153,9 @@ GEM activesupport (>= 5.1) haml (>= 4.0.6) railties (>= 5.1) - has_scope (0.7.2) - actionpack (>= 4.1) - activesupport (>= 4.1) + has_scope (0.8.0) + actionpack (>= 5.2) + activesupport (>= 5.2) hashery (2.1.2) htmlentities (4.3.4) i18n (1.12.0) @@ -157,10 +163,10 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inherited_resources (1.11.0) - actionpack (>= 5.0, < 6.1) + inherited_resources (1.13.1) + actionpack (>= 5.2, < 7.1) has_scope (~> 0.6) - railties (>= 5.0, < 6.1) + railties (>= 5.2, < 7.1) responders (>= 2, < 4) jquery-rails (4.5.1) rails-dom-testing (>= 1, < 3) @@ -184,10 +190,11 @@ GEM addressable (~> 2.7) letter_opener (1.8.1) launchy (>= 2.2, < 3) - letter_opener_web (1.4.1) - actionmailer (>= 3.2) - letter_opener (~> 1.0) - railties (>= 3.2) + letter_opener_web (2.0.0) + actionmailer (>= 5.2) + letter_opener (~> 1.7) + railties (>= 5.2) + rexml libv8-node (16.10.0.0) listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) @@ -220,8 +227,6 @@ GEM hashery (~> 2.0) ruby-rc4 ttfunk - polyamorous (2.3.0) - activerecord (>= 5.0) powerpack (0.1.3) prawn (0.13.2) pdf-reader (~> 1.2) @@ -238,17 +243,18 @@ GEM rack (2.2.6.2) rack-test (2.0.2) rack (>= 1.3) - rails (5.1.7) - actioncable (= 5.1.7) - actionmailer (= 5.1.7) - actionpack (= 5.1.7) - actionview (= 5.1.7) - activejob (= 5.1.7) - activemodel (= 5.1.7) - activerecord (= 5.1.7) - activesupport (= 5.1.7) + rails (5.2.8.1) + actioncable (= 5.2.8.1) + actionmailer (= 5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) + activemodel (= 5.2.8.1) + activerecord (= 5.2.8.1) + activestorage (= 5.2.8.1) + activesupport (= 5.2.8.1) bundler (>= 1.3.0) - railties (= 5.1.7) + railties (= 5.2.8.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) @@ -258,20 +264,18 @@ GEM rails-i18n (5.1.3) i18n (>= 0.7, < 2) railties (>= 5.0, < 6) - railties (5.1.7) - actionpack (= 5.1.7) - activesupport (= 5.1.7) + railties (5.2.8.1) + actionpack (= 5.2.8.1) + activesupport (= 5.2.8.1) method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) + thor (>= 0.19.0, < 2.0) rainbow (3.1.1) rake (13.0.6) - ransack (2.3.0) - actionpack (>= 5.0) - activerecord (>= 5.0) - activesupport (>= 5.0) + ransack (2.5.0) + activerecord (>= 5.2.4) + activesupport (>= 5.2.4) i18n - polyamorous (= 2.3.0) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) @@ -291,10 +295,10 @@ GEM rspec-mocks (3.12.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-rails (4.1.2) - actionpack (>= 4.2) - activesupport (>= 4.2) - railties (>= 4.2) + rspec-rails (5.1.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + railties (>= 5.2) rspec-core (~> 3.10) rspec-expectations (~> 3.10) rspec-mocks (~> 3.10) @@ -330,14 +334,14 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - shoulda-matchers (4.5.1) - activesupport (>= 4.2.0) - show_for (0.7.0) - actionpack (>= 5.0) - activemodel (>= 5.0) - simple_form (5.0.3) - actionpack (>= 5.0) - activemodel (>= 5.0) + shoulda-matchers (5.2.0) + activesupport (>= 5.2.0) + show_for (0.8.0) + actionpack (>= 5.2) + activemodel (>= 5.2) + simple_form (5.1.0) + actionpack (>= 5.2) + activemodel (>= 5.2) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) @@ -348,9 +352,9 @@ GEM sprockets (4.1.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) sqlite3 (1.6.0) mini_portile2 (~> 2.8.0) @@ -383,7 +387,7 @@ GEM rack (>= 2.0.9) webrick (1.7.0) websocket (1.2.9) - websocket-driver (0.6.5) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) @@ -399,6 +403,7 @@ PLATFORMS DEPENDENCIES active_hash audited + bootsnap bootstrap-sass byebug cancancan (~> 1.17) @@ -432,7 +437,7 @@ DEPENDENCIES prawn_rails psych (< 4.0) puma - rails (>= 5.1.7, < 5.1.99) + rails (>= 5.2.0, < 5.2.99) rails-i18n ransack redcarpet diff --git a/app/models/travel_expense_report.rb b/app/models/travel_expense_report.rb index 51baed92..a367d636 100644 --- a/app/models/travel_expense_report.rb +++ b/app/models/travel_expense_report.rb @@ -16,7 +16,7 @@ class TravelExpenseReport < ApplicationRecord delegate :user, to: :request, prefix: false delegate :event, to: :request, prefix: false - @by = { + BY = { event: [ { field: :event_id, sql: 'event_id', hidden: true }, { field: :event_name, sql: 'events.name' }, @@ -61,7 +61,7 @@ class TravelExpenseReport < ApplicationRecord { field: :event_name, sql: 'events.name' }, { field: :subject, sql: 'request_expenses.subject' } ] - } + }.freeze # Main scope for using the whole model. Takes cares of all the grouping, # conditions and selections needed for a given amount field and a given @@ -76,9 +76,9 @@ class TravelExpenseReport < ApplicationRecord currency = RequestExpense.currency_field_for(type.to_sym) r = joins(request: [{ user: :profile }, :event]) r = r.joins('LEFT JOIN reimbursements ON reimbursements.request_id = requests.id') - r = r.select("sum(#{type}_amount) AS sum_amount, #{currency} AS sum_currency, #{@by[g.to_sym].map { |f| "#{f[:sql]} AS #{f[:field]}" }.join(', ')}") + r = r.select("sum(#{type}_amount) AS sum_amount, #{currency} AS sum_currency, #{TravelExpenseReport::BY[g.to_sym].map { |f| "#{f[:sql]} AS #{f[:field]}" }.join(', ')}") r = r.where("#{type}_amount IS NOT NULL") - r = r.group("#{currency}, #{@by[g.to_sym].map { |f| f[:sql] }.join(', ')}") + r = r.group("#{currency}, #{TravelExpenseReport::BY[g.to_sym].map { |f| f[:sql] }.join(', ')}") } # Scope for filtering @@ -136,14 +136,14 @@ class TravelExpenseReport < ApplicationRecord # @param [#to_sym] group The grouping option used when invoking the scope # @return [array] The names of the resulting fields (as an array of symbols) def self.fields_for(group) - @by[group.to_sym].reject { |f| f[:hidden] }.map { |i| i[:field] } + %i[sum_amount sum_currency] + TravelExpenseReport::BY[group.to_sym].reject { |f| f[:hidden] }.map { |i| i[:field] } + %i[sum_amount sum_currency] end # Available group options for calling the 'by' scope # # @return [array] An array with the available grouping criterias (as symbols) def self.groups - @by.keys + TravelExpenseReport::BY.keys end # Casted value of a given attribute. diff --git a/bin/bundle b/bin/bundle index 79639d69..0513e50f 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,3 @@ #!/usr/bin/env ruby.ruby2.7 -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/setup b/bin/setup index 0dfa1315..85076e34 100755 --- a/bin/setup +++ b/bin/setup @@ -1,10 +1,9 @@ #!/usr/bin/env ruby.ruby2.7 -require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -21,7 +20,6 @@ chdir APP_ROOT do # Install JavaScript dependencies if using Yarn # system('bin/yarn') - # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' diff --git a/bin/update b/bin/update index b8a990dc..989fdb81 100755 --- a/bin/update +++ b/bin/update @@ -1,10 +1,9 @@ #!/usr/bin/env ruby.ruby2.7 -require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -18,6 +17,9 @@ chdir APP_ROOT do system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + puts "\n== Updating database ==" system! 'bin/rails db:migrate' diff --git a/bin/yarn b/bin/yarn index d8c74509..050b49d9 100755 --- a/bin/yarn +++ b/bin/yarn @@ -1,8 +1,8 @@ #!/usr/bin/env ruby.ruby2.7 -VENDOR_PATH = File.expand_path('..', __dir__) -Dir.chdir(VENDOR_PATH) do +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do begin - exec "yarnpkg #{ARGV.join(" ")}" + exec "yarnpkg", *ARGV rescue Errno::ENOENT $stderr.puts "Yarn executable was not detected in the system." $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" diff --git a/config/application.rb b/config/application.rb index cb6f85cc..4ae7e75e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -12,47 +12,8 @@ class Application < Rails::Application config.load_defaults 5.1 # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - - # Custom directories with classes and modules you want to be autoloadable. - # config.autoload_paths += %W(#{config.root}/extras) - - # Only load the plugins named here, in the order given (default is alphabetical). - # :all can be used as a placeholder for all plugins not explicitly named. - # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - - # Activate observers that should always be running. - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - config.i18n.available_locales = [:en] - config.i18n.enforce_available_locales = true - - # Configure the default encoding used in templates for Ruby 1.9. - config.encoding = "utf-8" - - # Configure sensitive parameters which will be filtered from the log file. - config.filter_parameters += [:password] - - # Enable escaping HTML in JSON. - config.active_support.escape_html_entities_in_json = true - - # Use SQL instead of Active Record's schema dumper when creating the database. - # This is necessary if your schema can't be completely dumped by the schema dumper, - # like if you have constraints or database-specific column types - # config.active_record.schema_format = :sql - - # Enable the asset pipeline - config.assets.enabled = true - - # The configuration file for the application - config.site = config_for(:site) + # 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. end end diff --git a/config/boot.rb b/config/boot.rb index 30f5120d..b9e460ce 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +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. diff --git a/config/cable.yml b/config/cable.yml deleted file mode 100644 index 4cc71f90..00000000 --- a/config/cable.yml +++ /dev/null @@ -1,10 +0,0 @@ -development: - adapter: async - -test: - adapter: async - -production: - adapter: redis - url: redis://localhost:6379/1 - channel_prefix: travel_support_production diff --git a/config/environments/development.rb b/config/environments/development.rb index 5187e221..1311e3e4 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -13,12 +13,13 @@ config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. - if Rails.root.join('tmp/caching-dev.txt').exist? + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" + 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -26,6 +27,9 @@ config.cache_store = :null_store end + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false @@ -37,6 +41,9 @@ # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. diff --git a/config/environments/production.rb b/config/environments/production.rb index 70f8b0d2..c81176d4 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -14,10 +14,9 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Attempt to read encrypted secrets from `config/secrets.yml.enc`. - # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or - # `config/secrets.yml.key`. - config.read_encrypted_secrets = 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). + # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. @@ -39,6 +38,9 @@ # 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' @@ -60,6 +62,7 @@ # 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 = "travel_support_#{Rails.env}" + config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. diff --git a/config/environments/test.rb b/config/environments/test.rb index 8e5cbde5..0a38fd3c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -15,7 +15,7 @@ # 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.seconds.to_i}" + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. @@ -27,6 +27,10 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory + config.active_storage.service = :test + config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. diff --git a/config/initializers/config.rb b/config/initializers/config.rb index 8aa4aa47..59bb1d5e 100644 --- a/config/initializers/config.rb +++ b/config/initializers/config.rb @@ -1,10 +1,7 @@ +# The configuration file for the application +Rails.application.config.site = Rails.application.config_for(:site) + ActionMailer::Base.default_url_options = Rails.configuration.site['email_default_url_options'].symbolize_keys -if theme = Rails.configuration.site['theme'] - path = Rails.root.join('app/themes', theme) - ActionController::Base.prepend_view_path path.join('views') - Rails.application.config.assets.paths.unshift path.join('assets/images'), path.join('assets/javascripts'), path.join('assets/stylesheets') - Sprockets.prepend_path(path.join('assets/config')) - Sprockets.prepend_path(path.join('assets/stylesheets')) - Sprockets.prepend_path(path.join('assets/javascripts')) -end +# Allow some data types to be included in activerecord +Rails.application.config.active_record.yaml_column_permitted_classes = [Symbol, BigDecimal, ActiveSupport::TimeWithZone, Time, ActiveSupport::TimeZone, Date] diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 00000000..d3bcaa5e --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# 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 + +# 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 + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# 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/new_framework_defaults_5_2.rb b/config/initializers/new_framework_defaults_5_2.rb new file mode 100644 index 00000000..c383d072 --- /dev/null +++ b/config/initializers/new_framework_defaults_5_2.rb @@ -0,0 +1,38 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.2 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. + +# Make Active Record use stable #cache_key alongside new #cache_version method. +# This is needed for recyclable cache keys. +# Rails.application.config.active_record.cache_versioning = true + +# Use AES-256-GCM authenticated encryption for encrypted cookies. +# Also, embed cookie expiry in signed or encrypted cookies for increased security. +# +# This option is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 5.2. +# +# Existing cookies will be converted on read then written with the new scheme. +# Rails.application.config.action_dispatch.use_authenticated_cookie_encryption = true + +# Use AES-256-GCM authenticated encryption as default cipher for encrypting messages +# instead of AES-256-CBC, when use_authenticated_message_encryption is set to true. +# Rails.application.config.active_support.use_authenticated_message_encryption = true + +# Add default protection from forgery to ActionController::Base instead of in +# ApplicationController. +# Rails.application.config.action_controller.default_protect_from_forgery = true + +# Store boolean values are in sqlite3 databases as 1 and 0 instead of 't' and +# 'f' after migrating old data. +# Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true + +# Use SHA-1 instead of MD5 to generate non-sensitive digests, such as the ETag header. +# Rails.application.config.active_support.use_sha1_digests = true + +# Make `form_with` generate id attributes for any generated HTML tags. +# Rails.application.config.action_view.form_with_generates_ids = true diff --git a/config/initializers/theme.rb b/config/initializers/theme.rb new file mode 100644 index 00000000..48ee9861 --- /dev/null +++ b/config/initializers/theme.rb @@ -0,0 +1,8 @@ +if theme = Rails.configuration.site['theme'] + path = Rails.root.join('app/themes', theme) + ActionController::Base.prepend_view_path path.join('views') + Rails.application.config.assets.paths.unshift path.join('assets/images'), path.join('assets/javascripts'), path.join('assets/stylesheets') + Sprockets.prepend_path(path.join('assets/config')) + Sprockets.prepend_path(path.join('assets/stylesheets')) + Sprockets.prepend_path(path.join('assets/javascripts')) +end diff --git a/config/puma.rb b/config/puma.rb index 1e19380d..b2102072 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -15,6 +15,9 @@ # environment ENV.fetch("RAILS_ENV") { "development" } +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. @@ -26,31 +29,9 @@ # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. If you use this option -# you need to make sure to reconnect any threads in the `on_worker_boot` -# block. +# process behavior so workers use less memory. # # preload_app! -# If you are preloading your application and using Active Record, it's -# recommended that you close any connections to the database before workers -# are forked to prevent connection leakage. -# -# before_fork do -# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) -# end - -# The code in the `on_worker_boot` will be called if you are using -# clustered mode by specifying a number of `workers`. After each worker -# process is booted, this block will be run. If you are using the `preload_app!` -# option, you will want to use this block to reconnect to any threads -# or connections that may have been created at application boot, as Ruby -# cannot share connections between processes. -# -# on_worker_boot do -# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) -# end -# - # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 00000000..d32f76e8 --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] From 7d80e40772287b003f8dd480a0cb448efc3ad395 Mon Sep 17 00:00:00 2001 From: Jacob Michalskie Date: Tue, 31 Jan 2023 10:31:13 +0100 Subject: [PATCH 2/2] more --- Gemfile.lock | 1 + app/models/event_organizer.rb | 2 +- db/schema.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e9c152ab..84bbfb27 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -213,6 +213,7 @@ GEM mini_racer (0.6.3) libv8-node (~> 16.10.0.0) minitest (5.17.0) + msgpack (1.6.0) nio4r (2.5.8) nokogiri (1.13.10) mini_portile2 (~> 2.8.0) diff --git a/app/models/event_organizer.rb b/app/models/event_organizer.rb index 168f647c..aed3ed66 100644 --- a/app/models/event_organizer.rb +++ b/app/models/event_organizer.rb @@ -11,6 +11,6 @@ class EventOrganizer < ApplicationRecord validates :user_id, uniqueness: { scope: :event_id, message: 'Already an event organizer for this event' } def self.autocomplete_users(term) - User.order('lower(nickname)').where('nickname like ? or email like ?', "%#{term}%", "%#{term}%").pluck(:nickname, :email) + User.order(Arel.sql('lower(nickname)')).where('nickname like ? or email like ?', "%#{term}%", "%#{term}%").pluck(:nickname, :email) end end diff --git a/db/schema.rb b/db/schema.rb index 924ebfda..cc081310 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20230130095633) do +ActiveRecord::Schema.define(version: 2023_01_30_095633) do create_table "audits", force: :cascade do |t| t.integer "auditable_id"