mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 16:16:40 +08:00
Start detecting install problems and report them on the admin dashboard. This commit adds check for Rails.env
This commit is contained in:
parent
04c6087ef0
commit
1e4dd3ea0c
@ -8,5 +8,9 @@
|
|||||||
**/
|
**/
|
||||||
Discourse.AdminDashboardController = Ember.Controller.extend({
|
Discourse.AdminDashboardController = Ember.Controller.extend({
|
||||||
loading: true,
|
loading: true,
|
||||||
versionCheck: null
|
versionCheck: null,
|
||||||
|
|
||||||
|
foundProblems: function() {
|
||||||
|
return(this.get('problems') && this.get('problems').length > 0);
|
||||||
|
}.property('problems')
|
||||||
});
|
});
|
||||||
|
@ -27,6 +27,7 @@ Discourse.AdminDashboardRoute = Discourse.Route.extend({
|
|||||||
c.set(report.type, Discourse.Report.create(report));
|
c.set(report.type, Discourse.Report.create(report));
|
||||||
});
|
});
|
||||||
c.set('totalUsers', d.total_users);
|
c.set('totalUsers', d.total_users);
|
||||||
|
c.set('problems', d.problems);
|
||||||
c.set('loading', false);
|
c.set('loading', false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,21 @@
|
|||||||
<div class="dashboard-left">
|
<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}}
|
{{#if Discourse.SiteSettings.version_checks}}
|
||||||
<div {{bindAttr class=":dashboard-stats :version-check versionCheck.critical_updates:critical:normal"}}>
|
<div {{bindAttr class=":dashboard-stats :version-check versionCheck.critical_updates:critical:normal"}}>
|
||||||
<table class="table table-condensed table-hover">
|
<table class="table table-condensed table-hover">
|
||||||
|
@ -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 {
|
&.totals {
|
||||||
width: 160px;
|
width: 160px;
|
||||||
|
|
||||||
|
@ -2,12 +2,7 @@
|
|||||||
class Admin::DashboardController < Admin::AdminController
|
class Admin::DashboardController < Admin::AdminController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
render_json_dump({
|
render_json_dump(AdminDashboardData.fetch)
|
||||||
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} : {}
|
|
||||||
))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
22
app/models/admin_dashboard_data.rb
Normal file
22
app/models/admin_dashboard_data.rb
Normal file
@ -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
|
@ -698,6 +698,7 @@ en:
|
|||||||
update_often: 'Please update often!'
|
update_often: 'Please update often!'
|
||||||
total_users: "Total Users"
|
total_users: "Total Users"
|
||||||
moderator_short: "mod"
|
moderator_short: "mod"
|
||||||
|
problems_found: "Some problems have been found with your installation of Discourse:"
|
||||||
|
|
||||||
reports:
|
reports:
|
||||||
today: "Today"
|
today: "Today"
|
||||||
|
@ -283,6 +283,9 @@ en:
|
|||||||
xaxis: "Day"
|
xaxis: "Day"
|
||||||
yaxis: "Number of Emails"
|
yaxis: "Number of Emails"
|
||||||
|
|
||||||
|
dashboard:
|
||||||
|
rails_env_warning: "Your server is running in %{env} mode."
|
||||||
|
|
||||||
site_settings:
|
site_settings:
|
||||||
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
|
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
|
||||||
min_post_length: "Minimum post length in characters"
|
min_post_length: "Minimum post length in characters"
|
||||||
|
24
spec/models/admin_dashboard_data_spec.rb
Normal file
24
spec/models/admin_dashboard_data_spec.rb
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user