diff --git a/app/models/setting.rb b/app/models/setting.rb index 36df94788..70f31da20 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -159,14 +159,13 @@ class Setting < ApplicationRecord "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, @@ -199,6 +198,14 @@ class Setting < ApplicationRecord } end + def default_org_name + Tenant.current&.name || default_main_org_name + end + + def default_main_org_name + "CONSUL" + end + def default_mailer_from_address "noreply@#{Tenant.current_host.presence || "consul.dev"}" end diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 45d9e2373..d01f610ba 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -91,6 +91,10 @@ class Tenant < ApplicationRecord Apartment::Tenant.current end + def self.current + find_by(schema: current_schema) + end + def self.switch(...) Apartment::Tenant.switch(...) end diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index 81b61b83b..709b70a65 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -6,12 +6,10 @@ section "Creating Settings" do "feature.featured_proposals": "true", "feature.map": "true", "instagram_handle": "CONSUL", - "mailer_from_name": "CONSUL", "meta_description": "Citizen participation tool for an open, "\ "transparent and democratic government", "meta_keywords": "citizen participation, open government", "meta_title": "CONSUL", - "org_name": "CONSUL", "proposal_code_prefix": "MAD", "proposal_notification_minimum_interval_in_days": 0, "telegram_handle": "CONSUL", diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 0fa294635..13b168d14 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -187,6 +187,20 @@ describe Setting do end end + describe ".default_org_name" do + it "returns the main org name 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") + + Tenant.switch("new") do + expect(Setting.default_org_name).to eq "New Institution" + end + end + end + describe ".default_mailer_from_address" do before { allow(Tenant).to receive(:default_host).and_return("consulproject.org") }