Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prep rails upgrades #8528

Merged
merged 14 commits into from
Jan 13, 2025
2 changes: 1 addition & 1 deletion app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class UserController < ApplicationController
# tries to sign in or sign up. There's little CSRF potential here as
# these actions only sign in or up users with valid credentials. The
# user_id in the session is not expected, and gives no extra privilege
skip_before_action :verify_authenticity_token, only: [:signin, :signup]
skip_before_action :verify_authenticity_token, only: [:signup]

# Show page about a user
def show
Expand Down
15 changes: 7 additions & 8 deletions app/models/info_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,13 @@ def self.download_zip_dir
end

def self.reject_incoming_at_mta(options)
query = InfoRequest.where(["updated_at < (now() -
interval ?)
AND allow_new_responses_from = 'nobody'
AND rejected_incoming_count >= ?
AND reject_incoming_at_mta = ?
AND url_title <> 'holding_pen'",
"#{options[:age_in_months]} months",
options[:rejection_threshold], false])
query = InfoRequest.where(
updated_at: ...options[:age_in_months].months.ago,
rejected_incoming_count: options[:rejection_threshold]..,
allow_new_responses_from: 'nobody',
reject_incoming_at_mta: false
).where.not(url_title: 'holding_pen')

yield query.pluck(:id) if block_given?

if options[:dryrun]
Expand Down
2 changes: 1 addition & 1 deletion app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

INSTANTLY = :instantly
DAILY = :daily
enum frequency: [ INSTANTLY, DAILY ]
enum :frequency, [ INSTANTLY, DAILY ]

Check warning on line 25 in app/models/notification.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Do not use space inside array brackets. Raw Output: app/models/notification.rb:25:21: C: Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.

Check warning on line 25 in app/models/notification.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Do not use space inside array brackets. Raw Output: app/models/notification.rb:25:38: C: Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.

validates_presence_of :info_request_event, :user, :frequency, :send_after

Expand Down
3 changes: 2 additions & 1 deletion app/models/post_redirect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def local_part_uri
def email_token_valid?
return true unless PostRedirect.verifier.valid_message?(email_token)

data = PostRedirect.verifier.verify(email_token, purpose: circumstance)
data = PostRedirect.verifier.verify(email_token, purpose: circumstance).
symbolize_keys
user.id == data[:user_id] && user.login_token == data[:login_token]
end

Expand Down
12 changes: 9 additions & 3 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@
# to make Rails upgrades easier.
# ----------------------------------------------------------------

config.action_mailer.preview_path = Rails.root.join(
'spec', 'mailers', 'previews'
)
if Rails.version < '7.1.0'
config.action_mailer.preview_path = Rails.root.join(
'spec', 'mailers', 'previews'
)
else
config.action_mailer.preview_paths = [
Rails.root.join('spec', 'mailers', 'previews')
]
end

# Set LOG_LEVEL in the environment to a valid log level to temporarily run the
# application with a non-default setting.
Expand Down
5 changes: 5 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test

config.action_mailer.perform_caching = false

# Tell Action Mailer not to deliver emails to the real world.
Expand Down Expand Up @@ -83,4 +86,6 @@
exception_recipients: AlaveteliConfiguration.exception_notifications_to
}
end

config.active_job.queue_adapter = :test
end
1 change: 0 additions & 1 deletion config/initializers/alaveteli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
require 'attachment_to_html'
require 'health_checks'
require 'mail_handler'
require 'ability'
require 'normalize_string'
require 'alaveteli_file_types'
require 'theme'
Expand Down
30 changes: 30 additions & 0 deletions config/initializers/zeitwerk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Rails.autoloaders.main.inflector.inflect(
"alaveteli_geoip" => "AlaveteliGeoIP",
"alaveteli_gettext" => "AlaveteliGetText",
"html_to_pdf_converter" => "HTMLtoPDFConverter",
"ip_rate_limiter" => "IPRateLimiter",
"pstore_database" => "PStoreDatabase",
"public_body_csv" => "PublicBodyCSV",
"world_foi_websites" => "WorldFOIWebsites"
)

Rails.autoloaders.main.ignore(
"lib/acts_as_xapian",
"lib/confidence_intervals.rb",
"lib/configuration.rb",
"lib/core_ext",
"lib/custom_cops",
"lib/generators",
"lib/has_tag_string",
"lib/i18n_fixes.rb",
"lib/languages.rb",
"lib/mail_handler/backends/mail_extensions.rb",
"lib/no_constraint_disabling.rb",
"lib/normalize_string.rb",
"lib/quiet_opener.rb",
"lib/routing_filters.rb",
"lib/stripe_mock_patch.rb",
"lib/theme.rb",
"lib/themes",
"lib/use_spans_for_errors.rb"
)
3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,7 @@ def matches?(request)
post 'redeliver', :on => :member
end
resource :incoming_messages,
:controller => 'admin_incoming_message',
:only => [:bulk_destroy] do
:controller => 'admin_incoming_message' do
post 'bulk_destroy'
end
end
Expand Down
4 changes: 4 additions & 0 deletions config/storage.yml-example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# project: ''
# bucket: ''

test:
service: Disk
root: <%= Rails.root.join('tmp/storage') %>

## Raw Emails ##

raw_emails_disk: &raw_emails_disk
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20220720085105_create_notes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
class CreateNotes < ActiveRecord::Migration[6.1]
# Predefine Note model to allow creation of translation table before adding
# style enum is added. This prevents migration errors since enums require
# existing database columns.
class Note < ApplicationRecord
translates :body
end

def change
create_table :notes do |t|
t.references :notable, polymorphic: true
Expand Down
26 changes: 5 additions & 21 deletions lib/alaveteli_localization/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,14 @@ class Railtie < Rails::Railtie

I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)

if Rails.version < '7.0.0' && Rails.env.development?
##
# Ideally the following would only be called in the `after_initialize`
# hook but this leads to an error when booting Rails 6.1 in development
# mode. (As config.cache_classes = false)
#
# This due Alaveteli not yet using the new Zeitwork autoloading feature
# and Rails attempts to render a deprecation warning which happens to
# includes an I18n translation so requires the default locale to be
# setup.
#
# Once we support Zeitwork (which is needed for Rails 7) then this can
# be removed.
#
# See: https://github.com/mysociety/alaveteli/issues/5382
#
AlaveteliLocalization.set_locales(
AlaveteliConfiguration.available_locales,
AlaveteliConfiguration.default_locale
)
end
set_locales
end

config.after_initialize do
set_locales
end

def set_locales
AlaveteliLocalization.set_locales(
AlaveteliConfiguration.available_locales,
AlaveteliConfiguration.default_locale
Expand Down
1 change: 1 addition & 0 deletions lib/alaveteli_mail_poller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'net/pop'
require 'config_helper'

class AlaveteliMailPoller
include ConfigHelper
Expand Down
1 change: 1 addition & 0 deletions lib/alaveteli_text_masker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'tempfile'
require 'config_helper'

module AlaveteliTextMasker
include ConfigHelper
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions lib/generators/acts_as_xapian/acts_as_xapian_generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'rails/generators'
require 'rails/generators/active_record/migration'

class ActsAsXapianGenerator < Rails::Generators::Base
Expand Down
6 changes: 5 additions & 1 deletion lib/no_constraint_disabling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ module ActiveRecord
class FixtureSet
def self.create_fixtures(fixtures_directory, fixture_set_names, class_names = {}, config = ActiveRecord::Base)
fixture_set_names = Array(fixture_set_names).map(&:to_s)
class_names = ClassCache.new class_names, config
if Rails.version < '7.1.0'
class_names = ClassCache.new class_names, config
else
class_names.stringify_keys!
end

# FIXME: Apparently JK uses this.
connection = block_given? ? yield : ActiveRecord::Base.connection
Expand Down
2 changes: 0 additions & 2 deletions lib/typeahead_search.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class TypeaheadSearch
include ConfigHelper

attr_accessor :query, :model, :page, :per_page, :wildcard, :run_search

def initialize(query, opts = {})
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/admin/translated_record_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

describe '#translated_fields' do
subject do
builder.translated_fields { |t| template.concat(t.text_field(:name)) }
builder.translated_fields { |t| template.concat(t.text_field(:name)) }.to_s

Check warning on line 9 in spec/helpers/admin/translated_record_form_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Line is too long. [81/80] (https://rubystyle.guide#max-line-length) Raw Output: spec/helpers/admin/translated_record_form_spec.rb:9:81: C: Layout/LineLength: Line is too long. [81/80] (https://rubystyle.guide#max-line-length)
end

let(:resource) do
Expand Down
Loading