From 63d52db91be607d31e7ec43f0a3ea3eb04ec21ec Mon Sep 17 00:00:00 2001 From: wvengen Date: Tue, 2 Sep 2014 12:18:50 +0200 Subject: [PATCH] more sensible mailer option defaults Conflicts: app/mailers/base_mailer.rb config/app_config.yml.SAMPLE spec/app_config.yml --- app/mailers/mailer.rb | 6 ++++-- config/app_config.yml.SAMPLE | 11 +++++------ config/environments/development.rb.SAMPLE | 4 ++-- config/environments/production.rb | 3 +++ config/environments/test.rb | 3 +++ spec/app_config.yml | 1 - 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index bbe78d43..8f7b7c23 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -87,9 +87,11 @@ class Mailer < ActionMailer::Base private + # @todo this global stuff gives threading problems when foodcoops have different values! - pass args to `url_for` instead def set_foodcoop_scope(foodcoop = FoodsoftConfig.scope) - ActionMailer::Base.default_url_options[:protocol] = FoodsoftConfig[:protocol] - ActionMailer::Base.default_url_options[:host] = FoodsoftConfig[:host] + [:protocol, :host, :port].each do |k| + ActionMailer::Base.default_url_options[k] = FoodsoftConfig[k] if FoodsoftConfig[k] + end ActionMailer::Base.default_url_options[:foodcoop] = foodcoop end diff --git a/config/app_config.yml.SAMPLE b/config/app_config.yml.SAMPLE index d63bce33..fd4af4d4 100644 --- a/config/app_config.yml.SAMPLE +++ b/config/app_config.yml.SAMPLE @@ -8,12 +8,6 @@ default: &defaults # If multi_coop_install you have to use a coop name, which you you wanna be selected by default default_scope: 'f' - # http config for this host - # Required for action mailer - protocol: http - host: localhost - port: 3000 - # name of this foodcoop name: FC Test # foodcoop contact information (used for FAX messages) @@ -106,6 +100,11 @@ default: &defaults sender_address: "\"Foodsoft Error\" " email_prefix: "[Foodsoft]" + # http config for this host to generate links in emails (uses environment config when not set) + #protocol: http + #host: localhost + #port: 3000 + # Access to sharedLists, the external article-database shared_lists: adapter: mysql2 diff --git a/config/environments/development.rb.SAMPLE b/config/environments/development.rb.SAMPLE index 8f888ea5..0b84aec8 100644 --- a/config/environments/development.rb.SAMPLE +++ b/config/environments/development.rb.SAMPLE @@ -33,8 +33,8 @@ Foodsoft::Application.configure do # Required for i18n-js config.assets.initialize_on_precompile = true - # Configure hostname for action mailer - config.action_mailer.default_url_options = { host: 'localhost:3000' } + # Configure hostname for action mailer (can be overridden in foodcoop config) + config.action_mailer.default_url_options = { host: 'localhost', port: 3000, protocol: 'http' } # Mailcatcher config, start mailcatcher from console with 'mailcatcher' # Mailcatcher can be installed by gem install mailcatcher diff --git a/config/environments/production.rb b/config/environments/production.rb index a476f86c..80a77879 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -75,6 +75,9 @@ Foodsoft::Application.configure do # Disable automatic flushing of the log to improve performance. # config.autoflush_log = false + # Configure hostname for action mailer (can be overridden in foodcoop config) + config.action_mailer.default_url_options = { host: `hostname -f`, protocol: 'https' } + # Use sendmail to avoid ssl cert problems config.action_mailer.delivery_method = :sendmail diff --git a/config/environments/test.rb b/config/environments/test.rb index 63e0fb27..f389ad59 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -29,6 +29,9 @@ Foodsoft::Application.configure do # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false + # Configure hostname for action mailer (can be overridden in foodcoop config) + config.action_mailer.default_url_options = { host: 'localhost', port: 3000, protocol: 'http' } + # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. diff --git a/spec/app_config.yml b/spec/app_config.yml index 1a3fc7cf..f9d0ed81 100644 --- a/spec/app_config.yml +++ b/spec/app_config.yml @@ -8,7 +8,6 @@ default: &defaults multi_coop_install: false default_scope: 'f' - host: localhost name: FC Minimal contact: