diff --git a/Gemfile b/Gemfile index df6623bbf..3a186e27f 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ gem 'pg' gem 'pg_advisory_lock', git: 'https://github.com/didww/pg_advisory_lock.git' gem 'pg_sql_caller', git: 'https://github.com/didww/pg_sql_caller.git' gem 'rack', ' ~> 2.2.6' -gem 'rails', '~> 7.1.0' +gem 'rails', '~> 7.2.0' gem 'responders' # Authentication @@ -52,7 +52,7 @@ gem 'jsonapi-resources', '~> 0.9.12' # Ext gem 'validates_timeliness', '~> 7.0.0.beta1' -# Object oriented authorization for Rails applications +# Object-oriented authorization for Rails applications gem 'pundit' gem 'paper_trail' diff --git a/Gemfile.lock b/Gemfile.lock index 78fa259a5..d8ce6da8c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,51 +96,46 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (7.1.5.1) - actionpack (= 7.1.5.1) - activesupport (= 7.1.5.1) + actioncable (7.2.2.1) + actionpack (= 7.2.2.1) + activesupport (= 7.2.2.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.5.1) - actionpack (= 7.1.5.1) - activejob (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.5.1) - actionpack (= 7.1.5.1) - actionview (= 7.1.5.1) - activejob (= 7.1.5.1) - activesupport (= 7.1.5.1) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (7.2.2.1) + actionpack (= 7.2.2.1) + activejob (= 7.2.2.1) + activerecord (= 7.2.2.1) + activestorage (= 7.2.2.1) + activesupport (= 7.2.2.1) + mail (>= 2.8.0) + actionmailer (7.2.2.1) + actionpack (= 7.2.2.1) + actionview (= 7.2.2.1) + activejob (= 7.2.2.1) + activesupport (= 7.2.2.1) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.5.1) - actionview (= 7.1.5.1) - activesupport (= 7.1.5.1) + actionpack (7.2.2.1) + actionview (= 7.2.2.1) + activesupport (= 7.2.2.1) nokogiri (>= 1.8.5) racc - rack (>= 2.2.4) + rack (>= 2.2.4, < 3.2) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.5.1) - actionpack (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) + useragent (~> 0.16) + actiontext (7.2.2.1) + actionpack (= 7.2.2.1) + activerecord (= 7.2.2.1) + activestorage (= 7.2.2.1) + activesupport (= 7.2.2.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.5.1) - activesupport (= 7.1.5.1) + actionview (7.2.2.1) + activesupport (= 7.2.2.1) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) @@ -156,8 +151,8 @@ GEM active_admin_sidebar (1.1.0) activeadmin active_admin_theme (1.1.2) - active_record_extended (3.2.1) - activerecord (>= 5.2, < 7.2.0) + active_record_extended (3.3.0) + activerecord (>= 5.2, < 8.0.0) pg (< 3.0) activeadmin (3.2.2) arbre (~> 1.2, >= 1.2.1) @@ -169,8 +164,8 @@ GEM kaminari (>= 1.2.1) railties (>= 6.1) ransack (>= 4.0) - activejob (7.1.5.1) - activesupport (= 7.1.5.1) + activejob (7.2.2.1) + activesupport (= 7.2.2.1) globalid (>= 0.3.6) activeldap (5.1.1) activemodel (> 4.0.0) @@ -178,37 +173,36 @@ GEM gettext gettext_i18n_rails locale - activemodel (7.1.5.1) - activesupport (= 7.1.5.1) + activemodel (7.2.2.1) + activesupport (= 7.2.2.1) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (7.1.5.1) - activemodel (= 7.1.5.1) - activesupport (= 7.1.5.1) + activerecord (7.2.2.1) + activemodel (= 7.2.2.1) + activesupport (= 7.2.2.1) timeout (>= 0.4.0) activerecord-import (2.0.0) activerecord (>= 4.2) - activestorage (7.1.5.1) - actionpack (= 7.1.5.1) - activejob (= 7.1.5.1) - activerecord (= 7.1.5.1) - activesupport (= 7.1.5.1) + activestorage (7.2.2.1) + actionpack (= 7.2.2.1) + activejob (= 7.2.2.1) + activerecord (= 7.2.2.1) + activesupport (= 7.2.2.1) marcel (~> 1.0) - activesupport (7.1.5.1) + activesupport (7.2.2.1) base64 benchmark (>= 0.3) bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) logger (>= 1.4.2) minitest (>= 5.1) - mutex_m securerandom (>= 0.3) - tzinfo (~> 2.0) + tzinfo (~> 2.0, >= 2.0.5) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) annotate (3.2.0) @@ -288,10 +282,10 @@ GEM activerecord (>= 3.2) date (3.3.3) deep_merge (1.2.1) - delayed_job (4.1.11) - activesupport (>= 3.0, < 8.0) - delayed_job_active_record (4.1.7) - activerecord (>= 3.0, < 8.0) + delayed_job (4.1.13) + activesupport (>= 3.0, < 9.0) + delayed_job_active_record (4.1.11) + activerecord (>= 3.0, < 9.0) delayed_job (>= 3.0, < 5) devise (4.9.4) bcrypt (~> 3.0) @@ -451,7 +445,6 @@ GEM msgpack (1.7.2) multi_xml (0.6.0) mustache (1.1.1) - mutex_m (0.3.0) net-imap (0.3.6) date net-protocol @@ -697,20 +690,20 @@ GEM rackup (1.0.1) rack (< 3) webrick - rails (7.1.5.1) - actioncable (= 7.1.5.1) - actionmailbox (= 7.1.5.1) - actionmailer (= 7.1.5.1) - actionpack (= 7.1.5.1) - actiontext (= 7.1.5.1) - actionview (= 7.1.5.1) - activejob (= 7.1.5.1) - activemodel (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) + rails (7.2.2.1) + actioncable (= 7.2.2.1) + actionmailbox (= 7.2.2.1) + actionmailer (= 7.2.2.1) + actionpack (= 7.2.2.1) + actiontext (= 7.2.2.1) + actionview (= 7.2.2.1) + activejob (= 7.2.2.1) + activemodel (= 7.2.2.1) + activerecord (= 7.2.2.1) + activestorage (= 7.2.2.1) + activesupport (= 7.2.2.1) bundler (>= 1.15.0) - railties (= 7.1.5.1) + railties (= 7.2.2.1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -718,17 +711,17 @@ GEM rails-html-sanitizer (1.6.1) loofah (~> 2.21) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) - railties (7.1.5.1) - actionpack (= 7.1.5.1) - activesupport (= 7.1.5.1) - irb + railties (7.2.2.1) + actionpack (= 7.2.2.1) + activesupport (= 7.2.2.1) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.0.6) - ransack (4.1.1) + ransack (4.2.1) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n @@ -858,6 +851,7 @@ GEM unicode (0.4.4.5) unicode-display_width (2.4.2) uniform_notifier (1.16.0) + useragent (0.16.11) validates_timeliness (7.0.0.beta2) activemodel (>= 7.0.0, < 8) timeliness (>= 0.3.10, < 1) @@ -956,7 +950,7 @@ DEPENDENCIES puma_worker_killer pundit rack (~> 2.2.6) - rails (~> 7.1.0) + rails (~> 7.2.0) rails-html-sanitizer (>= 1.6.1) ransack responders @@ -988,4 +982,4 @@ DEPENDENCIES zip-zip BUNDLED WITH - 2.6.2 + 2.6.3 diff --git a/app/models/concerns/routing_tag_ids_scopeable.rb b/app/models/concerns/routing_tag_ids_scopeable.rb index 521128b49..f1ff6a82e 100644 --- a/app/models/concerns/routing_tag_ids_scopeable.rb +++ b/app/models/concerns/routing_tag_ids_scopeable.rb @@ -6,14 +6,14 @@ module RoutingTagIdsScopeable included do scope :routing_tag_ids_covers, lambda { |*routing_tag_ids| type = ActiveModel::Type::Integer.new(limit: 2) - routing_tag_ids = routing_tag_ids.map do |id| + serialized_tag_ids = routing_tag_ids.map do |id| type.serialize(id) rescue ActiveModel::RangeError nil end - return none if routing_tag_ids.any?(&:nil?) + return none if serialized_tag_ids.any?(&:nil?) - where('yeti_ext.tag_compare(routing_tag_ids, ARRAY[?], routing_tag_mode_id)>0', routing_tag_ids) + where('yeti_ext.tag_compare(routing_tag_ids, ARRAY[?]::smallint[], routing_tag_mode_id)>0', serialized_tag_ids) } scope :tagged, lambda { |value| diff --git a/app/models/report/realtime/bad_routing.rb b/app/models/report/realtime/bad_routing.rb index 35f855fef..fafcfc648 100644 --- a/app/models/report/realtime/bad_routing.rb +++ b/app/models/report/realtime/bad_routing.rb @@ -190,7 +190,11 @@ class Report::Realtime::BadRouting < Report::Realtime::Base } scope :time_interval_eq, lambda { |value| - where('time_start >=(now()-\'? seconds\'::interval) and time_start < (now()-\'? seconds\'::interval)', 2 * value.to_i, value.to_i) + where( + "time_start >= (now()-(?::varchar||' seconds')::interval) AND time_start < (now()-(?::varchar||' seconds')::interval)", + 2 * value.to_i, + value.to_i + ) } private diff --git a/app/models/report/realtime/not_authenticated.rb b/app/models/report/realtime/not_authenticated.rb index 625bd7b7a..8ab67eeb0 100644 --- a/app/models/report/realtime/not_authenticated.rb +++ b/app/models/report/realtime/not_authenticated.rb @@ -182,9 +182,9 @@ class Report::Realtime::NotAuthenticated < Report::Realtime::Base scope :time_interval_eq, lambda { |value| where( - "time_start >=(now()-(?||'seconds')::interval) and time_start < (now()-(?||'seconds')::interval)", - (2 * value.to_i).to_s, - value.to_i.to_s + "time_start >=(now()-(?::varchar||' seconds')::interval) and time_start < (now()-(?||'seconds')::interval)", + 2 * value.to_i, + value.to_i ) } diff --git a/app/models/report/realtime/origination_performance.rb b/app/models/report/realtime/origination_performance.rb index 896656063..17442a847 100644 --- a/app/models/report/realtime/origination_performance.rb +++ b/app/models/report/realtime/origination_performance.rb @@ -185,7 +185,11 @@ class Report::Realtime::OriginationPerformance < Report::Realtime::Base } scope :time_interval_eq, lambda { |value| - where('time_start >=(now()-\'? seconds\'::interval) and time_start < (now()-\'? seconds\'::interval)', 2 * value.to_i, value.to_i) + where( + "time_start >= (now()-(?::varchar||' seconds')::interval) AND time_start < (now()-(?::varchar||' seconds')::interval)", + 2 * value.to_i, + value.to_i + ) } private diff --git a/app/models/stats/termination_quality_stat.rb b/app/models/stats/termination_quality_stat.rb index c77300976..a1c736341 100644 --- a/app/models/stats/termination_quality_stat.rb +++ b/app/models/stats/termination_quality_stat.rb @@ -37,7 +37,8 @@ def self.total min(pdd) as min_pdd, #{GuiConfig.termination_stats_window}::integer as w ").where( - "time_start>= now()-'? hours'::interval", GuiConfig.termination_stats_window + "time_start>= now()-(?::varchar||' hours')::interval", + GuiConfig.termination_stats_window ).reorder('').take end @@ -51,7 +52,8 @@ def self.dp_measurement max(pdd) as max_pdd, min(pdd) as min_pdd, dialpeer_id").where( - "time_start>= now()-'? hours'::interval and dialpeer_id is not null", GuiConfig.termination_stats_window + "time_start>= now()-(?::varchar||' hours')::interval and dialpeer_id is not null", + GuiConfig.termination_stats_window ).group('dialpeer_id').having( 'count(id)>=? AND sum(duration)>=?', min_calls_count, min_calls_duration ).reorder('') @@ -67,7 +69,8 @@ def self.gw_measurement max(pdd) as max_pdd, min(pdd) as min_pdd, gateway_id").where( - "time_start>= now()-'? hours'::interval and gateway_id is not null", GuiConfig.termination_stats_window + "time_start>= now()-(?::varchar||' hours')::interval and gateway_id is not null", + GuiConfig.termination_stats_window ).group('gateway_id').having( 'count(id)>=? AND sum(duration)>=?', min_calls_count, min_calls_duration ).reorder('') @@ -83,7 +86,8 @@ def self.dst_measurement max(pdd) as max_pdd, min(pdd) as min_pdd, destination_id").where( - "time_start>= now()-'? hours'::interval and destination_id is not null", GuiConfig.termination_stats_window + "time_start>= now()-(?::varchar||' hours')::interval and destination_id is not null", + GuiConfig.termination_stats_window ).group('destination_id').having( 'count(id)>=? AND sum(duration)>=?', min_calls_count, min_calls_duration ).reorder('') @@ -91,7 +95,8 @@ def self.dst_measurement def self.pdd_distribution select('pdd::integer, count(id)').where( - "time_start>= now()-'? hours'::interval", GuiConfig.termination_stats_window + "time_start>= now()-(?::varchar||' hours')::interval", + GuiConfig.termination_stats_window ).where(success: true).group('pdd::integer').order('pdd::integer ASC') end diff --git a/config/application.rb b/config/application.rb index abbd9ce6a..e7b67186b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,10 +26,10 @@ module Yeti class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 7.1 + config.load_defaults 7.2 # changing defaults - Rails.application.config.action_view.default_enforce_utf8 = true + config.action_view.default_enforce_utf8 = true # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers @@ -86,11 +86,13 @@ class Application < Rails::Application } config.active_job.queue_adapter = :delayed_job + config.active_job.enqueue_after_transaction_commit = :never # Use RSpec for testing config.generators do |g| g.test_framework :rspec g.integration_tool :rspec + g.system_tests nil end # reimplementing minimal Rails.application.secrets, that was removed in Rails 7.2 diff --git a/config/environments/development.rb b/config/environments/development.rb index 594b6165d..7868c04d1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -16,7 +16,7 @@ # Show full error reports. config.consider_all_requests_local = true - # Enable server timing + # Enable server timing. config.server_timing = true # Enable/disable caching. By default caching is disabled. @@ -26,9 +26,7 @@ config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" - } + config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -38,8 +36,12 @@ # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -70,9 +72,9 @@ # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. - # config.action_view.annotate_rendered_view_with_filenames = true + config.action_view.annotate_rendered_view_with_filenames = true - # Raise error when a before_action's only/except options reference missing actions + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true if ENV['RAILS_LOG_TO_STDOUT'].present? diff --git a/config/environments/production.rb b/config/environments/production.rb index 181f832c9..2c9c32fdf 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -73,6 +73,8 @@ # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "yeti_production" + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. @@ -91,6 +93,9 @@ config.use_schema_cache_dump = true + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [:id] + # Enable DNS rebinding protection and other `Host` header attacks. # config.hosts = [ # "example.com", # Allow requests from example.com diff --git a/config/environments/test.rb b/config/environments/test.rb index c966e2cc3..d14faf7dd 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -20,10 +20,7 @@ config.eager_load = ENV['CI'].present? # Configure public file server for tests with Cache-Control for performance. - config.public_file_server.enabled = true - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" - } + config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -38,6 +35,8 @@ # config.action_controller.allow_forgery_protection = false config.action_controller.allow_forgery_protection = true + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. @@ -45,6 +44,10 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Unlike controllers, the mailer instance doesn't have any context about the + # incoming request so you'll need to provide the :host parameter yourself. + config.action_mailer.default_url_options = { host: 'www.example.com' } + # Print deprecation notices to the stderr. # config.active_support.deprecation = :stderr config.active_support.deprecation = :raise @@ -61,12 +64,14 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true - # Raise error when a before_action's only/except options reference missing actions + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true + config.active_job.queue_adapter = :test + config.after_initialize do Bullet.enable = true # Detect unnecessary COUNT queries which could be avoided diff --git a/dev/db_test_prepare.sh b/dev/db_test_prepare.sh new file mode 100755 index 000000000..acc59657b --- /dev/null +++ b/dev/db_test_prepare.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "prepare test databases..." + +RAILS_ENV=test bundle exec rake db:drop \ + db:create \ + db:schema:load \ + db:seed \ + custom_seeds[network_prefixes] diff --git a/dev/migrate_test_db.sh b/dev/migrate_test_db.sh new file mode 100755 index 000000000..87b367cad --- /dev/null +++ b/dev/migrate_test_db.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "prepare and migrate test database..." + +RAILS_ENV=test bundle exec rake db:drop \ + db:create \ + db:schema:load \ + db:migrate \ + db:seed && \ +RAILS_ENV=test bundle exec rake custom_seeds[network_prefixes] && \ +RAILS_ENV=test bundle exec rake annotate_models diff --git a/public/404.html b/public/404.html index 9a48320a5..2be3af26f 100644 --- a/public/404.html +++ b/public/404.html @@ -2,25 +2,66 @@
You may have mistyped the address or the page may have moved.
+You may have mistyped the address or the page may have moved.
+If you are the application owner check the logs for more information.
Please upgrade your browser to continue.
+Maybe you tried to change something you didn't have access to.
+Maybe you tried to change something you didn't have access to.
+If you are the application owner check the logs for more information.
If you are the application owner check the logs for more information.