From 20c81a25b9af59bc2aa1558c446b73cc932fc394 Mon Sep 17 00:00:00 2001 From: Cess Date: Sun, 5 May 2019 06:08:43 +0300 Subject: [PATCH 001/152] ActiveSupport::Testing::Performance extracted to a gem --- Gemfile | 1 + Gemfile.lock | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 92051d954..1e8d37b90 100644 --- a/Gemfile +++ b/Gemfile @@ -44,6 +44,7 @@ group :test do gem 'simplecov', require: false gem 'simplecov-cobertura', require: false gem 'test-unit' + gem 'rails-perftest' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index d781a44a8..f3ed72068 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -130,6 +130,7 @@ GEM activesupport (= 3.2.22.5) bundler (~> 1.0) railties (= 3.2.22.5) + rails-perftest (0.0.7) railties (3.2.22.5) actionpack (= 3.2.22.5) activesupport (= 3.2.22.5) @@ -223,6 +224,7 @@ DEPENDENCIES popper_js (~> 1.11, >= 1.11.1) pry-rails rails (~> 3.2) + rails-perftest rake (~> 12.3.2) rdiscount (= 2.2.0.1) recaptcha From d4131fde8b988deda68e5c99a2f4630b31cf9e86 Mon Sep 17 00:00:00 2001 From: Cess Date: Sun, 5 May 2019 06:12:58 +0300 Subject: [PATCH 002/152] ruby prof required as a dependency --- Gemfile | 3 ++- Gemfile.lock | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 1e8d37b90..bbc1f2d49 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,7 @@ group :dependencies do gem "open_id_authentication" gem "RubyInline" gem "paperclip", "~>4.3.7" + gem 'ruby-prof' # if you use amazon s3 for warpable image storage gem 'aws-sdk', '~> 1.5.7' @@ -43,8 +44,8 @@ group :test do gem "rubocop", '~> 0.52.0' gem 'simplecov', require: false gem 'simplecov-cobertura', require: false - gem 'test-unit' gem 'rails-perftest' + gem 'test-unit' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index f3ed72068..fe9f980c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -162,6 +162,7 @@ GEM ruby-openid (2.7.0) ruby-openid-apps-discovery (1.2.0) ruby-openid (>= 2.1.7) + ruby-prof (0.18.0) ruby-progressbar (1.10.1) sass (3.7.4) sass-listen (~> 4.0.0) @@ -231,6 +232,7 @@ DEPENDENCIES right_aws rubocop (~> 0.52.0) ruby-openid (~> 2.5) + ruby-prof sass simplecov simplecov-cobertura @@ -247,4 +249,4 @@ RUBY VERSION ruby 2.4.6p354 BUNDLED WITH - 1.16.6 + 1.17.3 From 9c219521980a89b19262664e6a68588a8d96b898 Mon Sep 17 00:00:00 2001 From: Cess Date: Sun, 5 May 2019 05:15:27 +0300 Subject: [PATCH 003/152] Configurations update for rails 4.0 --- Gemfile | 6 +- Gemfile.lock | 163 ++++++++++-------- bin/bundle | 3 + bin/rails | 4 + bin/rake | 4 + bin/setup | 29 ++++ config/application.rb | 27 +-- config/boot.rb | 5 +- config/environment.rb | 4 +- config/environments/development.rb | 37 ++-- config/environments/production.rb | 89 +++++----- config/environments/test.rb | 32 ++-- config/initializers/assets.rb | 11 ++ config/initializers/cookies_serializer.rb | 3 + .../initializers/filter_parameter_logging.rb | 4 + config/initializers/inflections.rb | 11 +- config/initializers/mime_types.rb | 1 - config/initializers/session_store.rb | 7 +- config/initializers/wrap_parameters.rb | 6 +- config/locales/en.yml | 22 ++- config/secrets.yml | 22 +++ 21 files changed, 304 insertions(+), 186 deletions(-) create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/cookies_serializer.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/secrets.yml diff --git a/Gemfile b/Gemfile index bbc1f2d49..e3360daf2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" -ruby "2.4.6" -gem "rails", "~>3.2" +ruby '2.4.6' +gem 'rails', '~>4.0' gem 'rake', '~> 12.3.2' gem 'skylight' @@ -42,9 +42,9 @@ end group :test do gem "rubocop", '~> 0.52.0' + gem 'rails-perftest' gem 'simplecov', require: false gem 'simplecov-cobertura', require: false - gem 'rails-perftest' gem 'test-unit' end diff --git a/Gemfile.lock b/Gemfile.lock index fe9f980c6..a4ac481c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,34 +4,41 @@ GEM RubyInline (3.12.4) ZenTest (~> 4.3) ZenTest (4.11.2) - actionmailer (3.2.22.5) - actionpack (= 3.2.22.5) - mail (~> 2.5.4) - actionpack (3.2.22.5) - activemodel (= 3.2.22.5) - activesupport (= 3.2.22.5) - builder (~> 3.0.0) + actionmailer (4.2.11.1) + actionpack (= 4.2.11.1) + actionview (= 4.2.11.1) + activejob (= 4.2.11.1) + 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-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.11.1) + activesupport (= 4.2.11.1) + builder (~> 3.1) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.5) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activemodel (3.2.22.5) - activesupport (= 3.2.22.5) - builder (~> 3.0.0) - activerecord (3.2.22.5) - activemodel (= 3.2.22.5) - activesupport (= 3.2.22.5) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.22.5) - activemodel (= 3.2.22.5) - activesupport (= 3.2.22.5) - activesupport (3.2.22.5) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - arel (3.0.3) + rails-dom-testing (~> 1.0, >= 1.0.5) + 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) + activesupport (4.2.11.1) + i18n (~> 0.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + arel (6.0.4) ast (2.4.0) autoprefixer-rails (9.5.1.1) execjs @@ -40,45 +47,53 @@ GEM json (~> 1.4) nokogiri (>= 1.4.4) uuidtools (~> 2.1) - builder (3.0.4) + builder (3.2.3) byebug (11.0.1) climate_control (0.2.0) cocaine (0.5.8) climate_control (>= 0.0.3, < 1.0) coderay (1.1.2) concurrent-ruby (1.1.5) + crass (1.0.4) docile (1.3.1) erubis (2.7.0) execjs (2.7.0) faker (1.9.3) i18n (>= 0.7) ffi (1.11.1) - friendly_id (4.0.10.1) - activerecord (>= 3.0, < 4.0) + friendly_id (5.2.5) + activerecord (>= 4.0.0) geokit (1.13.1) geokit-rails (1.1.4) geokit (>= 1.5.0) - hike (1.2.3) - httparty (0.16.2) + globalid (0.4.2) + activesupport (>= 4.2.0) + httparty (0.17.0) + mime-types (~> 3.0) multi_xml (>= 0.5.2) i18n (0.9.5) concurrent-ruby (~> 1.0) image_science (1.3.0) RubyInline (~> 3.9) - journey (1.0.4) jshintrb (0.3.0) execjs multi_json (>= 1.3) rake json (1.8.6) libv8 (3.16.14.19) - mail (2.5.5) - mime-types (~> 1.16) - treetop (~> 1.4.8) + loofah (2.2.3) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) method_source (0.9.2) - mime-types (1.25.1) + mime-types (3.2.2) + mime-types-data (~> 3.2015) + mime-types-data (3.2019.0331) mimemagic (0.3.0) + mini_mime (1.0.1) mini_portile2 (2.4.0) + minitest (5.11.3) multi_json (1.13.1) multi_xml (0.6.0) mysql2 (0.3.21) @@ -103,7 +118,6 @@ GEM passenger (6.0.2) rack rake (>= 0.8.1) - polyglot (0.3.5) popper_js (1.14.5) power_assert (1.1.4) powerpack (0.1.2) @@ -112,40 +126,43 @@ GEM method_source (~> 0.9.0) pry-rails (0.3.9) pry (>= 0.10.4) - rack (1.4.7) - rack-cache (1.9.0) - rack (>= 0.4) + rack (1.6.11) rack-openid (1.3.1) rack (>= 1.1.0) ruby-openid (>= 2.1.8) - rack-ssl (1.3.4) - rack rack-test (0.6.3) rack (>= 1.0) - rails (3.2.22.5) - actionmailer (= 3.2.22.5) - actionpack (= 3.2.22.5) - activerecord (= 3.2.22.5) - activeresource (= 3.2.22.5) - activesupport (= 3.2.22.5) - bundler (~> 1.0) - railties (= 3.2.22.5) + 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-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) rails-perftest (0.0.7) - railties (3.2.22.5) - actionpack (= 3.2.22.5) - activesupport (= 3.2.22.5) - rack-ssl (~> 1.3.2) + railties (4.2.11.1) + actionpack (= 4.2.11.1) + activesupport (= 4.2.11.1) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) + thor (>= 0.18.1, < 2.0) rainbow (3.0.0) rake (12.3.2) rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) rdiscount (2.2.0.1) - rdoc (3.12.2) - json (~> 1.4) recaptcha (4.14.0) json ref (2.0.0) @@ -176,13 +193,17 @@ GEM simplecov-cobertura (1.3.1) simplecov (~> 0.8) simplecov-html (0.10.2) - skylight (1.7.2) - activesupport (>= 3.0.0) - sprockets (2.2.3) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) + skylight (4.0.2) + skylight-core (= 4.0.2) + skylight-core (4.0.2) + activesupport (>= 4.2.0) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) sqlite3 (1.4.1) test-unit (3.3.3) power_assert @@ -190,11 +211,9 @@ GEM libv8 (~> 3.16.14.15) ref thor (0.20.3) - tilt (1.4.1) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - tzinfo (0.3.55) + thread_safe (0.3.6) + tzinfo (1.2.5) + thread_safe (~> 0.1) uglifier (4.1.20) execjs (>= 0.3.0, < 3) unicode-display_width (1.6.0) @@ -224,7 +243,7 @@ DEPENDENCIES passenger popper_js (~> 1.11, >= 1.11.1) pry-rails - rails (~> 3.2) + rails (~> 4.0) rails-perftest rake (~> 12.3.2) rdiscount (= 2.2.0.1) diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 000000000..66e9889e8 --- /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 index 000000000..5191e6927 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 000000000..17240489f --- /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 index 000000000..acdb2c138 --- /dev/null +++ b/bin/setup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +Dir.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 || bundle install" + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # system "cp config/database.yml.sample config/database.yml" + # end + + puts "\n== Preparing database ==" + system "bin/rake db:setup" + + puts "\n== Removing old logs and tempfiles ==" + system "rm -f log/*" + system "rm -rf tmp/cache" + + puts "\n== Restarting application server ==" + system "touch tmp/restart.txt" +end diff --git a/config/application.rb b/config/application.rb index 63217e5ba..09d4d4575 100644 --- a/config/application.rb +++ b/config/application.rb @@ -2,12 +2,9 @@ require 'rails/all' -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 Mapknitter class Application < Rails::Application @@ -19,13 +16,6 @@ class Application < Rails::Application # config.autoload_paths += %W(#{config.root}/extras) config.autoload_paths += %W(#{config.root}/lib/) - # Only load the plugins named here, in the order given (default is alphabetical). - # :all can be used as a placeholder for all plugins not explicitly named. - # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - - # Activate observers that should always be running. - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' @@ -43,16 +33,14 @@ class Application < Rails::Application # 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 + # config.active_record.whitelist_attributes = true + + # Do not swallow errors in after_commit/after_rollback callbacks. + config.active_record.raise_in_transactional_callbacks = true # Enable the asset pipeline config.assets.enabled = true @@ -60,6 +48,5 @@ class Application < Rails::Application # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.3' config.assets.paths << Rails.root.join("public","lib") - end end diff --git a/config/boot.rb b/config/boot.rb index f2830ae31..44358b8e4 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,3 @@ -require 'rubygems' - -# Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) # Set up gems listed in the Gemfile. diff --git a/config/environment.rb b/config/environment.rb index 761c5657b..99fb29737 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ -# Load the rails application +# Load the Rails application. require File.expand_path('../application', __FILE__) -# Initialize the rails application +# Initialize the Rails application. Mapknitter::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index f834629b2..dd73b21a2 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,33 +1,43 @@ Mapknitter::Application.configure do - # Settings specified here will take precedence over those in config/application.rb + # 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. - config.whiny_nils = true + # Do not eager load code on boot. + config.eager_load = false - # 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 - # Don't care if the mailer can't send + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false - # Print deprecation notices to the Rails logger + # 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 an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict + # 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 - # 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 + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true # Do not compress assets config.assets.compress = false @@ -37,5 +47,4 @@ config.serve_static_assets = true config.assets.logger = false - end diff --git a/config/environments/production.rb b/config/environments/production.rb index ca5cdf415..219f7fc32 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,65 +1,74 @@ -require 'uglifier' - Mapknitter::Application.configure do - # Settings specified here will take precedence over those in config/application.rb - # Code is not reloaded between requests + # Settings specified here will take precedence over those in config/application.rb. + + # 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_assets = true + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like + # NGINX, varnish or squid. + # config.action_dispatch.rack_cache = true - # Compress JavaScripts and CSS - config.assets.compress = true + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? - # Don't fallback to assets pipeline if a precompiled asset is missed - config.assets.compile = true + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass - config.assets.js_compressor = Uglifier.new(:harmony => true) + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = true - # Generate digests for assets URLs + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. config.assets.digest = true config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/ config.assets.precompile += ['tags.js', - 'uploads.js', - 'knitter.js', - 'annotations.js', - 'maps.js'] - - # Defaults to nil and saved in location specified by config.assets.prefix - # config.assets.manifest = YOUR_PATH + 'uploads.js', + 'knitter.js', + 'annotations.js', + 'maps.js'] + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb - # 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 # 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) + # 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 + # Prepend all log lines with the following tags. # config.log_tags = [ :subdomain, :uuid ] - # Use a different logger for distributed setups + # 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" + # 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 ) - - # 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 config.action_mailer.delivery_method = :sendmail config.action_mailer.sendmail_settings = { @@ -67,18 +76,16 @@ arguments: '-i' } - # 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 + # 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 8b5dc4405..278bd7e91 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,5 +1,6 @@ Mapknitter::Application.configure do - # Settings specified here will take precedence over those in config/application.rb + + # 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,31 +8,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_assets = 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 static file server for tests with Cache-Control for performance. + config.serve_static_files = true + config.static_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 # 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 + # Randomize the order test cases are executed. + config.active_support.test_order = :random - # Print deprecation notices to the stderr + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 000000000..01ef3e663 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 000000000..ac5f8b663 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +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 index 000000000..4a994e1e7 --- /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 index 5d8d9be23..ac033bf9d 100644 --- 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 index 72aca7e44..dc1899682 100644 --- 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/session_store.rb b/config/initializers/session_store.rb index 24b534974..d496b7352 100644 --- 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. -Mapknitter::Application.config.session_store :cookie_store, key: '_mapknitter_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") -# Mapknitter::Application.config.session_store :active_record_store +Rails.application.config.session_store :cookie_store, key: '_mapknitter_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 999df2018..35d7efeaf 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,14 +1,14 @@ # Be sure to restart your server when you modify this file. -# + # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) end -# Disable root element in JSON by default. +# Disable root element in JSON for ActiveRecord objects. ActiveSupport.on_load(:active_record) do self.include_root_in_json = false end diff --git a/config/locales/en.yml b/config/locales/en.yml index 179c14ca5..065395716 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,23 @@ -# 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. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 000000000..b839a03ad --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: d4b805f25ee5bdba59cfd75d808721c6a73215f9e499e86af29dc2855c2e377bf05a463c8ee46e7ad896a435cd3f4e912794a9f9eb788b75a85c75624b34f01e + +test: + secret_key_base: 3aecc44ce8fabf9194016bb240fa78113f3c26b8d2c7b1b4dc0611300fbe6f95fdb89fef41f025f2494ec2281c40ca0dd0b86ac3eee3a46683abc42f63c449af + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> From c4a3cba4b091fe318296fdbe7b30c7ef45b72cbe Mon Sep 17 00:00:00 2001 From: Cess Date: Sun, 5 May 2019 12:24:03 +0300 Subject: [PATCH 004/152] disable rubocop on bin folder --- .codeclimate.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 4c1449c23..7922fef22 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,23 +1,23 @@ version: 2 -plugins: - rubocop: +plugins: + rubocop: enabled: true channel: rubocop-0-70 - brakeman: + brakeman: enabled: true - bundler-audit: + bundler-audit: enabled: true - duplication: + duplication: enabled: true config: languages: - ruby: - javascript: - eslint: + eslint: enabled: true - fixme: + fixme: enabled: true - rubocop: + rubocop: enabled: true exclude_patterns: @@ -25,5 +25,6 @@ exclude_patterns: - db/ - vendor/ - log/ +- bin/ From 58b80a188f69db462b519e168f6512c500bfd4e8 Mon Sep 17 00:00:00 2001 From: Cess Date: Sun, 5 May 2019 23:51:00 +0300 Subject: [PATCH 005/152] http patch --- config/routes.rb | 66 +++--------------------------------------------- 1 file changed, 4 insertions(+), 62 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 6dd6d53f8..2cd514153 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,57 +1,13 @@ Mapknitter::Application.routes.draw do - # The priority is based upon order of creation: - # first created -> highest priority. - - # Sample of regular route: - # match 'products/:id' => 'catalog#view' - # Keep in mind you can assign values other than :controller and :action - - # Sample of named route: - # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase - # This route can be invoked with purchase_url(:id => product.id) - - # Sample resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Sample resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Sample resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Sample resource route with more complex sub-resources - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', :on => :collection - # end - # end - - # Sample resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end + + root :to => 'maps#index' + get 'front-page' => 'front_ui#index' get 'mappers' => 'front_ui#nearby_mappers' post "save_location" => 'front_ui#save_location' get 'about' => 'front_ui#about' get 'all_maps' => 'front_ui#all_maps' - # these are a mess: get 'external_url_test' => 'export#external_url_test' get 'local/:login' => 'sessions#local' get 'logout' => 'sessions#logout' @@ -61,10 +17,8 @@ # since rails 3.2, we use this to log in: get 'sessions/create' => 'sessions#create' - # believe this is unnecessary: - #get 'session' => 'sessions#create', :conditions => { :method => :get } - resources :users, :sessions + resources :users, :sessions, :maps # redirect legacy route: get 'tag/:id', to: redirect('/tags/%{id}') @@ -87,20 +41,14 @@ get 'tms/:id/alt/' => 'utility#tms_info' # once we have string-based ids, reorganize these around 'maps' and resourceful routing - get 'maps' => 'maps#index' - post 'maps' => 'maps#create' # legacy, will be replaced by resourceful route get 'map/map' => 'maps#map' - put 'map/:id' => 'maps#update' # legacy, will be replaced by resourceful route get 'search/:id' => 'maps#search' get 'search' => 'maps#search' - get 'map/update/:id' => 'maps#update' # legacy get 'map/archive/:id' => 'maps#archive' get 'map/region/:id' => 'maps#region' get 'map/license/:id' => 'maps#license' get 'maps/featured' => 'maps#featured' get 'map/view/:id', to: redirect('/maps/%{id}') # legacy - get 'maps/new' => 'maps#new' # legacy, will be replaced by resourceful route - get 'maps/:id/edit' => 'maps#edit' # legacy, will be replaced by resourceful route get 'maps/:id/annotate' => 'maps#annotate' get 'maps/exports/:id' => 'maps#exports' get 'maps/:id/warpables' => 'maps#images' # deprecate this in favor of resourceful route below; this is just to override maps/:id @@ -108,7 +56,6 @@ get 'export/progress/:id' => 'export#progress' get 'export/status/:id' => 'export#status' get 'exports' => 'export#index' - get 'maps/:id' => 'maps#show' get 'map/:id', to: redirect('/maps/%{id}') get 'embed/:id' => 'maps#embed' post 'maps/export/:id' => 'maps#export' @@ -125,13 +72,8 @@ delete 'maps/:map_id/warpables/:id' => 'images#destroy' #legacy, will be resourceful delete 'images/:id' => 'images#destroy' #legacy, will be resourceful - # You can have the root of your site routed with 'root' - # just remember to delete public/index.html. - root :to => 'maps#index' - # RESTful API resources :maps do - resources :tags resources :tags, only: [:create, :show, :destroy] resources :comments resources :warpables From 76d6e33bfd2c95130693dab1b889b1bd1d5d8902 Mon Sep 17 00:00:00 2001 From: Cess Date: Mon, 6 May 2019 00:14:41 +0300 Subject: [PATCH 006/152] Comment out to allow testing --- config/initializers/visitor.rb | 26 +++++++++++++------------- test/performance/browsing_test.rb | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/config/initializers/visitor.rb b/config/initializers/visitor.rb index 443c9ce3b..df4d800c5 100644 --- a/config/initializers/visitor.rb +++ b/config/initializers/visitor.rb @@ -11,18 +11,18 @@ # Arel is now bundled in the Active Record gem, and maintained in the rails/rails repository. # This code can be deleted on update to `activerecord >= 6.0` (Rails 6) -module Arel - module Visitors - class DepthFirst < Arel::Visitors::Visitor - alias :visit_Integer :terminal - end +# module Arel +# module Visitors +# class DepthFirst < Arel::Visitors::Visitor +# alias :visit_Integer :terminal +# end - class Dot < Arel::Visitors::Visitor - alias :visit_Integer :visit_String - end +# class Dot < Arel::Visitors::Visitor +# alias :visit_Integer :visit_String +# end - class ToSql < Arel::Visitors::Visitor - alias :visit_Integer :literal - end - end -end \ No newline at end of file +# class ToSql < Arel::Visitors::Visitor +# alias :visit_Integer :literal +# end +# end +# end diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb index 3fea27b91..96ebe7f1e 100644 --- a/test/performance/browsing_test.rb +++ b/test/performance/browsing_test.rb @@ -1,12 +1,12 @@ -require 'test_helper' -require 'rails/performance_test_help' +# require 'test_helper' +# require 'rails/performance_test_help' -class BrowsingTest < ActionDispatch::PerformanceTest - # Refer to the documentation for all available options - # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory] - # :output => 'tmp/performance', :formats => [:flat] } +# class BrowsingTest < ActionDispatch::PerformanceTest +# # Refer to the documentation for all available options +# # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory] +# # :output => 'tmp/performance', :formats => [:flat] } - def test_homepage - get '/' - end -end +# def test_homepage +# get '/' +# end +# end From 3d7d8ba97d3dc07a5a7257b56cd4d56720714e96 Mon Sep 17 00:00:00 2001 From: Cess Date: Mon, 6 May 2019 00:16:18 +0300 Subject: [PATCH 007/152] no longer supports plugin loading --- vendor/plugins/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 vendor/plugins/.gitkeep diff --git a/vendor/plugins/.gitkeep b/vendor/plugins/.gitkeep deleted file mode 100644 index e69de29bb..000000000 From 8b2eaaf01b0f339a26df3b31200a6a1ed33e0f4f Mon Sep 17 00:00:00 2001 From: Cess Date: Mon, 6 May 2019 01:17:34 +0300 Subject: [PATCH 008/152] lock to sprockets 2.12 --- Gemfile | 2 +- Gemfile.lock | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index e3360daf2..2453ee174 100644 --- a/Gemfile +++ b/Gemfile @@ -33,7 +33,7 @@ group :dependencies do gem "rdiscount", "2.2.0.1" # asset pipelining - gem "sprockets"#, "2.12.1" + gem 'sprockets', '2.12.1' gem "sass", :require => 'sass' gem "autoprefixer-rails" gem "uglifier" diff --git a/Gemfile.lock b/Gemfile.lock index a4ac481c6..d3010eb1d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,7 @@ GEM geokit (>= 1.5.0) globalid (0.4.2) activesupport (>= 4.2.0) + hike (1.2.3) httparty (0.17.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) @@ -197,13 +198,15 @@ GEM skylight-core (= 4.0.2) skylight-core (4.0.2) activesupport (>= 4.2.0) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) + sprockets (2.12.1) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.3.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (>= 2.8, < 4.0) sqlite3 (1.4.1) test-unit (3.3.3) power_assert @@ -212,6 +215,7 @@ GEM ref thor (0.20.3) thread_safe (0.3.6) + tilt (1.4.1) tzinfo (1.2.5) thread_safe (~> 0.1) uglifier (4.1.20) @@ -256,7 +260,7 @@ DEPENDENCIES simplecov simplecov-cobertura skylight - sprockets + sprockets (= 2.12.1) sqlite3 test-unit therubyracer From ddb6d7c4b31099f09c7266a61ccc97680c931bde Mon Sep 17 00:00:00 2001 From: Cess Date: Mon, 6 May 2019 01:18:12 +0300 Subject: [PATCH 009/152] Active record patches --- Gemfile | 2 +- Gemfile.lock | 2 +- app/controllers/annotations_controller.rb | 28 +++++++++------ app/controllers/comments_controller.rb | 13 ++++--- app/controllers/export_controller.rb | 6 ++++ app/controllers/feeds_controller.rb | 17 ++++----- app/controllers/images_controller.rb | 10 ++++-- app/controllers/maps_controller.rb | 6 +++- app/controllers/tags_controller.rb | 6 ++++ app/controllers/users_controller.rb | 5 +++ app/models/annotation.rb | 2 -- app/models/comment.rb | 1 - app/models/export.rb | 13 +++---- app/models/map.rb | 42 +++++++++-------------- app/models/node.rb | 1 - app/models/tag.rb | 8 ++--- app/models/user.rb | 1 - app/models/warpable.rb | 4 +-- app/models/way.rb | 3 +- app/views/maps/_statistics.html.erb | 4 +-- config/initializers/assets.rb | 5 +++ 21 files changed, 103 insertions(+), 76 deletions(-) diff --git a/Gemfile b/Gemfile index 2453ee174..e3360daf2 100644 --- a/Gemfile +++ b/Gemfile @@ -33,7 +33,7 @@ group :dependencies do gem "rdiscount", "2.2.0.1" # asset pipelining - gem 'sprockets', '2.12.1' + gem "sprockets"#, "2.12.1" gem "sass", :require => 'sass' gem "autoprefixer-rails" gem "uglifier" diff --git a/Gemfile.lock b/Gemfile.lock index d3010eb1d..bfb4b9980 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -260,7 +260,7 @@ DEPENDENCIES simplecov simplecov-cobertura skylight - sprockets (= 2.12.1) + sprockets sqlite3 test-unit therubyracer diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb index 3435ce4c0..9905f52bc 100644 --- a/app/controllers/annotations_controller.rb +++ b/app/controllers/annotations_controller.rb @@ -9,7 +9,7 @@ def index end def create - geojson = params[:annotation] + geojson = annotation_params # params[:annotation] respond_to do |format| format.json do @@ -32,15 +32,16 @@ def show def update @annotation = Annotation.find params[:id] - geojson = params[:annotation] - return if @annotation.user_id.nil? || current_user.can_edit?(@annotation) - - Annotation.update(@annotation.id, - coordinates: geojson[:geometry][:coordinates], - text: geojson[:properties][:textContent], - style: geojson[:properties][:style]) - render file: 'annotations/update.json.erb', - content_type: 'application/json' + + geojson = annotation_params + if @annotation.user_id.nil? || current_user.can_edit?(@annotation) + Annotation.update(@annotation.id, + coordinates: geojson[:geometry][:coordinates], + text: geojson[:properties][:textContent], + style: geojson[:properties][:style]) + render file: 'annotations/update.json.erb', + content_type: 'application/json' + end end def destroy @@ -54,4 +55,11 @@ def destroy def find_map @map = Map.find params[:map_id] end + + private + + def annotation_params + params.require(:annotation).permit(:annotation_type, + :coordinates, :text, :style) + end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index c0e01fbf0..d73678f11 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -3,10 +3,7 @@ def create if logged_in? @map = Map.find params[:map_id] - @comment = @map.comments.new( - user_id: current_user.id, - body: params[:comment][:body] - ) + @comment = @map.comments.new(comment_params, user_id: current_user.id) if @comment.save! users = @map.comments.collect(&:user) users += [@map.user] unless @map.user.nil? @@ -31,7 +28,7 @@ def create def update @comment = Comment.find params[:id] if logged_in? && current_user.can_edit?(@comment) - @comment.update_attribute(:body, params[:comment][:body]) + @comment.update_attribute(comment_params) redirect_to '/maps/' + params[:map_id] else flash[:error] = 'You do not have permissions to update that comment.' @@ -50,4 +47,10 @@ def destroy end redirect_to "/maps/#{params[:map_id]}" end + + private + + def comment_params + params.require(:comment).permit(:body) + end end diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 2b3c98470..424fa4a71 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -85,4 +85,10 @@ def status def external_url_test render json: Export.last.to_json end + + private + + def export_params + params.require(:export).permit(:status, :export_url) + end end diff --git a/app/controllers/feeds_controller.rb b/app/controllers/feeds_controller.rb index 3405ea31d..2224f9e53 100644 --- a/app/controllers/feeds_controller.rb +++ b/app/controllers/feeds_controller.rb @@ -3,10 +3,11 @@ class FeedsController < ApplicationController def all # (Warpable.all + Map.all).sort_by(&:created_at) - @maps = Map.find(:all, order: 'id DESC', limit: 20, - conditions: { archived: false, password: '' }, - joins: %i(user warpables), - group: 'maps.id') + @maps = Map.where(archived: false, password: '') + .joins(%i[user warpables]) + .group('maps.id') + .order('id DESC') + .limit(20) render layout: false, template: 'feeds/all' response.headers['Content-Type'] = 'application/xml; charset=utf-8' end @@ -23,10 +24,10 @@ def license end def author - @maps = Map.find_all_by_author(params[:id], - order: 'id DESC', - conditions: { archived: false, password: '' }, - joins: :warpables, group: 'maps.id') + @maps = Map.where(author: params[:id], archived: false, password: '') + .order('id DESC') + .joins(:warpables) + .group('maps.id') images = [] @maps.each do |map| images += map.warpables diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index 2f670da0f..fe79c6a14 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -23,8 +23,8 @@ def fetch # assign attributes directly after rails update def create - @warpable = Warpable.new - @warpable.image = params[:uploaded_data] + @warpable = Warpable.new(image_params) + # @warpable.image = params[:uploaded_data] map = Map.find(params[:map_id]) @warpable.history = '' @warpable.map_id = map.id @@ -109,4 +109,10 @@ def destroy redirect_to '/login' end end + + private + + def image_params + params.require(:warpable).permit(:image) + end end diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 51258908e..69337853b 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -32,7 +32,7 @@ def new def create if logged_in? - @map = current_user.maps.new(params[:map]) + @map = current_user.maps.new(map_params) @map.author = current_user.login # eventually deprecate if @map.save redirect_to "/maps/#{@map.slug}" @@ -200,4 +200,8 @@ def search def find_map @map = Map.find(params[:id]) end + + def map_params + params.require(:map).permit(:author, :name, :slug, :lat, :lon, :location, :description, :zoom, :license) + end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index f6ad5ab3d..eba31b0f3 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -32,4 +32,10 @@ def destroy redirect_to '/login' end end + + private + + def tag_params + params.require(:tag).permit(:name) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 56d9379e6..5dc4f187f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -27,4 +27,9 @@ def sort_column def sort_direction params[:direction] || 'desc' end + + def user_params + params.require(:user).permit(:login, :email, :name, + :password, :password_confirmation) + end end diff --git a/app/models/annotation.rb b/app/models/annotation.rb index bfa3ce87c..05575fdff 100644 --- a/app/models/annotation.rb +++ b/app/models/annotation.rb @@ -2,8 +2,6 @@ class Annotation < ActiveRecord::Base belongs_to :map belongs_to :user - attr_accessible :annotation_type, :coordinates, :text, :style - serialize :coordinates, Array serialize :style, Hash diff --git a/app/models/comment.rb b/app/models/comment.rb index 8ac15586e..0021e4761 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,4 @@ class Comment < ActiveRecord::Base - attr_accessible :user_id, :body belongs_to :map belongs_to :user diff --git a/app/models/export.rb b/app/models/export.rb index d37b52021..d85d62aa4 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -1,6 +1,4 @@ class Export < ActiveRecord::Base - attr_accessible :map_id, :status, :user_id, :export_url - belongs_to :map belongs_to :user @@ -10,7 +8,7 @@ def running? end def self.average_cm_per_pixel - e = Export.find :all, conditions: ['cm_per_pixel != "" AND cm_per_pixel < 500'] + e = Export.where('cm_per_pixel != "" AND cm_per_pixel < 500') sum = 0 e.each do |export| sum += export.cm_per_pixel @@ -23,7 +21,8 @@ def self.average_cm_per_pixel end def self.histogram_cm_per_pixel - e = Export.find :all, conditions: ['cm_per_pixel != "" AND cm_per_pixel < 500'], order: "cm_per_pixel DESC" + e = Export.where('cm_per_pixel != "" AND cm_per_pixel < 500') + .order('cm_per_pixel DESC') if !e.empty? hist = [] (0..e.first.cm_per_pixel.to_i).each do |bin| @@ -52,11 +51,13 @@ def self.histogram_cm_per_pixel_in_tens end def self.export_count - Export.count :all, conditions: ['status != "failed" AND status != "complete" AND status != "none" AND updated_at > ?', (DateTime.now - 24.hours).to_s(:db)] + Export.where('status != "failed" AND status != "complete" AND status != "none" AND updated_at > ?', + (DateTime.now-24.hours).to_s(:db)).count end # all exports currently running def self.exporting - Export.find :all, conditions: ['status != "failed" AND status != "complete" AND status != "none" AND updated_at > ?', (DateTime.now - 24.hours).to_s(:db)] + Export.where('status != "failed" AND status != "complete" AND status != "none" AND updated_at > ?', + (DateTime.now-24.hours).to_s(:db)) end end diff --git a/app/models/map.rb b/app/models/map.rb index 0ff3c51d4..9091c9722 100755 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -3,33 +3,23 @@ class Map < ActiveRecord::Base extend FriendlyId friendly_id :name, use: %i(slugged static) - attr_accessible :author, :name, :slug, :lat, :lon, - :location, :description, :zoom, :license attr_accessor :image_urls - validates :name, :slug, :author, :lat, :lon, presence: true - - validates :slug, format: { - with: /^[\w-]*$/, - message: "must only include permitted URL safe character types: - alphanumerics, dashes, and underscores. It will be in your map's - URL path (i.e., https://mapknitter.org/maps/your-map-name)." - }, uniqueness: true, on: :create - - validates :location, presence: { - message: ' cannot be found. - Try entering a latitude and longitude if this problem persists.' - } - # validates :tile_url, format { with: - # /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\. - # [a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix - # } - validates :lat, :lon, NotAtOrigin: true - - has_many :exports, dependent: :destroy - has_many :tags, dependent: :destroy - has_many :comments, dependent: :destroy - has_many :annotations, dependent: :destroy + validates_presence_of :name, :slug, :author, :lat, :lon + validates_uniqueness_of :slug + validates_presence_of :location, :message => ' cannot be found. Try entering a latitude and longitude if this problem persists.' + # validates_format_of :slug, + # :with => /^[\w-]*$/, + # :message => " must not include spaces and must be alphanumeric, as it'll be used in the URL of your map, like: https://mapknitter.org/maps/your-map-name. You may use dashes and underscores.", + # :on => :create +# validates_format_of :tile_url, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix + validates_with NotAtOriginValidator + validates :lat, :lon, NotAtOrigin: true + + has_many :exports, :dependent => :destroy + has_many :tags, :dependent => :destroy + has_many :comments, :dependent => :destroy + has_many :annotations, :dependent => :destroy belongs_to :user has_many :warpables @@ -272,7 +262,7 @@ def license_link end def has_tag(tagname) - !Tag.find(:all, conditions: { map_id: id, name: tagname }).empty? + !Tag.where(map_id: self.id, name: tagname).empty? end def add_tag(tagname, user) diff --git a/app/models/node.rb b/app/models/node.rb index 92aa1ee70..a6e3018b7 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -1,4 +1,3 @@ class Node < ActiveRecord::Base - attr_accessible :body, :lat, :lon, :map_id, :way_order, :way_id, :color, :author, :name belongs_to :way end diff --git a/app/models/tag.rb b/app/models/tag.rb index 3a699d727..be5a179e5 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -2,11 +2,9 @@ class Tag < ActiveRecord::Base belongs_to :map belongs_to :user - attr_accessible :name, :map_id, :user_id - - validates_presence_of :name, on: :create, message: "can't be blank" - validates_presence_of :user_id, on: :create, message: "can't be blank" - validates_presence_of :map_id, on: :create, message: "can't be blank" + validates_presence_of :name, :on => :create, :message => "can't be blank" + validates_presence_of :user_id, :on => :create, :message => "can't be blank" + validates_presence_of :map_id, :on => :create, :message => "can't be blank" def maps Map.where(id: Tag.where(name: name).collect(&:map_id).uniq) diff --git a/app/models/user.rb b/app/models/user.rb index 0eaa31479..55e036669 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,7 +18,6 @@ class User < ActiveRecord::Base # HACK: HACK HACK -- how to do attr_accessible from here? # prevents a user from submitting a crafted form that bypasses activation # anything else you want your user to change should be added here. - attr_accessible :login, :email, :name, :password, :password_confirmation # Authenticates a user by their login name and unencrypted password. Returns the user or nil. # diff --git a/app/models/warpable.rb b/app/models/warpable.rb index a35fce0d1..bac4a300f 100755 --- a/app/models/warpable.rb +++ b/app/models/warpable.rb @@ -1,5 +1,4 @@ class Warpable < ActiveRecord::Base - attr_accessible :image attr_accessor :src, :srcmedium # for json generation # Paperclip; config and production/development specific configs @@ -109,7 +108,8 @@ def get_cm_per_pixel end def self.histogram_cm_per_pixel - w = Warpable.find :all, conditions: ['cm_per_pixel != 0 AND cm_per_pixel < 500'], order: "cm_per_pixel DESC" + w = Warpable.where('cm_per_pixel != 0 AND cm_per_pixel < 500') + .order('cm_per_pixel DESC') if !w.empty? hist = [] (0..w.first.cm_per_pixel.to_i).each do |bin| diff --git a/app/models/way.rb b/app/models/way.rb index f92f1f1df..8237be702 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -1,6 +1,5 @@ class Way < ActiveRecord::Base - attr_accessible :body, :lat, :lon, :map_id, :color - has_many :nodes, dependent: :destroy + has_many :nodes, :dependent => :destroy def bbox=(bbox) # counting from left, counter-clockwise diff --git a/app/views/maps/_statistics.html.erb b/app/views/maps/_statistics.html.erb index 5935c074d..7f53e5463 100644 --- a/app/views/maps/_statistics.html.erb +++ b/app/views/maps/_statistics.html.erb @@ -1,9 +1,9 @@
- <% if (Export.count(:all, :conditions => ["cm_per_pixel != ''"]) > 0) %> +<% if (Export.where("cm_per_pixel != ''").count > 0) %>

What people have been doing with MapKnitter


- MapKnitter is hosting <%= Export.count(:all, :conditions => ["cm_per_pixel != ''"]) %> completed maps of an average resolution of <%= Export.average_cm_per_pixel.to_i %> cm per pixel. Images average. Currently exporting <%= Export.export_count %> maps.

+ MapKnitter is hosting <%= Export.where("cm_per_pixel != ''").count %> completed maps of an average resolution of <%= Export.average_cm_per_pixel.to_i %> cm per pixel. Images average. Currently exporting <%= Export.export_count %> maps.

Resolutions:

Resolutions:

Maps: diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 01ef3e663..f5d0ac0f0 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -9,3 +9,8 @@ # 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 ) +Rails.application.config.assets.precompile += ['tags.js', + 'uploads.js', + 'knitter.js', + 'annotations.js', + 'maps.js'] From a79930a51d3cde63a895a22f3157d73958ea3467 Mon Sep 17 00:00:00 2001 From: Cess Date: Tue, 7 May 2019 02:17:59 +0300 Subject: [PATCH 010/152] remove deprecated test syntax --- test/functional/maps_controller_test.rb | 4 ++-- test/functional/sessions_controller_test.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/functional/maps_controller_test.rb b/test/functional/maps_controller_test.rb index 47acfc77b..866f4c288 100644 --- a/test/functional/maps_controller_test.rb +++ b/test/functional/maps_controller_test.rb @@ -190,7 +190,7 @@ def teardown @map.reload assert_redirected_to '/?_=' + Time.now.to_i.to_s - assert_true @map.archived + assert @map.archived end test 'should not archive map without enough permissions' do @@ -199,7 +199,7 @@ def teardown @map.reload assert_redirected_to '/?_=' + Time.now.to_i.to_s - assert_false @map.archived + assert_not @map.archived end test 'should update map' do diff --git a/test/functional/sessions_controller_test.rb b/test/functional/sessions_controller_test.rb index 4087cf6b9..98da1b9dd 100644 --- a/test/functional/sessions_controller_test.rb +++ b/test/functional/sessions_controller_test.rb @@ -19,7 +19,7 @@ class SessionsControllerTest < ActionController::TestCase test 'logs out a user' do session[:user_id] = 1 get :logout - assert_equal nil, session[:user_id] + assert_nil session[:user_id] assert flash[:success].present? assert_equal 'You have successfully logged out.', flash[:success] assert_redirected_to "/?_=#{Time.now.to_i}" From a1d0aaf10e1ba31577c648478487ccc6557aa496 Mon Sep 17 00:00:00 2001 From: Cess Date: Tue, 7 May 2019 12:16:16 +0300 Subject: [PATCH 011/152] fix failing tests --- app/controllers/comments_controller.rb | 14 +++++++------- app/controllers/images_controller.rb | 10 ++-------- app/controllers/maps_controller.rb | 2 +- app/views/images/_new.html.erb | 3 ++- test/functional/comments_controller_test.rb | 1 + test/functional/maps_controller_test.rb | 4 ++-- 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index d73678f11..347644693 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,15 +1,15 @@ class CommentsController < ApplicationController def create if logged_in? - @map = Map.find params[:map_id] - @comment = @map.comments.new(comment_params, user_id: current_user.id) + @comment = current_user.comments.new(comment_params) + @map = Map.find comment_params[:map_id] if @comment.save! users = @map.comments.collect(&:user) users += [@map.user] unless @map.user.nil? users.uniq.each do |user| - unless user.id == current_user.id - CommentMailer.notify(user, @comment).deliver + unless @map.user_id == current_user.id + CommentMailer.notify(user, @comment).deliver_now end end end @@ -28,8 +28,8 @@ def create def update @comment = Comment.find params[:id] if logged_in? && current_user.can_edit?(@comment) - @comment.update_attribute(comment_params) - redirect_to '/maps/' + params[:map_id] + @comment.update_attributes(comment_params) + redirect_to "/maps/#{@comment.map.slug}" else flash[:error] = 'You do not have permissions to update that comment.' redirect_to '/login' @@ -51,6 +51,6 @@ def destroy private def comment_params - params.require(:comment).permit(:body) + params.require(:comment).permit(:body, :map_id) end end diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index fe79c6a14..2f670da0f 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -23,8 +23,8 @@ def fetch # assign attributes directly after rails update def create - @warpable = Warpable.new(image_params) - # @warpable.image = params[:uploaded_data] + @warpable = Warpable.new + @warpable.image = params[:uploaded_data] map = Map.find(params[:map_id]) @warpable.history = '' @warpable.map_id = map.id @@ -109,10 +109,4 @@ def destroy redirect_to '/login' end end - - private - - def image_params - params.require(:warpable).permit(:image) - end end diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 69337853b..7e5cc7454 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -40,7 +40,7 @@ def create render 'new' end else - @map = Map.new(params[:map]) + @map = Map.new(map_params) if Rails.env != 'production' || verify_recaptcha(model: @map, message: "ReCAPTCHA thinks you're not human! Try again!") if @map.save redirect_to "/maps/#{@map.slug}" diff --git a/app/views/images/_new.html.erb b/app/views/images/_new.html.erb index 608db8b6f..27862c3cf 100644 --- a/app/views/images/_new.html.erb +++ b/app/views/images/_new.html.erb @@ -10,7 +10,8 @@