diff --git a/Gemfile b/Gemfile index d74ba069..432bcfa0 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ if Gem::Version.new(Bundler::VERSION) < Gem::Version.new('1.8.4') end # as web framework -gem 'rails', '~> 5.0.7' +gem 'rails', '~> 5.2' # Use Puma as the app server gem 'puma', '~> 3.0' @@ -140,7 +140,7 @@ gem 'prawn_rails' gem 'rqrcode' # to render XLS spreadsheets -gem 'axlsx', git: 'https://github.com/randym/axlsx.git' +gem 'axlsx' gem 'axlsx_rails' # as error catcher @@ -222,6 +222,9 @@ gem 'nokogiri', '>= 1.8.1' # memcached binary connector gem 'dalli' +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.1.0', require: false + # Use guard and spring for testing in development group :development do # to launch specs when files are modified diff --git a/Gemfile.lock b/Gemfile.lock index 887a7816..a2a26eb6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,39 +1,29 @@ -GIT - remote: https://github.com/randym/axlsx.git - revision: c593a08b2a929dac7aa8dc418b55e26b4c49dc34 - specs: - axlsx (3.0.0.pre) - htmlentities (~> 4.3, >= 4.3.4) - mimemagic (~> 0.3) - nokogiri (~> 1.8, >= 1.8.2) - rubyzip (~> 1.2, >= 1.2.1) - GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: Ascii85 (1.0.3) - actioncable (5.0.7.2) - actionpack (= 5.0.7.2) - nio4r (>= 1.2, < 3.0) - websocket-driver (~> 0.6.1) - actionmailer (5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) + actioncable (5.2.2.1) + actionpack (= 5.2.2.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.2.1) + actionpack (= 5.2.2.1) + actionview (= 5.2.2.1) + activejob (= 5.2.2.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.7.2) - actionview (= 5.0.7.2) - activesupport (= 5.0.7.2) + actionpack (5.2.2.1) + actionview (= 5.2.2.1) + activesupport (= 5.2.2.1) rack (~> 2.0) - rack-test (~> 0.6.3) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.7.2) - activesupport (= 5.0.7.2) + actionview (5.2.2.1) + activesupport (= 5.2.2.1) builder (~> 3.1) - erubis (~> 2.7.0) + erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) active_model_serializers (0.10.9) @@ -41,16 +31,20 @@ GEM activemodel (>= 4.1, < 6) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (5.0.7.2) - activesupport (= 5.0.7.2) + activejob (5.2.2.1) + activesupport (= 5.2.2.1) globalid (>= 0.3.6) - activemodel (5.0.7.2) - activesupport (= 5.0.7.2) - activerecord (5.0.7.2) - activemodel (= 5.0.7.2) - activesupport (= 5.0.7.2) - arel (~> 7.0) - activesupport (5.0.7.2) + activemodel (5.2.2.1) + activesupport (= 5.2.2.1) + activerecord (5.2.2.1) + activemodel (= 5.2.2.1) + activesupport (= 5.2.2.1) + arel (>= 9.0) + activestorage (5.2.2.1) + actionpack (= 5.2.2.1) + activerecord (= 5.2.2.1) + marcel (~> 0.3.1) + activesupport (5.2.2.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -71,19 +65,26 @@ GEM railties (>= 4.0) archive-zip (0.12.0) io-like (~> 0.3.0) - arel (7.1.4) + arel (9.0.0) ast (2.4.0) autoprefixer-rails (9.5.0) execjs awesome_nested_set (3.1.4) activerecord (>= 4.0.0, < 5.3) aws_cf_signer (0.1.3) + axlsx (3.0.0.pre) + htmlentities (~> 4.3, >= 4.3.4) + mimemagic (~> 0.3) + nokogiri (~> 1.8, >= 1.8.2) + rubyzip (~> 1.2, >= 1.2.1) axlsx_rails (0.5.2) actionpack (>= 3.1) axlsx (>= 2.0.1) bcrypt (3.1.12) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) + bootsnap (1.4.2) + msgpack (~> 1.0) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) @@ -169,6 +170,7 @@ GEM dotenv-rails (2.7.2) dotenv (= 2.7.2) railties (>= 3.2, < 6.1) + erubi (1.8.0) erubis (2.7.0) execjs (2.7.0) factory_bot (4.11.1) @@ -276,6 +278,8 @@ GEM lumberjack (1.0.12) mail (2.7.1) mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) method_source (0.8.2) mime-types (3.2.2) mime-types-data (~> 3.2015) @@ -299,6 +303,7 @@ GEM monetize (~> 1.9.0) money (~> 6.13.0) railties (>= 3.0) + msgpack (1.2.9) multi_json (1.13.1) multi_xml (0.6.0) multipart-post (2.0.0) @@ -379,19 +384,20 @@ GEM rack-openid (1.3.1) rack (>= 1.1.0) ruby-openid (>= 2.1.8) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.7.2) - actioncable (= 5.0.7.2) - actionmailer (= 5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) - activemodel (= 5.0.7.2) - activerecord (= 5.0.7.2) - activesupport (= 5.0.7.2) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.2.1) + actioncable (= 5.2.2.1) + actionmailer (= 5.2.2.1) + actionpack (= 5.2.2.1) + actionview (= 5.2.2.1) + activejob (= 5.2.2.1) + activemodel (= 5.2.2.1) + activerecord (= 5.2.2.1) + activestorage (= 5.2.2.1) + activesupport (= 5.2.2.1) bundler (>= 1.3.0) - railties (= 5.0.7.2) + railties (= 5.2.2.1) sprockets-rails (>= 2.0.0) rails-assets-bootstrap (3.3.6) rails-assets-jquery (>= 1.9.1, < 3) @@ -425,12 +431,12 @@ GEM rails-i18n (5.0.4) i18n (~> 0.7) railties (~> 5.0) - railties (5.0.7.2) - actionpack (= 5.0.7.2) - activesupport (= 5.0.7.2) + railties (5.2.2.1) + actionpack (= 5.2.2.1) + activesupport (= 5.2.2.1) method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) + thor (>= 0.19.0, < 2.0) rainbow (3.0.0) rake (12.3.2) rb-fsevent (0.10.3) @@ -591,7 +597,7 @@ GEM addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff - websocket-driver (0.6.5) + websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) whenever (0.10.0) @@ -611,8 +617,9 @@ DEPENDENCIES ajax-datatables-rails autoprefixer-rails awesome_nested_set (~> 3.1.3) - axlsx! + axlsx axlsx_rails + bootsnap (>= 1.1.0) bootstrap-sass (~> 3.4.0) bootstrap-switch-rails (~> 3.0.0) bootstrap3-datetimepicker-rails (~> 4.17.47) @@ -671,7 +678,7 @@ DEPENDENCIES prawn-qrcode (~> 0.3.0) prawn_rails puma (~> 3.0) - rails (~> 5.0.7) + rails (~> 5.2) rails-assets-bootstrap-markdown! rails-assets-bootstrap-select! rails-assets-date.format! @@ -722,4 +729,4 @@ RUBY VERSION ruby 2.5.0p0 BUNDLED WITH - 1.17.1 + 1.17.3 diff --git a/app/models/booth_request.rb b/app/models/booth_request.rb index 5cce46a1..e3fee080 100644 --- a/app/models/booth_request.rb +++ b/app/models/booth_request.rb @@ -4,8 +4,7 @@ class BoothRequest < ApplicationRecord belongs_to :booth belongs_to :user - validates :role, - presence: true + validates :role, presence: true ROLES = %w[submitter responsible].freeze end diff --git a/app/models/conference.rb b/app/models/conference.rb index 89ca5d19..139d96fa 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -94,9 +94,15 @@ class Conference < ApplicationRecord before_create :add_color before_create :create_email_settings - after_create :create_free_ticket after_update :delete_event_schedules + after_create do + create_free_ticket + create_contact + create_program + create_roles + end + enum ticket_layout: [:portrait, :landscape] ## @@ -115,7 +121,7 @@ class Conference < ApplicationRecord # Delete all EventSchedules that are not in the hours range # After the conference has been successfully updated def delete_event_schedules - if start_hour_changed? || end_hour_changed? + if start_hour_previously_changed? || end_hour_previously_changed? event_schedules = program.event_schedules.select do |event_schedule| event_schedule.start_time.hour < start_hour || event_schedule.end_time.hour > end_hour || @@ -753,12 +759,6 @@ class Conference < ApplicationRecord ((i * big_prime_numbers[component]) % 239 + 16).to_s(16) end - after_create do - create_contact - create_program - create_roles - end - ## # Creates free ticket for the conference # after the conference has been successfully created @@ -1120,7 +1120,6 @@ class Conference < ApplicationRecord # def create_email_settings build_email_settings - true end ## diff --git a/app/models/event.rb b/app/models/event.rb index 7fbc007d..6a69b6ce 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -3,6 +3,8 @@ class Event < ApplicationRecord include ActiveRecord::Transitions include RevisionCount + include ActionView::Helpers::NumberHelper + has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id } acts_as_commentable diff --git a/app/models/program.rb b/app/models/program.rb index 6c3a3b4a..98657ee9 100644 --- a/app/models/program.rb +++ b/app/models/program.rb @@ -72,8 +72,8 @@ class Program < ApplicationRecord after_create :create_event_types after_create :create_difficulty_levels - after_save :unschedule_unfit_events, if: :schedule_interval_changed? - after_save :normalize_event_types_length, if: :schedule_interval_changed? + after_save :unschedule_unfit_events, if: :schedule_interval_previously_changed? + after_save :normalize_event_types_length, if: :schedule_interval_previously_changed? validate :check_languages_format # Returns all event_schedules for the selected schedule ordered by start_time diff --git a/app/models/registration.rb b/app/models/registration.rb index f7c032ea..8719c019 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -76,7 +76,7 @@ class Registration < ApplicationRecord end def registration_limit_not_exceed - if conference.registration_limit > 0 && conference.registrations(:reload).count >= conference.registration_limit + if conference.registration_limit > 0 && conference.registrations.reload.count >= conference.registration_limit errors.add(:base, 'Registration limit exceeded') end end diff --git a/app/models/role.rb b/app/models/role.rb index d759f47d..2be87d7b 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -18,6 +18,6 @@ class Role < ApplicationRecord # Needed to ensure that removing all user from role doesn't remove role. def cancel - false + throw(:abort) end end diff --git a/app/models/survey_question.rb b/app/models/survey_question.rb index 7f3f7750..e1cb0427 100644 --- a/app/models/survey_question.rb +++ b/app/models/survey_question.rb @@ -10,7 +10,7 @@ class SurveyQuestion < ActiveRecord::Base ICONS = { boolean: 'dot-circle-o', choice: 'check-square-o', string: 'edit', text: 'align-left', datetime: 'clock-o', numeric: 'slack' }.freeze validates :title, presence: true - validates :possible_answers, :max_choices, :min_choices, presence: true, if: 'choice?' + validates :possible_answers, :max_choices, :min_choices, presence: true, if: :choice? validates :min_choices, numericality: { greater_than_or_equal_to: 1 }, allow_blank: true validates :max_choices, numericality: { greater_than_or_equal_to: 1 }, allow_blank: true diff --git a/app/models/user.rb b/app/models/user.rb index bc71f61f..e597a158 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,11 +11,6 @@ class User < ApplicationRecord # prevent N+1 queries with has_cached_role? by preloading roles *always* default_scope { preload(:roles) } - has_many :physical_tickets, through: :ticket_purchases do - def by_conference(conference) - where('ticket_purchases.conference_id = ?', conference) - end - end has_many :users_roles has_many :roles, through: :users_roles, dependent: :destroy @@ -74,6 +69,11 @@ class User < ApplicationRecord where(conference: conference, registration_ticket: true).first end end + has_many :physical_tickets, through: :ticket_purchases do + def by_conference(conference) + where('ticket_purchases.conference_id = ?', conference) + end + end has_many :votes, dependent: :destroy has_many :voted_events, through: :votes, source: :events has_many :subscriptions, dependent: :destroy diff --git a/bin/bundle b/bin/bundle index 66e9889e..f19acf5b 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -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/rails b/bin/rails index f8da2cff..07396602 100755 --- a/bin/rails +++ b/bin/rails @@ -1,6 +1,4 @@ #!/usr/bin/env ruby -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. - -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' require 'rails/commands' diff --git a/bin/setup b/bin/setup index e620b4da..94fd4d79 100755 --- a/bin/setup +++ b/bin/setup @@ -1,10 +1,9 @@ #!/usr/bin/env ruby -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== 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 a8e4462f..58bfaed5 100755 --- a/bin/update +++ b/bin/update @@ -1,10 +1,9 @@ #!/usr/bin/env ruby -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 new file mode 100755 index 00000000..adabdd97 --- /dev/null +++ b/bin/yarn @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do + 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' + exit 1 +end diff --git a/config/application.rb b/config/application.rb index e3483d4a..5571fda2 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,69 +1,19 @@ -require File.expand_path('../boot', __FILE__) +require_relative 'boot' require 'rails/all' -ActiveSupport::Deprecation.debug = true if Rails.env.test? -include ActionView::Helpers::NumberHelper -if defined?(Bundler) - # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups(assets: %w(development test))) - # If you want your assets lazily compiled in production, use this line - # Bundler.require(:default, :assets, Rails.env) -end +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) module Osem class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.2 + # 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 = (ENV['OSEM_TIME_ZONE'] || 'UTC') - - # 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 - - # 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 - - # Enforce whitelist mode for mass assignment. - # This will create an empty whitelist of attributes available for mass-assignment for all models - # in your app. As such, your models will need to explicitly whitelist or blacklist accessible - # parameters by using an attr_accessible or attr_protected declaration. - # config.active_record.whitelist_attributes = true - - # Enable the asset pipeline - config.assets.enabled = true - - # Version of your assets, change this if you want to expire all your assets - config.assets.version = '1.0' - - # Set cache headers - config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=31536000' } - - config.active_job.queue_adapter = :delayed_job + # 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 index e9bac116..e319d3f9 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -6,4 +6,5 @@ test: production: adapter: redis - url: <%= ENV['OSEM_REDIS_URL'] %> + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: osem_production diff --git a/config/environment.rb b/config/environment.rb index 09cdef82..a0ed620a 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ -# Load the rails application -require File.expand_path('../application', __FILE__) +# Load the Rails application. +require_relative 'application' # Load the configuration file path = Rails.root.join('config', 'config.yml') @@ -21,5 +21,5 @@ bundle exec rake data:migrate:config2dotenv RAILS_ENV=production " end -# Initialize the rails application -Osem::Application.initialize! +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index c3dcac54..3962662d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,49 +1,67 @@ -Osem::Application.configure do - # Settings specified here will take precedence over those in config/application.rb - - config.action_mailer.delivery_method = :letter_opener +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 # since you don't have to restart the web server when you make code changes. config.cache_classes = false - config.cache_store = :memory_store, { size: 64.megabytes } - - # Show full error reports and disable caching - config.consider_all_requests_local = true - config.action_controller.perform_caching = false - - # Don't care if the mailer can't send - config.action_mailer.raise_delivery_errors = false - - # Print deprecation notices to the Rails logger - config.active_support.deprecation = :log - - # Only use best-standards-support built into browsers - config.action_dispatch.best_standards_support = :builtin - - # Raise exception on mass assignment protection for Active Record models - # config.active_record.mass_assignment_sanitizer = :strict - - # Do not compress assets - config.assets.compress = false - - # Expands the lines which load the assets - config.assets.debug = true - # Do not eager load code on boot. config.eager_load = false - # Do not log asset requests + # Show full error reports. + config.consider_all_requests_local = 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? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + 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 + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # 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. + config.assets.debug = true + + # Suppress logger output for asset requests. config.assets.quiet = true + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = 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 + # Set the detault url for action mailer config.action_mailer.default_url_options = { host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000') } - # Set the secret key base if it's not set via other means - config.secret_key_base ||= 'f4be765bc98e516de82ac01daa8f8aa11c5ca13cb6c911887851ac89457b6c0b056b2361a21b5c08926c9386e0f91eef84fc0b103d522bf00bc0c78ea8ce7c58' - # Use omniauth mock credentials OmniAuth.config.test_mode = true @@ -113,5 +131,4 @@ Osem::Application.configure do devise_config.ichain_test_mode = true end end - end diff --git a/config/environments/production.rb b/config/environments/production.rb index 60e023a0..3d1cd214 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,62 +1,59 @@ -Osem::Application.configure do - # Settings specified here will take precedence over those in config/application.rb +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. - # Code is not reloaded between requests + # Code is not reloaded between requests. config.cache_classes = true - # Full error reports are disabled and caching is turned on - config.consider_all_requests_local = false - config.action_controller.perform_caching = true - # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both thread web servers + # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true - # Disable Rails's static asset server (Apache or nginx will already do this) - config.public_file_server.enabled = false - # Compress JavaScripts and CSS - config.assets.compress = true + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true - # Don't fallback to assets pipeline if a precompiled asset is missed - config.assets.compile = false - - # Generate digests for assets URLs - config.assets.digest = true - - config.assets.css_compressor = :sass - config.assets.js_compressor = :uglifier - config.assets.gzip = true - - # Defaults to nil and saved in location specified by config.assets.prefix - # config.assets.manifest = YOUR_PATH - - # 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 - - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - config.force_ssl = !!ENV['FORCE_SSL'] - - # See everything in the log (default is :info) - config.log_level = ENV['OSEM_LOG_LEVEL'].try(:to_sym) || :info - - # Prepend all log lines with the following tags - config.log_tags = [:uuid] + # 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. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + config.assets.css_compressor = :sass + config.assets.gzip = true - # Use a different cache store in production - # config.cache_store = :mem_cache_store + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.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 + + # 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.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + config.force_ssl = !!ENV['FORCE_SSL'] + + # Prepend all log lines with the following tags. + config.log_tags = [:request_id] + + # Use a different cache store in production. if ENV["OSEM_MEMCACHED_SERVERS"] config.cache_store = :mem_cache_store, ENV["OSEM_MEMCACHED_SERVERS"].split(','), { username: ENV["OSEM_MEMCACHED_USERNAME"], @@ -64,25 +61,16 @@ Osem::Application.configure do } end - # Enable serving of images, stylesheets, and JavaScripts from an asset server - # config.action_controller.asset_host = "http://assets.example.com" + # 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 = "osem_#{Rails.env}" - # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) - # config.assets.precompile += %w( search.js ) + config.action_mailer.perform_caching = false - # Disable delivery errors, bad email addresses will be ignored + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false - # Enable threaded mode - # config.threadsafe! - - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found) - config.i18n.fallbacks = true - - # Send deprecation notices to registered listeners - config.active_support.deprecation = :notify - # Set the detault url for action mailer config.action_mailer.default_url_options = { host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000') } @@ -99,6 +87,30 @@ Osem::Application.configure do openssl_verify_mode: ENV['OSEM_SMTP_OPENSSL_VERIFY_MODE'] } - # Set the secret_key_base from the env, if not set by any other means - config.secret_key_base ||= ENV["SECRET_KEY_BASE"] + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = ENV['OSEM_LOG_LEVEL'].try(:to_sym) || :info + + # 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') + + 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 end diff --git a/config/environments/test.rb b/config/environments/test.rb index 225ae26f..71bfa471 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,5 +1,5 @@ -Osem::Application.configure do - # Settings specified here will take precedence over those in config/application.rb +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that @@ -7,42 +7,45 @@ Osem::Application.configure do # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - # Configure static asset server for tests with Cache-Control for performance - config.public_file_server.enabled = true - config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } - - # Do not eager load code on boot. + # 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 - # Show full error reports and disable caching + # 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}" + } + + # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false - # Raise exceptions instead of rendering exception templates + # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false - # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + # 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 + + # Set the default url for action mailer + config.action_mailer.default_url_options = { host: 'localhost:3000' } + + config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Raise exception on mass assignment protection for Active Record models - # config.active_record.mass_assignment_sanitizer = :strict - - # Print deprecation notices to the stderr + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Set the detault url for action mailer - config.action_mailer.default_url_options = { host: 'localhost:3000' } - - # Do not perform deliveries on test - config.action_mailer.perform_deliveries = false - - # Set the secret key base if it's not set via other means - config.secret_key_base ||= 'f4be765bc98e516de82ac01daa8f8aa11c5ca13cb6c911887851ac89457b6c0b056b2361a21b5c08926c9386e0f91eef84fc0b103d522bf00bc0c78ea8ce7c58' + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true config.after_initialize do ActiveRecord::Base.logger = nil @@ -51,5 +54,4 @@ Osem::Application.configure do Timecop.travel(t) ActiveSupport::Deprecation.silenced = true end - end diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 51639b67..89d2efab 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,6 +1,8 @@ # Be sure to restart your server when you modify this file. -# ApplicationController.renderer.defaults.merge!( -# http_host: 'example.org', -# https: false -# ) +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 01ef3e66..4b828e80 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -3,9 +3,12 @@ # 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 +# Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') # Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -# Rails.application.config.assets.precompile += %w( search.js ) +# 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 ) diff --git a/config/initializers/cache_headers.rb b/config/initializers/cache_headers.rb new file mode 100644 index 00000000..e2604a7b --- /dev/null +++ b/config/initializers/cache_headers.rb @@ -0,0 +1,2 @@ +# Set cache headers +Rails.application.config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=31536000' } 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/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 1389e86a..5a6a32d3 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -2,4 +2,4 @@ # Specify a serializer for the signed and encrypted cookie jars. # Valid options are :json, :marshal, and :hybrid. -Rails.application.config.action_dispatch.cookies_serializer = :marshal +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/delayed_job.rb b/config/initializers/delayed_job.rb new file mode 100644 index 00000000..343c0bd2 --- /dev/null +++ b/config/initializers/delayed_job.rb @@ -0,0 +1 @@ +Rails.application.config.active_job.queue_adapter = :delayed_job diff --git a/config/initializers/json.rb b/config/initializers/json.rb new file mode 100644 index 00000000..c7fced94 --- /dev/null +++ b/config/initializers/json.rb @@ -0,0 +1,2 @@ +# Enable escaping HTML in JSON. +Rails.application.config.active_support.escape_html_entities_in_json = true diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb deleted file mode 100644 index dc189968..00000000 --- a/config/initializers/mime_types.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new mime types for use in respond_to blocks: -# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb index cbf423a8..33194b55 100644 --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -19,7 +19,4 @@ Rails.application.config.action_controller.forgery_protection_origin_check = fal ActiveSupport.to_time_preserves_timezone = false # Require `belongs_to` associations by default. Previous versions had false. -Rails.application.config.active_record.belongs_to_required_by_default = false - -# Do not halt callback chains when a callback returns false. Previous versions had true. -ActiveSupport.halt_callback_chains_on_return_false = true +ActiveRecord::Base.belongs_to_required_by_default = false 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/timezone.rb b/config/initializers/timezone.rb new file mode 100644 index 00000000..09dde7fe --- /dev/null +++ b/config/initializers/timezone.rb @@ -0,0 +1,3 @@ +# 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. +Rails.application.config.time_zone = (ENV['OSEM_TIME_ZONE'] || 'UTC') diff --git a/config/locales/en.yml b/config/locales/en.yml index 1a1147e0..a99b6ddd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,8 +1,35 @@ -# Sample localization file for English. Add more files in this directory for other locales. -# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. en: - hello: "Hello world" time: formats: short: "%Y-%m-%dT%H:%M:%S" diff --git a/config/spring.rb b/config/spring.rb index c9119b40..9fa7863f 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,6 +1,6 @@ -%w( +%w[ .ruby-version .rbenv-vars tmp/restart.txt tmp/caching-dev.txt -).each { |path| Spring.watch(path) } +].each { |path| Spring.watch(path) } 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 ]