FIX: bootstrap mode should not amend setting that is not in default state

This commit is contained in:
Arpit Jalan 2016-05-04 16:35:54 +05:30
parent 5576c8efca
commit 9427e0c732
4 changed files with 19 additions and 4 deletions

View File

@ -10,8 +10,8 @@ module Jobs
return unless user.is_singular_admin?
# let's enable bootstrap mode settings
SiteSetting.set_and_log('default_trust_level', TrustLevel[1])
SiteSetting.set_and_log('default_email_digest_frequency', 1440)
SiteSetting.set_and_log('default_trust_level', TrustLevel[1]) if SiteSetting.send('default_trust_level') == TrustLevel[0]
SiteSetting.set_and_log('default_email_digest_frequency', 1440) if SiteSetting.send('default_email_digest_frequency') == 10080
SiteSetting.set_and_log('bootstrap_mode_enabled', true)
end
end

View File

@ -7,8 +7,8 @@ module Jobs
total_users = User.where.not(id: Discourse::SYSTEM_USER_ID).count
if SiteSetting.bootstrap_mode_min_users == 0 || total_users > SiteSetting.bootstrap_mode_min_users
SiteSetting.set_and_log('default_trust_level', TrustLevel[0])
SiteSetting.set_and_log('default_email_digest_frequency', 10080)
SiteSetting.set_and_log('default_trust_level', TrustLevel[0]) if SiteSetting.send('default_trust_level') == TrustLevel[1]
SiteSetting.set_and_log('default_email_digest_frequency', 10080) if SiteSetting.send('default_email_digest_frequency') == 1440
SiteSetting.set_and_log('bootstrap_mode_enabled', false)
end
end

View File

@ -7,6 +7,8 @@ describe Jobs::DisableBootstrapMode do
before do
SiteSetting.bootstrap_mode_enabled = true
SiteSetting.default_trust_level = TrustLevel[1]
SiteSetting.default_email_digest_frequency = 1440
end
it 'does not execute if bootstrap mode is already disabled' do
@ -21,6 +23,13 @@ describe Jobs::DisableBootstrapMode do
Jobs::DisableBootstrapMode.new.execute(user_id: admin.id)
end
it 'does not amend setting that is not in bootstrap state' do
SiteSetting.bootstrap_mode_min_users = 0
SiteSetting.default_trust_level = TrustLevel[3]
StaffActionLogger.any_instance.expects(:log_site_setting_change).twice
Jobs::DisableBootstrapMode.new.execute(user_id: admin.id)
end
it 'successfully turns off bootstrap mode' do
SiteSetting.bootstrap_mode_min_users = 5
6.times do

View File

@ -25,6 +25,12 @@ describe Jobs::EnableBootstrapMode do
Jobs::EnableBootstrapMode.new.execute(user_id: admin.id)
end
it 'does not amend setting that is not in default state' do
SiteSetting.default_trust_level = TrustLevel[3]
StaffActionLogger.any_instance.expects(:log_site_setting_change).twice
Jobs::EnableBootstrapMode.new.execute(user_id: admin.id)
end
it 'successfully turns on bootstrap mode' do
StaffActionLogger.any_instance.expects(:log_site_setting_change).times(3)
Jobs::EnableBootstrapMode.new.execute(user_id: admin.id)