Skip to content

Commit

Permalink
Use the tenant name as default organization name
Browse files Browse the repository at this point in the history
This way we'll avoid having all tenant organizations named "CONSUL" by
default, and we'll also use different email senders per tenant, which
will reduce the change of the emails being marked as spam.
  • Loading branch information
javierm committed Nov 25, 2022
1 parent 22e9f69 commit 5bdfeeb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,13 @@ def defaults
"twitter_handle": nil,
"twitter_hashtag": nil,
"youtube_handle": nil,
# CONSUL installation's organization name
"org_name": "CONSUL",
"org_name": default_org_name,
"meta_title": nil,
"meta_description": nil,
"meta_keywords": nil,
"proposal_notification_minimum_interval_in_days": 3,
"direct_message_max_per_day": 3,
"mailer_from_name": "CONSUL",
"mailer_from_name": default_org_name,
"mailer_from_address": default_mailer_from_address,
"min_age_to_participate": 16,
"hot_score_period_in_days": 31,
Expand Down Expand Up @@ -199,6 +198,10 @@ def defaults
}
end

def default_org_name
Tenant.current&.name || "CONSUL"
end

def default_mailer_from_address
"noreply@#{Tenant.current_host.presence || "consul.dev"}"
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def self.current_schema
Apartment::Tenant.current
end

def self.current
find_by(schema: current_schema)
end

def self.switch(...)
Apartment::Tenant.switch(...)
end
Expand Down
13 changes: 13 additions & 0 deletions spec/models/setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@
end
end

describe ".default_org_name" do
it "returns CONSUL for the default tenant" do
expect(Setting.default_org_name).to eq "CONSUL"
end

it "returns the tenant name for other tenants" do
create(:tenant, schema: "new", name: "New Institution")
allow(Tenant).to receive(:current_schema).and_return("new")

expect(Setting.default_org_name).to eq "New Institution"
end
end

describe ".default_mailer_from_address" do
before { allow(Tenant).to receive(:default_host).and_return("consulproject.org") }

Expand Down

0 comments on commit 5bdfeeb

Please sign in to comment.