A platform for community discussion. Free, open, simple.
FEATURE: Display force_https warning in admin problems dashboard
Vinoth Kannanb96ae142619d
diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rbindex ed021d9158d..51be59fcde2 100644--- a/app/controllers/admin/dashboard_controller.rb+++ b/app/controllers/admin/dashboard_controller.rb@@ -9,6 +9,6 @@ class Admin::DashboardController < Admin::AdminControllerenddef problems- render_json_dump(problems: AdminDashboardData.fetch_problems)+ render_json_dump(problems: AdminDashboardData.fetch_problems(check_force_https: request.ssl?))endenddiff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rbindex 57a4394c27d..8ba294d4249 100644--- a/app/models/admin_dashboard_data.rb+++ b/app/models/admin_dashboard_data.rb@@ -39,6 +39,10 @@ class AdminDashboardDataendclass << self; attr_reader :problem_syms, :problem_blocks, :problem_messages; end+ def initialize(opts = {})+ @opts = opts+ end+def problemsproblems = []AdminDashboardData.problem_syms.each do |sym|@@ -90,7 +94,7 @@ class AdminDashboardData'dashboard.poll_pop3_auth_error']- add_problem_check :rails_env_check, :host_names_check,+ add_problem_check :rails_env_check, :host_names_check, :force_https_check,:ram_check, :google_oauth2_config_check,:facebook_config_check, :twitter_config_check,:github_config_check, :s3_config_check, :image_magick_check,@@ -112,8 +116,8 @@ class AdminDashboardData'dash-stats'end- def self.fetch_problems- AdminDashboardData.new.problems+ def self.fetch_problems(opts = {})+ AdminDashboardData.new(opts).problemsenddef self.problem_message_check(i18n_key)@@ -234,4 +238,9 @@ class AdminDashboardDataI18n.t('dashboard.missing_mailgun_api_key')end+ def force_https_check+ return unless @opts[:check_force_https]+ I18n.t('dashboard.force_https_warning') unless SiteSetting.force_https+ end+enddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 714d5d8268e..96b7e87209f 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -956,6 +956,7 @@ en:bad_favicon_url: "The favicon is failing to load. Check your favicon_url setting in <a href='/admin/site_settings'>Site Settings</a>."poll_pop3_timeout: "Connection to the POP3 server is timing out. Incoming email could not be retrieved. Please check your <a href='/admin/site_settings/category/email'>POP3 settings</a> and service provider."poll_pop3_auth_error: "Connection to the POP3 server is failing with an authentication error. Please check your <a href='/admin/site_settings/category/email'>POP3 settings</a>."+ force_https_warning: "Your website using SSL. But `<a href='/admin/site_settings/category/all_results?filter=force_https'>force_https</a>` is not yet enabled in your site settings."site_settings:censored_words: "Words that will be automatically replaced with ■■■■"diff --git a/spec/models/admin_dashboard_data_spec.rb b/spec/models/admin_dashboard_data_spec.rbindex d04142bef5f..f65de862fd1 100644--- a/spec/models/admin_dashboard_data_spec.rb+++ b/spec/models/admin_dashboard_data_spec.rb@@ -15,6 +15,9 @@ describe AdminDashboardData doAdminDashboardData.fetch_problemsexpect(called).to eq(true)++ AdminDashboardData.fetch_problems(check_force_https: true)+ expect(called).to eq(true)endit 'calls the passed method' do@@ -281,6 +284,32 @@ describe AdminDashboardData doendend+ describe 'force_https_check' do+ subject { described_class.new(check_force_https: true).force_https_check }++ it 'returns nil if force_https site setting enabled' do+ SiteSetting.force_https = true+ expect(subject).to be_nil+ end++ it 'returns nil if force_https site setting not enabled' do+ SiteSetting.force_https = false+ expect(subject).to eq(I18n.t('dashboard.force_https_warning'))+ end+ end++ describe 'ignore force_https_check' do+ subject { described_class.new(check_force_https: false).force_https_check }++ it 'returns nil' do+ SiteSetting.force_https = true+ expect(subject).to be_nil++ SiteSetting.force_https = false+ expect(subject).to be_nil+ end+ end+describe 'stats cache' doinclude_examples 'stats cachable'end