Dashboard checks for facebook, twitter, and github configs

This commit is contained in:
Neil Lalonde 2013-03-29 13:31:00 -04:00
parent 92eaa69df9
commit 436515ec6c
3 changed files with 83 additions and 2 deletions

View File

@ -11,7 +11,7 @@ class AdminDashboardData
def as_json
@json ||= {
reports: REPORTS.map { |type| Report.find(type) },
problems: [rails_env_check, host_names_check, gc_checks, sidekiq_check || clockwork_check, ram_check].compact,
problems: [rails_env_check, host_names_check, gc_checks, sidekiq_check || clockwork_check, ram_check, facebook_config_check, twitter_config_check, github_config_check].compact,
admins: User.admins.count,
moderators: User.moderators.count
}.merge(
@ -43,4 +43,16 @@ class AdminDashboardData
def ram_check
I18n.t('dashboard.memory_warning') if MemInfo.new.mem_total and MemInfo.new.mem_total < 1_000_000
end
def facebook_config_check
I18n.t('dashboard.facebook_config_warning') if SiteSetting.enable_facebook_logins and (!SiteSetting.facebook_app_id.present? or !SiteSetting.facebook_app_secret.present?)
end
def twitter_config_check
I18n.t('dashboard.twitter_config_warning') if SiteSetting.enable_twitter_logins and (!SiteSetting.twitter_consumer_key.present? or !SiteSetting.twitter_consumer_secret.present?)
end
def github_config_check
I18n.t('dashboard.github_config_warning') if SiteSetting.enable_github_logins and (!SiteSetting.github_client_id.present? or !SiteSetting.github_client_secret.present?)
end
end

View File

@ -298,6 +298,9 @@ en:
clockwork_warning: 'Clockwork is not running. Ensure that a clockwork process is always running so that important jobs can be scheduled. <a href="https://github.com/tomykaira/clockwork">Learn about clockwork here</a>.'
sidekiq_warning: 'Sidekiq is not running. Many tasks, like sending emails, are executed asynchronously by sidekiq. Please ensure at least one sidekiq process is running. <a href="https://github.com/mperham/sidekiq">Learn about Sidekiq here</a>.'
memory_warning: 'Your server is running with less than 1 GB of total memory. At least 1 GB of memory is recommended.'
facebook_config_warning: 'The server is configured to allow signup and log in with Facebook (enable_facebook_logins), but the app id and app secret values are not set. Go to <a href="/admin/site_settings">the Site Settings</a> and update the settings. <a href="https://github.com/discourse/discourse/wiki/The-Discourse-Admin-Quick-Start-Guide#enable-facebook-logins" target="_blank">See this guide to learn more</a>.'
twitter_config_warning: 'The server is configured to allow signup and log in with Twitter (enable_twitter_logins), but the key and secret values are not set. Go to <a href="/admin/site_settings">the Site Settings</a> and update the settings. <a href="https://github.com/discourse/discourse/wiki/The-Discourse-Admin-Quick-Start-Guide#enable-twitter-logins" target="_blank">See this guide to learn more</a>.'
github_config_warning: 'The server is configured to allow signup and log in with GitHub (enable_github_logins), but the client id and secret values are not set. Go to <a href="/admin/site_settings">the Site Settings</a> and update the settings. <a href="https://github.com/discourse/discourse/wiki/The-Discourse-Admin-Quick-Start-Guide" target="_blank">See this guide to learn more</a>.'
site_settings:
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"

View File

@ -121,4 +121,70 @@ describe AdminDashboardData do
end
end
describe 'auth_config_checks' do
shared_examples_for 'problem detection for login providers' do
context 'when disabled' do
it 'returns nil' do
SiteSetting.stubs(enable_setting).returns(false)
subject.should be_nil
end
end
context 'when enabled' do
before do
SiteSetting.stubs(enable_setting).returns(true)
end
it 'returns nil key and secret are set' do
SiteSetting.stubs(key).returns('12313213')
SiteSetting.stubs(secret).returns('12312313123')
subject.should be_nil
end
it 'returns a string when key is not set' do
SiteSetting.stubs(key).returns('')
SiteSetting.stubs(secret).returns('12312313123')
subject.should_not be_nil
end
it 'returns a string when secret is not set' do
SiteSetting.stubs(key).returns('123123')
SiteSetting.stubs(secret).returns('')
subject.should_not be_nil
end
it 'returns a string when key and secret are not set' do
SiteSetting.stubs(key).returns('')
SiteSetting.stubs(secret).returns('')
subject.should_not be_nil
end
end
end
describe 'facebook' do
subject { AdminDashboardData.new.facebook_config_check }
let(:enable_setting) { :enable_facebook_logins }
let(:key) { :facebook_app_id }
let(:secret) { :facebook_app_secret }
it_should_behave_like 'problem detection for login providers'
end
describe 'twitter' do
subject { AdminDashboardData.new.twitter_config_check }
let(:enable_setting) { :enable_twitter_logins }
let(:key) { :twitter_consumer_key }
let(:secret) { :twitter_consumer_secret }
it_should_behave_like 'problem detection for login providers'
end
describe 'github' do
subject { AdminDashboardData.new.github_config_check }
let(:enable_setting) { :enable_github_logins }
let(:key) { :github_client_id }
let(:secret) { :github_client_secret }
it_should_behave_like 'problem detection for login providers'
end
end
end