Skip to content

Commit

Permalink
Start detecting install problems and report them on the admin dashboa…
Browse files Browse the repository at this point in the history
…rd. This commit adds check for Rails.env
  • Loading branch information
nlalonde committed Mar 20, 2013
1 parent 04c6087 commit 1e4dd3e
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 7 deletions.
Expand Up @@ -8,5 +8,9 @@
**/
Discourse.AdminDashboardController = Ember.Controller.extend({
loading: true,
versionCheck: null
versionCheck: null,

foundProblems: function() {
return(this.get('problems') && this.get('problems').length > 0);
}.property('problems')
});
Expand Up @@ -27,6 +27,7 @@ Discourse.AdminDashboardRoute = Discourse.Route.extend({
c.set(report.type, Discourse.Report.create(report));
});
c.set('totalUsers', d.total_users);
c.set('problems', d.problems);
c.set('loading', false);
});
}
Expand Down
17 changes: 17 additions & 0 deletions app/assets/javascripts/admin/templates/dashboard.js.handlebars
@@ -1,4 +1,21 @@
<div class="dashboard-left">
{{#if foundProblems}}
<div class="dashboard-stats detected-problems">
<div class="look-here"><i class="icon icon-warning-sign"></i></div>
<div class="problem-messages">
<p>
{{i18n admin.dashboard.problems_found}}
<ul>
{{#each problem in problems}}
<li>{{problem}}</li>
{{/each}}
</ul>
</p>
</div>
<div class="clearfix"></div>
</div>
{{/if}}

{{#if Discourse.SiteSettings.version_checks}}
<div {{bindAttr class=":dashboard-stats :version-check versionCheck.critical_updates:critical:normal"}}>
<table class="table table-condensed table-hover">
Expand Down
25 changes: 25 additions & 0 deletions app/assets/stylesheets/admin/admin_base.scss
Expand Up @@ -367,6 +367,31 @@ table {
}
}

&.detected-problems {
@include border-radius-all(5px);
background-color: #eee;
border: 1px solid #ccc;
margin-bottom: 20px;
margin-top: 10px;
box-shadow: inset 0 0 10px #bbb;

.look-here {
float: left;
margin: 20px 20px 0 20px;

.icon {
font-size: 32px;
vertical-align: middle;
color: $darkish_gray;
}
}

.problem-messages {
float: left;
width: 355px;
}
}

&.totals {
width: 160px;

Expand Down
7 changes: 1 addition & 6 deletions app/controllers/admin/dashboard_controller.rb
Expand Up @@ -2,12 +2,7 @@
class Admin::DashboardController < Admin::AdminController

def index
render_json_dump({
reports: ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes', 'emails'].map { |type| Report.find(type) },
total_users: User.count
}.merge(
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}
))
render_json_dump(AdminDashboardData.fetch)
end

end
22 changes: 22 additions & 0 deletions app/models/admin_dashboard_data.rb
@@ -0,0 +1,22 @@
class AdminDashboardData

REPORTS = ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes', 'emails']

def self.fetch
AdminDashboardData.new
end

def as_json
@json ||= {
reports: REPORTS.map { |type| Report.find(type) },
total_users: User.count,
problems: [rails_env_check].compact
}.merge(
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}
)
end

def rails_env_check
I18n.t("dashboard.rails_env_warning", env: Rails.env) unless Rails.env == 'production'
end
end
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Expand Up @@ -698,6 +698,7 @@ en:
update_often: 'Please update often!'
total_users: "Total Users"
moderator_short: "mod"
problems_found: "Some problems have been found with your installation of Discourse:"

reports:
today: "Today"
Expand Down
3 changes: 3 additions & 0 deletions config/locales/server.en.yml
Expand Up @@ -283,6 +283,9 @@ en:
xaxis: "Day"
yaxis: "Number of Emails"

dashboard:
rails_env_warning: "Your server is running in %{env} mode."

site_settings:
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
min_post_length: "Minimum post length in characters"
Expand Down
24 changes: 24 additions & 0 deletions spec/models/admin_dashboard_data_spec.rb
@@ -0,0 +1,24 @@
require 'spec_helper'

describe AdminDashboardData do

describe "rails_env_check" do
subject { AdminDashboardData.new.rails_env_check }

it 'returns nil when running in production mode' do
Rails.stubs(:env).returns('production')
subject.should be_nil
end

it 'returns a string when running in development mode' do
Rails.stubs(:env).returns('development')
subject.should_not be_nil
end

it 'returns a string when running in test mode' do
Rails.stubs(:env).returns('test')
subject.should_not be_nil
end
end

end

0 comments on commit 1e4dd3e

Please sign in to comment.