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:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user