# HG changeset patch # User Nattee Niparnan # Date 2019-07-03 05:57:48 # Node ID 0e4dc1847f889637bf5d1ab4ad39d452fdc67415 # Parent 4c1b44c35caff5a442b6cec986389d3c7a2bd77c start migrate to 5.0 diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' #rails -gem 'rails', '~>4.2.0' +gem 'rails', '~>5.0' gem 'activerecord-session_store' diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,48 +13,51 @@ ZenTest (~> 4.3) ZenTest (4.11.2) ace-rails-ap (4.2) - actionmailer (4.2.11.1) - actionpack (= 4.2.11.1) - actionview (= 4.2.11.1) - activejob (= 4.2.11.1) + 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) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.11.1) - actionview (= 4.2.11.1) - activesupport (= 4.2.11.1) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) + actionpack (5.0.7.2) + actionview (= 5.0.7.2) + activesupport (= 5.0.7.2) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.11.1) - activesupport (= 4.2.11.1) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) builder (~> 3.1) erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.11.1) - activesupport (= 4.2.11.1) - globalid (>= 0.3.0) - activemodel (4.2.11.1) - activesupport (= 4.2.11.1) - builder (~> 3.1) - activerecord (4.2.11.1) - activemodel (= 4.2.11.1) - activesupport (= 4.2.11.1) - arel (~> 6.0) + activejob (5.0.7.2) + activesupport (= 5.0.7.2) + 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) activerecord-session_store (1.1.3) actionpack (>= 4.0) activerecord (>= 4.0) multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0) - activesupport (4.2.11.1) - i18n (~> 0.7) + activesupport (5.0.7.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) ansi (1.5.0) - arel (6.0.4) + arel (7.1.4) autoprefixer-rails (9.5.1.1) execjs best_in_place (3.0.3) @@ -101,7 +104,7 @@ haml (>= 4.0, < 6) nokogiri (>= 1.6.0) ruby_parser (~> 3.5) - i18n (0.9.5) + i18n (1.6.0) concurrent-ruby (~> 1.0) in_place_editing (1.2.0) jquery-countdown-rails (2.0.2) @@ -125,6 +128,7 @@ nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) + method_source (0.9.2) mini_mime (1.0.1) mini_portile2 (2.4.0) minitest (5.11.3) @@ -137,35 +141,35 @@ railties (>= 3.1) multi_json (1.13.1) mysql2 (0.5.2) + nio4r (2.3.1) nokogiri (1.10.3) mini_portile2 (~> 2.4.0) - rack (1.6.11) + rack (2.0.7) rack-test (0.6.3) rack (>= 1.0) - rails (4.2.11.1) - actionmailer (= 4.2.11.1) - actionpack (= 4.2.11.1) - actionview (= 4.2.11.1) - activejob (= 4.2.11.1) - activemodel (= 4.2.11.1) - activerecord (= 4.2.11.1) - activesupport (= 4.2.11.1) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.11.1) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.9) - activesupport (>= 4.2.0, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) + 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) + bundler (>= 1.3.0) + railties (= 5.0.7.2) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) rails_bootstrap_sortable (2.0.6) momentjs-rails (>= 2.8.3) - railties (4.2.11.1) - actionpack (= 4.2.11.1) - activesupport (= 4.2.11.1) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (12.3.2) @@ -216,6 +220,9 @@ thread_safe (~> 0.1) uglifier (4.1.20) execjs (>= 0.3.0, < 3) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.4) will_paginate (3.0.12) yaml_db (0.7.0) rails (>= 3.0) @@ -250,7 +257,7 @@ minitest-reporters momentjs-rails mysql2 - rails (~> 4.2.0) + rails (~> 5.0) rails_bootstrap_sortable rdiscount rouge diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/bin/bundle b/bin/bundle new file mode 100755 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 --- /dev/null +++ b/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/update b/bin/update new file mode 100755 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/config/boot.rb b/config/boot.rb --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,3 @@ -require 'rubygems' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -# Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) - -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,9 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: redis://localhost:6379/1 diff --git a/config/database.yml.SAMPLE b/config/database.yml.SAMPLE deleted file mode 100644 --- a/config/database.yml.SAMPLE +++ /dev/null @@ -1,42 +0,0 @@ -# MySQL. Versions 4.1 and 5.0 are recommended. -# -# Install the MYSQL driver -# gem install mysql2 -# -# Ensure the MySQL gem is defined in your Gemfile -# gem 'mysql2' -# -# And be sure to use new-style password hashing: -# http://dev.mysql.com/doc/refman/5.0/en/old-client.html -development: - adapter: mysql2 - encoding: utf8 - reconnect: false - database: ioi - pool: 5 - username: ioi - password: ioi - socket: /var/run/mysqld/mysqld.sock - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - adapter: mysql2 - encoding: utf8 - reconnect: false - database: ioi_test - pool: 5 - username: ioi - password: ioi - socket: /var/run/mysqld/mysqld.sock - -production: - adapter: mysql2 - encoding: utf8 - reconnect: false - database: ioi - pool: 5 - username: ioi - password: ioi - socket: /var/run/mysqld/mysqld.sock diff --git a/config/environment.rb b/config/environment.rb --- 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' -# Initialize the rails application -CafeGrader::Application.initialize! +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,42 +1,54 @@ -CafeGrader::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. # 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 - # Log error messages when you accidentally call methods on nil. //DEPRICATED - # config.whiny_nils = true // DEPRICATED + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true - # Show full error reports and disable caching - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=172800' + } + else + config.action_controller.perform_caching = false - # Don't care if the mailer can't send + config.cache_store = :null_store + end + + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false - # Print deprecation notices to the Rails logger + config.action_mailer.perform_caching = 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 //DEPRICATED + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load - # Log the query plan for queries taking more than this (works // DEPRICATED - # with SQLite, MySQL, and PostgreSQL) // DEPRICATED - # config.active_record.auto_explain_threshold_in_seconds = 0.5 // DEPRICATED - - # Do not compress assets - config.assets.compress = false - - # Expands the lines which load the assets + # 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 - # Prevents assets from rendering twice - config.serve_static_files = true + # Suppress logger output for asset requests. + config.assets.quiet = true - config.eager_load = false + # 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 end diff --git a/config/environments/production.rb b/config/environments/production.rb --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,69 +1,86 @@ -CafeGrader::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 + # Eager load code on boot. This eager loads most of Rails and + # 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 + + # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_files = false + # 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? - # Compress JavaScripts and CSS - config.assets.compress = true + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass - # Don't fallback to assets pipeline if a precompiled asset is missed + # Do not 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.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' - # 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 - # 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 + # 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 = true - # See everything in the log (default is :info) - # config.log_level = :debug + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug - # Prepend all log lines with the following tags - # config.log_tags = [ :subdomain, :uuid ] + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] - # Use a different logger for distributed setups - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) - - # Use a different cache store in production + # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server - # config.action_controller.asset_host = "http://assets.example.com" - - # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) - # config.assets.precompile += %w( search.js ) + # 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 = "cafe_grader_#{Rails.env}" + 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) + # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners + # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - # config.active_record.auto_explain_threshold_in_seconds = 0.5 + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - config.eager_load = true + 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 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,5 +1,5 @@ -CafeGrader::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,37 +7,36 @@ # 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.serve_static_files = true - config.static_cache_control = "public, max-age=3600" + # 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 - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true + # 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=3600' + } - # Show full error reports and disable caching + # 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 + 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 // DEPRICATED - - # Print deprecation notices to the stderr + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - config.eager_load = false - - #test order - config.active_support.test_order = :sorted - + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# 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 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -3,20 +3,15 @@ # 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') -Rails.application.config.assets.paths << Rails.root.join('vendor/assets/fonts') # 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 ) - +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) Rails.application.config.assets.precompile += ['announcement_refresh.js','effects.js','site_update.js'] Rails.application.config.assets.precompile += ['local_jquery.js','tablesorter-theme.cafe.css'] -%w( announcements submissions configurations contests contest_management graders heartbeat +%w( announcements submissions configurations contests contest_management graders heartbeat login main messages problems report site sites sources tasks groups test user_admin users tags testcases).each do |controller| Rails.application.config.assets.precompile += ["#{controller}.js", "#{controller}.css"] diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# 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 diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# 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] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,15 +1,16 @@ # Be sure to restart your server when you modify this file. -# Add new inflection rules using the following format -# (all these examples are active by default): -# ActiveSupport::Inflector.inflections do |inflect| +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end -# + # These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections do |inflect| +# ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym 'RESTful' # end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,4 +2,3 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb new file mode 100644 --- /dev/null +++ b/config/initializers/new_framework_defaults.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.0 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. + +Rails.application.config.action_controller.raise_on_unfiltered_parameters = true + +# Enable per-form CSRF tokens. Previous versions had false. +Rails.application.config.action_controller.per_form_csrf_tokens = false + +# Enable origin-checking CSRF mitigation. Previous versions had false. +Rails.application.config.action_controller.forgery_protection_origin_check = false + +# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. +# Previous versions had false. +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 diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,8 +1,3 @@ # Be sure to restart your server when you modify this file. -#CafeGrader::Application.config.session_store :cookie_store, key: '_cafe_grader_web_session' -# Use the database for sessions instead of the cookie-based default, -# which shouldn't be used to store highly confidential information -# (create the session table with "rails generate session_migration") - -CafeGrader::Application.config.session_store :active_record_store +Rails.application.config.session_store :cookie_store, key: '_cafe_grader_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,5 +1,5 @@ # Be sure to restart your server when you modify this file. -# + # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. @@ -8,7 +8,7 @@ wrap_parameters format: [:json] end -# Disable root element in JSON by default. -ActiveSupport.on_load(:active_record) do - self.include_root_in_json = false -end +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,47 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum, this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# 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`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# 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. +# +# preload_app! + +# 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 `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, 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/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -110,5 +110,5 @@ # This is a legacy wild controller route that's not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. - match ':controller(/:action(/:id))(.:format)', via: [:get, :post] + # match ':controller(/:action(/:id))(.:format)', via: [:get, :post] end diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w( + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +).each { |path| Spring.watch(path) } diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -13,309 +12,296 @@ ActiveRecord::Schema.define(version: 20180612102327) do - create_table "announcements", force: :cascade do |t| - t.string "author", limit: 255 + create_table "announcements", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "author" t.text "body", limit: 65535 t.boolean "published" t.datetime "created_at" t.datetime "updated_at" t.boolean "frontpage", default: false t.boolean "contest_only", default: false - t.string "title", limit: 255 - t.string "notes", limit: 255 + t.string "title" + t.string "notes" end - create_table "contests", force: :cascade do |t| - t.string "title", limit: 255 + create_table "contests", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "title" t.boolean "enabled" t.datetime "created_at" t.datetime "updated_at" - t.string "name", limit: 255 + t.string "name" end - create_table "contests_problems", id: false, force: :cascade do |t| - t.integer "contest_id", limit: 4 - t.integer "problem_id", limit: 4 + create_table "contests_problems", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "contest_id" + t.integer "problem_id" end - create_table "contests_users", id: false, force: :cascade do |t| - t.integer "contest_id", limit: 4 - t.integer "user_id", limit: 4 + create_table "contests_users", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "contest_id" + t.integer "user_id" end - create_table "countries", force: :cascade do |t| - t.string "name", limit: 255 + create_table "countries", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "name" t.datetime "created_at" t.datetime "updated_at" end - create_table "descriptions", force: :cascade do |t| + create_table "descriptions", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| t.text "body", limit: 65535 t.boolean "markdowned" t.datetime "created_at" t.datetime "updated_at" end - create_table "grader_configurations", force: :cascade do |t| - t.string "key", limit: 255 - t.string "value_type", limit: 255 - t.string "value", limit: 255 + create_table "grader_configurations", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "key" + t.string "value_type" + t.string "value" t.datetime "created_at" t.datetime "updated_at" t.text "description", limit: 65535 end - create_table "grader_processes", force: :cascade do |t| - t.string "host", limit: 255 - t.integer "pid", limit: 4 - t.string "mode", limit: 255 + create_table "grader_processes", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "host" + t.integer "pid" + t.string "mode" t.boolean "active" t.datetime "created_at" t.datetime "updated_at" - t.integer "task_id", limit: 4 - t.string "task_type", limit: 255 + t.integer "task_id" + t.string "task_type" t.boolean "terminated" + t.index ["host", "pid"], name: "index_grader_processes_on_host_and_pid", using: :btree end - add_index "grader_processes", ["host", "pid"], name: "index_grader_processes_on_host_and_pid", using: :btree - - create_table "groups", force: :cascade do |t| - t.string "name", limit: 255 - t.string "description", limit: 255 + create_table "groups", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "name" + t.string "description" end - create_table "groups_problems", id: false, force: :cascade do |t| - t.integer "problem_id", limit: 4, null: false - t.integer "group_id", limit: 4, null: false + create_table "groups_problems", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "problem_id", null: false + t.integer "group_id", null: false + t.index ["group_id", "problem_id"], name: "index_groups_problems_on_group_id_and_problem_id", using: :btree end - add_index "groups_problems", ["group_id", "problem_id"], name: "index_groups_problems_on_group_id_and_problem_id", using: :btree - - create_table "groups_users", id: false, force: :cascade do |t| - t.integer "group_id", limit: 4, null: false - t.integer "user_id", limit: 4, null: false + create_table "groups_users", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "group_id", null: false + t.integer "user_id", null: false + t.index ["user_id", "group_id"], name: "index_groups_users_on_user_id_and_group_id", using: :btree end - add_index "groups_users", ["user_id", "group_id"], name: "index_groups_users_on_user_id_and_group_id", using: :btree - - create_table "heart_beats", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.string "ip_address", limit: 255 + create_table "heart_beats", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "user_id" + t.string "ip_address" t.datetime "created_at" t.datetime "updated_at" - t.string "status", limit: 255 + t.string "status" + t.index ["updated_at"], name: "index_heart_beats_on_updated_at", using: :btree end - add_index "heart_beats", ["updated_at"], name: "index_heart_beats_on_updated_at", using: :btree - - create_table "languages", force: :cascade do |t| + create_table "languages", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| t.string "name", limit: 10 - t.string "pretty_name", limit: 255 + t.string "pretty_name" t.string "ext", limit: 10 - t.string "common_ext", limit: 255 + t.string "common_ext" end - create_table "logins", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.string "ip_address", limit: 255 + create_table "logins", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "user_id" + t.string "ip_address" t.datetime "created_at" t.datetime "updated_at" end - create_table "messages", force: :cascade do |t| - t.integer "sender_id", limit: 4 - t.integer "receiver_id", limit: 4 - t.integer "replying_message_id", limit: 4 + create_table "messages", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "sender_id" + t.integer "receiver_id" + t.integer "replying_message_id" t.text "body", limit: 65535 t.boolean "replied" t.datetime "created_at" t.datetime "updated_at" end - create_table "problems", force: :cascade do |t| + create_table "problems", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| t.string "name", limit: 30 - t.string "full_name", limit: 255 - t.integer "full_score", limit: 4 + t.string "full_name" + t.integer "full_score" t.date "date_added" t.boolean "available" - t.string "url", limit: 255 - t.integer "description_id", limit: 4 + t.string "url" + t.integer "description_id" t.boolean "test_allowed" t.boolean "output_only" - t.string "description_filename", limit: 255 + t.string "description_filename" t.boolean "view_testcase" end - create_table "problems_tags", force: :cascade do |t| - t.integer "problem_id", limit: 4 - t.integer "tag_id", limit: 4 + create_table "problems_tags", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "problem_id" + t.integer "tag_id" + t.index ["problem_id", "tag_id"], name: "index_problems_tags_on_problem_id_and_tag_id", unique: true, using: :btree + t.index ["problem_id"], name: "index_problems_tags_on_problem_id", using: :btree + t.index ["tag_id"], name: "index_problems_tags_on_tag_id", using: :btree end - add_index "problems_tags", ["problem_id", "tag_id"], name: "index_problems_tags_on_problem_id_and_tag_id", unique: true, using: :btree - add_index "problems_tags", ["problem_id"], name: "index_problems_tags_on_problem_id", using: :btree - add_index "problems_tags", ["tag_id"], name: "index_problems_tags_on_tag_id", using: :btree - - create_table "rights", force: :cascade do |t| - t.string "name", limit: 255 - t.string "controller", limit: 255 - t.string "action", limit: 255 + create_table "rights", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "name" + t.string "controller" + t.string "action" end - create_table "rights_roles", id: false, force: :cascade do |t| - t.integer "right_id", limit: 4 - t.integer "role_id", limit: 4 + create_table "rights_roles", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "right_id" + t.integer "role_id" + t.index ["role_id"], name: "index_rights_roles_on_role_id", using: :btree end - add_index "rights_roles", ["role_id"], name: "index_rights_roles_on_role_id", using: :btree - - create_table "roles", force: :cascade do |t| - t.string "name", limit: 255 + create_table "roles", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "name" end - create_table "roles_users", id: false, force: :cascade do |t| - t.integer "role_id", limit: 4 - t.integer "user_id", limit: 4 + create_table "roles_users", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "role_id" + t.integer "user_id" + t.index ["user_id"], name: "index_roles_users_on_user_id", using: :btree end - add_index "roles_users", ["user_id"], name: "index_roles_users_on_user_id", using: :btree - - create_table "sessions", force: :cascade do |t| - t.string "session_id", limit: 255 + create_table "sessions", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "session_id" t.text "data", limit: 65535 t.datetime "updated_at" + t.index ["session_id"], name: "index_sessions_on_session_id", using: :btree + t.index ["updated_at"], name: "index_sessions_on_updated_at", using: :btree end - add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree - add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree - - create_table "sites", force: :cascade do |t| - t.string "name", limit: 255 + create_table "sites", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "name" t.boolean "started" t.datetime "start_time" t.datetime "created_at" t.datetime "updated_at" - t.integer "country_id", limit: 4 - t.string "password", limit: 255 + t.integer "country_id" + t.string "password" end - create_table "submission_view_logs", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "submission_id", limit: 4 + create_table "submission_view_logs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "user_id" + t.integer "submission_id" t.datetime "created_at" t.datetime "updated_at" end - create_table "submissions", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "problem_id", limit: 4 - t.integer "language_id", limit: 4 + create_table "submissions", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "user_id" + t.integer "problem_id" + t.integer "language_id" t.text "source", limit: 16777215 t.binary "binary", limit: 65535 t.datetime "submitted_at" t.datetime "compiled_at" t.text "compiler_message", limit: 65535 t.datetime "graded_at" - t.integer "points", limit: 4 + t.integer "points" t.text "grader_comment", limit: 65535 - t.integer "number", limit: 4 - t.string "source_filename", limit: 255 + t.integer "number" + t.string "source_filename" t.float "max_runtime", limit: 24 - t.integer "peak_memory", limit: 4 - t.integer "effective_code_length", limit: 4 - t.string "ip_address", limit: 255 + t.integer "peak_memory" + t.integer "effective_code_length" + t.string "ip_address" + t.index ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true, using: :btree + t.index ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree end - add_index "submissions", ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true, using: :btree - add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree - - create_table "tags", force: :cascade do |t| - t.string "name", limit: 255, null: false + create_table "tags", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.string "name", null: false t.text "description", limit: 65535 t.boolean "public" t.datetime "created_at", null: false t.datetime "updated_at", null: false end - create_table "tasks", force: :cascade do |t| - t.integer "submission_id", limit: 4 + create_table "tasks", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "submission_id" t.datetime "created_at" - t.integer "status", limit: 4 + t.integer "status" t.datetime "updated_at" + t.index ["submission_id"], name: "index_tasks_on_submission_id", using: :btree end - add_index "tasks", ["submission_id"], name: "index_tasks_on_submission_id", using: :btree - - create_table "test_pairs", force: :cascade do |t| - t.integer "problem_id", limit: 4 + create_table "test_pairs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "problem_id" t.text "input", limit: 16777215 t.text "solution", limit: 16777215 t.datetime "created_at" t.datetime "updated_at" end - create_table "test_requests", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "problem_id", limit: 4 - t.integer "submission_id", limit: 4 - t.string "input_file_name", limit: 255 - t.string "output_file_name", limit: 255 - t.string "running_stat", limit: 255 - t.integer "status", limit: 4 + create_table "test_requests", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "user_id" + t.integer "problem_id" + t.integer "submission_id" + t.string "input_file_name" + t.string "output_file_name" + t.string "running_stat" + t.integer "status" t.datetime "updated_at" t.datetime "submitted_at" t.datetime "compiled_at" t.text "compiler_message", limit: 65535 t.datetime "graded_at" - t.string "grader_comment", limit: 255 + t.string "grader_comment" t.datetime "created_at" t.float "running_time", limit: 24 - t.string "exit_status", limit: 255 - t.integer "memory_usage", limit: 4 + t.string "exit_status" + t.integer "memory_usage" + t.index ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id", using: :btree end - add_index "test_requests", ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id", using: :btree - - create_table "testcases", force: :cascade do |t| - t.integer "problem_id", limit: 4 - t.integer "num", limit: 4 - t.integer "group", limit: 4 - t.integer "score", limit: 4 + create_table "testcases", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "problem_id" + t.integer "num" + t.integer "group" + t.integer "score" t.text "input", limit: 4294967295 t.text "sol", limit: 4294967295 t.datetime "created_at" t.datetime "updated_at" + t.index ["problem_id"], name: "index_testcases_on_problem_id", using: :btree end - add_index "testcases", ["problem_id"], name: "index_testcases_on_problem_id", using: :btree - - create_table "user_contest_stats", force: :cascade do |t| - t.integer "user_id", limit: 4 + create_table "user_contest_stats", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| + t.integer "user_id" t.datetime "started_at" t.datetime "created_at" t.datetime "updated_at" t.boolean "forced_logout" end - create_table "users", force: :cascade do |t| + create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t| t.string "login", limit: 50 - t.string "full_name", limit: 255 - t.string "hashed_password", limit: 255 + t.string "full_name" + t.string "hashed_password" t.string "salt", limit: 5 - t.string "alias", limit: 255 - t.string "email", limit: 255 - t.integer "site_id", limit: 4 - t.integer "country_id", limit: 4 - t.boolean "activated", default: false + t.string "alias" + t.string "email" + t.integer "site_id" + t.integer "country_id" + t.boolean "activated", default: false t.datetime "created_at" t.datetime "updated_at" - t.string "section", limit: 255 - t.boolean "enabled", default: true - t.string "remark", limit: 255 - t.string "last_ip", limit: 255 + t.string "section" + t.boolean "enabled", default: true + t.string "remark" + t.string "last_ip" + t.index ["login"], name: "index_users_on_login", unique: true, using: :btree end - add_index "users", ["login"], name: "index_users_on_login", unique: true, using: :btree - add_foreign_key "problems_tags", "problems" add_foreign_key "problems_tags", "tags" end