Skip to content

Commit

Permalink
Overriding Rails config defaults for compatibility (#7016)
Browse files Browse the repository at this point in the history
* Set modified defaults during hyrax app generation

* Move Rails configuration default overrides into a Hyrax managed initializer

* Overriding action_view defaults resulting in test failures

* Overriding action_controller defaults to allow open redirects

* Overriding action_view sanitizer default back to HTML4, extra char encoding breaks test comparisons

* Adding allow_other_host option to intentional open redirects instead of overriding raise_on_open_redirects config default

---------

Co-authored-by: Daniel Pierce <[email protected]>
  • Loading branch information
randalldfloyd and dlpierce authored Feb 19, 2025
1 parent 02af9cf commit e88c89e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .dassie/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
module Dassie
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.0
config.load_defaults 7.2
config.add_autoload_paths_to_load_path = true

# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
Expand Down
3 changes: 2 additions & 1 deletion .koppie/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
module Koppie
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.0
config.load_defaults 7.2
config.add_autoload_paths_to_load_path = true

# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/hyrax/api/zotero_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initiate
session[:request_token] = request_token
current_user.zotero_token = request_token
current_user.save
redirect_to request_token.authorize_url(identity: '1', oauth_callback: callback_url)
redirect_to request_token.authorize_url(identity: '1', oauth_callback: callback_url), allow_other_host: true
rescue OAuth::Unauthorized
redirect_to root_url, alert: 'Invalid Zotero client key pair'
end
Expand Down
8 changes: 8 additions & 0 deletions config/initializers/new_framework_defaults_7_2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Any options set here are to override Rails 7.2 configuration defaults

# These fix a couple of issues arising from Rails 7.2 enforcement of HTML5 semantics
# by default when using certain Rails methods
Rails.application.config.action_view.button_to_generates_button_tag = false
Rails.application.config.action_view.sanitizer_vendor = Rails::HTML4::Sanitizer
2 changes: 1 addition & 1 deletion lib/generators/hyrax/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def riiif_image_server
generate 'hyrax:riiif' unless options[:'skip-riiif']
end

def insert_env_queue_adapter
def insert_application_config
insert_into_file 'config/application.rb', after: /config\.load_defaults [0-9.]+$/ do
"\n config.active_job.queue_adapter = ENV.fetch('HYRAX_ACTIVE_JOB_QUEUE') { 'async' }.to_sym\n"
end
Expand Down
5 changes: 5 additions & 0 deletions template.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# frozen_string_literal: true

insert_into_file 'config/application.rb', after: /config\.load_defaults [0-9.]+$/ do
"\n config.add_autoload_paths_to_load_path = true"
end

gem 'hyrax', '5.0.3'
run 'bundle install'
generate 'hyrax:install', '-f'

0 comments on commit e88c89e

Please sign in to comment.