Use current host as default email address domain

We were using `consul.dev` as default, which might be fine for the
development environment, but it's something that definitely needs to be
changed on production.

Now we're providing a better default setting: using the same domain
which is used to generate URLs in emails. This also makes it easier to
configure new tenants, since the setting will default to whatever host
the new tenant is using.

The `|| "consul.dev"` part might not be needed; I'm keeping it because
I'm not sure production environents would not experience any new issues
if we don't add it, but we might remove it in the future.
This commit is contained in:
Javi Martín
2022-11-10 00:19:02 +01:00
parent a400e4bd0c
commit 03614325d1
3 changed files with 27 additions and 2 deletions

View File

@@ -167,7 +167,7 @@ class Setting < ApplicationRecord
"proposal_notification_minimum_interval_in_days": 3, "proposal_notification_minimum_interval_in_days": 3,
"direct_message_max_per_day": 3, "direct_message_max_per_day": 3,
"mailer_from_name": "CONSUL", "mailer_from_name": "CONSUL",
"mailer_from_address": "noreply@consul.dev", "mailer_from_address": default_mailer_from_address,
"min_age_to_participate": 16, "min_age_to_participate": 16,
"hot_score_period_in_days": 31, "hot_score_period_in_days": 31,
"related_content_score_threshold": -0.3, "related_content_score_threshold": -0.3,
@@ -199,6 +199,10 @@ class Setting < ApplicationRecord
} }
end end
def default_mailer_from_address
"noreply@#{Tenant.current_host.presence || "consul.dev"}"
end
def reset_defaults def reset_defaults
defaults.each { |name, value| self[name] = value } defaults.each { |name, value| self[name] = value }
end end

View File

@@ -6,7 +6,6 @@ section "Creating Settings" do
"feature.featured_proposals": "true", "feature.featured_proposals": "true",
"feature.map": "true", "feature.map": "true",
"instagram_handle": "CONSUL", "instagram_handle": "CONSUL",
"mailer_from_address": "noreply@consul.dev",
"mailer_from_name": "CONSUL", "mailer_from_name": "CONSUL",
"meta_description": "Citizen participation tool for an open, "\ "meta_description": "Citizen participation tool for an open, "\
"transparent and democratic government", "transparent and democratic government",

View File

@@ -187,6 +187,28 @@ describe Setting do
end end
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 describe ".add_new_settings" do
context "default settings with strings" do context "default settings with strings" do
before do before do