Merge pull request #3697 from riking/patch-6

FEATURE: Allow plugins to add admin dashboard warnings
This commit is contained in:
Robin Ward 2015-09-08 16:49:58 -04:00
commit b6343b1e10
2 changed files with 63 additions and 21 deletions

View File

@ -32,30 +32,42 @@ class AdminDashboardData
MOBILE_REPORTS ||= ['mobile_visits'] + ApplicationRequest.req_types.keys.select {|r| r =~ /mobile/}.map { |r| r + "_reqs" } MOBILE_REPORTS ||= ['mobile_visits'] + ApplicationRequest.req_types.keys.select {|r| r =~ /mobile/}.map { |r| r + "_reqs" }
def self.add_problem_check(*syms, &blk)
@problem_syms.push(*syms) if syms
@problem_blocks << blk if blk
end
class << self; attr_reader :problem_syms, :problem_blocks; end
def problems def problems
[ rails_env_check, problems = []
ruby_version_check, AdminDashboardData.problem_syms.each do |sym|
host_names_check, problems << send(sym)
gc_checks, end
sidekiq_check || queue_size_check, AdminDashboardData.problem_blocks.each do |blk|
ram_check, problems << instance_exec(&blk)
google_oauth2_config_check, end
facebook_config_check, problems.compact
twitter_config_check,
github_config_check,
s3_config_check,
image_magick_check,
failing_emails_check,
default_logo_check,
contact_email_check,
send_consumer_email_check,
title_check,
site_description_check,
site_contact_username_check,
notification_email_check
].compact
end end
# used for testing
def self.reset_problem_checks
@problem_syms = []
@problem_blocks = []
add_problem_check :rails_env_check, :ruby_version_check, :host_names_check,
:gc_checks, :ram_check, :google_oauth2_config_check,
:facebook_config_check, :twitter_config_check,
:github_config_check, :s3_config_check, :image_magick_check,
:failing_emails_check, :default_logo_check, :contact_email_check,
:send_consumer_email_check, :title_check,
:site_description_check, :site_contact_username_check,
:notification_email_check
add_problem_check do
sidekiq_check || queue_size_check
end
end
reset_problem_checks
def self.fetch_stats def self.fetch_stats
AdminDashboardData.new.as_json AdminDashboardData.new.as_json

View File

@ -2,6 +2,36 @@ require 'spec_helper'
describe AdminDashboardData do describe AdminDashboardData do
describe "adding new checks" do
after do
AdminDashboardData.reset_problem_checks
end
it 'calls the passed block' do
called = false
AdminDashboardData.add_problem_check do
called = true
end
AdminDashboardData.fetch_problems
expect(called).to eq(true)
end
it 'calls the passed method' do
$test_AdminDashboardData_global = false
class AdminDashboardData
def my_test_method
$test_AdminDashboardData_global = true
end
end
AdminDashboardData.add_problem_check :my_test_method
AdminDashboardData.fetch_problems
expect($test_AdminDashboardData_global).to eq(true)
$test_AdminDashboardData_global = nil
end
end
describe "rails_env_check" do describe "rails_env_check" do
subject { described_class.new.rails_env_check } subject { described_class.new.rails_env_check }