Skip to content

Commit ae58a7d

Browse files
committed
Add a warning on dashboard if enforce_global_nicknames is checked, but access key is blank.
1 parent 281f839 commit ae58a7d

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

app/assets/stylesheets/common/admin/admin_base.scss

+3
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,9 @@ table.api-keys {
564564
.actions {
565565
text-align: right;
566566
}
567+
.btn {
568+
background-color: #ccc;
569+
}
567570
}
568571
}
569572

app/models/admin_dashboard_data.rb

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def problems
4141
access_password_removal,
4242
site_contact_username_check,
4343
notification_email_check,
44+
enforce_global_nicknames_check
4445
].compact
4546
end
4647

@@ -167,6 +168,10 @@ def ruby_version_check
167168
I18n.t('dashboard.ruby_version_warning') if RUBY_VERSION == '2.0.0' and RUBY_PATCHLEVEL < 247
168169
end
169170

171+
def enforce_global_nicknames_check
172+
I18n.t('dashboard.enforce_global_nicknames_warning') if SiteSetting.enforce_global_nicknames and !SiteSetting.discourse_org_access_key.present?
173+
end
174+
170175
# TODO: generalize this method of putting i18n keys with expiry in redis
171176
# that should be reported on the admin dashboard:
172177
def access_password_removal

config/locales/server.en.yml

+1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ en:
440440
access_password_removal: "Your site was using the access_password setting, which has been removed. The login_required and must_approve_users settings have been enabled, which should be used instead. You can change them in the <a href='/admin/site_settings'>Site Settings</a>. Be sure to <a href='/admin/users/list/pending'>approve users in the Pending Users list</a>. (This message will go away after 2 days.)"
441441
site_contact_username_warning: "The site_contact_username setting is blank. Please update it in the <a href='/admin/site_settings'>Site Settings</a>. Set it to the username of an admin user who should be the sender of system messages."
442442
notification_email_warning: "The notification_email setting is blank. Please update it in the <a href='/admin/site_settings'>Site Settings</a>."
443+
enforce_global_nicknames_warning: "The enforce_global_nicknames setting is checked, but the discourse_org_access_key is blank. A Discourse.org access key is required to use the enforce_global_nicknames setting. Please update your <a href='/admin/site_settings'>Site Settings</a>."
443444

444445
content_types:
445446
education_new_reply:

spec/models/admin_dashboard_data_spec.rb

+32-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe AdminDashboardData do
44

55
describe "rails_env_check" do
6-
subject { AdminDashboardData.new.rails_env_check }
6+
subject { described_class.new.rails_env_check }
77

88
it 'returns nil when running in production mode' do
99
Rails.stubs(:env).returns('production')
@@ -22,7 +22,7 @@
2222
end
2323

2424
describe 'host_names_check' do
25-
subject { AdminDashboardData.new.host_names_check }
25+
subject { described_class.new.host_names_check }
2626

2727
it 'returns nil when host_names is set' do
2828
Discourse.stubs(:current_hostname).returns('something.com')
@@ -41,7 +41,7 @@
4141
end
4242

4343
describe 'gc_checks' do
44-
subject { AdminDashboardData.new.gc_checks }
44+
subject { described_class.new.gc_checks }
4545

4646
it 'returns nil when gc params are set' do
4747
ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(90000000)
@@ -55,7 +55,7 @@
5555
end
5656

5757
describe 'sidekiq_check' do
58-
subject { AdminDashboardData.new.sidekiq_check }
58+
subject { described_class.new.sidekiq_check }
5959

6060
it 'returns nil when sidekiq processed a job recently' do
6161
Jobs.stubs(:last_job_performed_at).returns(1.minute.ago)
@@ -89,7 +89,7 @@
8989
end
9090

9191
describe 'ram_check' do
92-
subject { AdminDashboardData.new.ram_check }
92+
subject { described_class.new.ram_check }
9393

9494
it 'returns nil when total ram is 1 GB' do
9595
MemInfo.any_instance.stubs(:mem_total).returns(1025272)
@@ -108,7 +108,7 @@
108108
end
109109

110110
describe 'send_consumer_email_check' do
111-
subject { AdminDashboardData.new.send_consumer_email_check }
111+
subject { described_class.new.send_consumer_email_check }
112112

113113
it 'returns nil if gmail.com is not in the smtp_settings address' do
114114
ActionMailer::Base.stubs(:smtp_settings).returns({address: 'mandrillapp.com'})
@@ -131,7 +131,7 @@
131131
end
132132

133133
describe 'default_logo_check' do
134-
subject { AdminDashboardData.new.default_logo_check }
134+
subject { described_class.new.default_logo_check }
135135

136136
describe 'favicon_url check' do
137137
before do
@@ -220,28 +220,50 @@
220220
end
221221

222222
describe 'facebook' do
223-
subject { AdminDashboardData.new.facebook_config_check }
223+
subject { described_class.new.facebook_config_check }
224224
let(:enable_setting) { :enable_facebook_logins }
225225
let(:key) { :facebook_app_id }
226226
let(:secret) { :facebook_app_secret }
227227
include_examples 'problem detection for login providers'
228228
end
229229

230230
describe 'twitter' do
231-
subject { AdminDashboardData.new.twitter_config_check }
231+
subject { described_class.new.twitter_config_check }
232232
let(:enable_setting) { :enable_twitter_logins }
233233
let(:key) { :twitter_consumer_key }
234234
let(:secret) { :twitter_consumer_secret }
235235
include_examples 'problem detection for login providers'
236236
end
237237

238238
describe 'github' do
239-
subject { AdminDashboardData.new.github_config_check }
239+
subject { described_class.new.github_config_check }
240240
let(:enable_setting) { :enable_github_logins }
241241
let(:key) { :github_client_id }
242242
let(:secret) { :github_client_secret }
243243
include_examples 'problem detection for login providers'
244244
end
245245
end
246246

247+
describe "enforce_global_nicknames_check" do
248+
subject { described_class.new.enforce_global_nicknames_check }
249+
250+
it 'returns nil when enforce_global_nicknames and discourse_org_access_key are set' do
251+
SiteSetting.stubs(:enforce_global_nicknames).returns(true)
252+
SiteSetting.stubs(:discourse_org_access_key).returns('123')
253+
subject.should be_nil
254+
end
255+
256+
it 'returns a string when enforce_global_nicknames is true but discourse_org_access_key is not' do
257+
SiteSetting.stubs(:enforce_global_nicknames).returns(true)
258+
SiteSetting.stubs(:discourse_org_access_key).returns('')
259+
subject.should_not be_nil
260+
end
261+
262+
it 'returns nil when enforce_global_nicknames is false and discourse_org_access_key is set' do
263+
SiteSetting.stubs(:enforce_global_nicknames).returns(false)
264+
SiteSetting.stubs(:discourse_org_access_key).returns('123')
265+
subject.should be_nil
266+
end
267+
end
268+
247269
end

0 commit comments

Comments
 (0)