diff --git a/app/models/setting.rb b/app/models/setting.rb index 58cb8bb06..36df94788 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -167,7 +167,7 @@ class Setting < ApplicationRecord "proposal_notification_minimum_interval_in_days": 3, "direct_message_max_per_day": 3, "mailer_from_name": "CONSUL", - "mailer_from_address": "noreply@consul.dev", + "mailer_from_address": default_mailer_from_address, "min_age_to_participate": 16, "hot_score_period_in_days": 31, "related_content_score_threshold": -0.3, @@ -199,6 +199,10 @@ class Setting < ApplicationRecord } end + def default_mailer_from_address + "noreply@#{Tenant.current_host.presence || "consul.dev"}" + end + def reset_defaults defaults.each { |name, value| self[name] = value } end diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index 280e56c63..81b61b83b 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -6,7 +6,6 @@ section "Creating Settings" do "feature.featured_proposals": "true", "feature.map": "true", "instagram_handle": "CONSUL", - "mailer_from_address": "noreply@consul.dev", "mailer_from_name": "CONSUL", "meta_description": "Citizen participation tool for an open, "\ "transparent and democratic government", diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 8a5dc95b2..0fa294635 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -187,6 +187,28 @@ describe Setting do end end + describe ".default_mailer_from_address" do + before { allow(Tenant).to receive(:default_host).and_return("consulproject.org") } + + it "uses the default host for the default tenant" do + expect(Setting.default_mailer_from_address).to eq "noreply@consulproject.org" + end + + it "uses the tenant host for other tenants" do + allow(Tenant).to receive(:current_schema).and_return("new") + + expect(Setting.default_mailer_from_address).to eq "noreply@new.consulproject.org" + end + + context "empty default host" do + before { allow(Tenant).to receive(:default_host).and_return("") } + + it "uses consul.dev as host" do + expect(Setting.default_mailer_from_address).to eq "noreply@consul.dev" + end + end + end + describe ".add_new_settings" do context "default settings with strings" do before do