From c8508d3f26620cd9aaf8f3e8180970b764d612d4 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 20 Mar 2013 15:38:28 -0400 Subject: [PATCH] Dashboard warning when host_names is localhost --- app/models/admin_dashboard_data.rb | 6 +++++- config/locales/server.en.yml | 1 + spec/models/admin_dashboard_data_spec.rb | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index f08aed0fdd7..8dac0e9534f 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -10,7 +10,7 @@ class AdminDashboardData @json ||= { reports: REPORTS.map { |type| Report.find(type) }, total_users: User.count, - problems: [rails_env_check].compact + problems: [rails_env_check, host_names_check].compact }.merge( SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {} ) @@ -19,4 +19,8 @@ class AdminDashboardData def rails_env_check I18n.t("dashboard.rails_env_warning", env: Rails.env) unless Rails.env == 'production' end + + def host_names_check + I18n.t("dashboard.host_names_warning") if ['localhost', 'production.localhost'].include?(Discourse.current_hostname) + end end \ No newline at end of file diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 0c76bc7a70e..c0f91f7269c 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -285,6 +285,7 @@ en: dashboard: rails_env_warning: "Your server is running in %{env} mode." + host_names_warning: "Your config/database.yml file is using the default localhost hostname. Update it to use your site's hostname." site_settings: default_locale: "The default language of this Discourse instance (ISO 639-1 Code)" diff --git a/spec/models/admin_dashboard_data_spec.rb b/spec/models/admin_dashboard_data_spec.rb index eb368a6df48..b5c604abe04 100644 --- a/spec/models/admin_dashboard_data_spec.rb +++ b/spec/models/admin_dashboard_data_spec.rb @@ -21,4 +21,23 @@ describe AdminDashboardData do end end + describe 'host_names_check' do + subject { AdminDashboardData.new.host_names_check } + + it 'returns nil when host_names is set' do + Discourse.stubs(:current_hostname).returns('something.com') + subject.should be_nil + end + + it 'returns a string when host_name is localhost' do + Discourse.stubs(:current_hostname).returns('localhost') + subject.should_not be_nil + end + + it 'returns a string when host_name is production.localhost' do + Discourse.stubs(:current_hostname).returns('production.localhost') + subject.should_not be_nil + end + end + end \ No newline at end of file