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? return unless user.is_singular_admin?
# let's enable bootstrap mode settings # let's enable bootstrap mode settings
SiteSetting.set_and_log('default_trust_level', TrustLevel[1]) 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) 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) SiteSetting.set_and_log('bootstrap_mode_enabled', true)
end end
end end

View file

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

View file

@ -7,6 +7,8 @@ describe Jobs::DisableBootstrapMode do
before do before do
SiteSetting.bootstrap_mode_enabled = true SiteSetting.bootstrap_mode_enabled = true
SiteSetting.default_trust_level = TrustLevel[1]
SiteSetting.default_email_digest_frequency = 1440
end end
it 'does not execute if bootstrap mode is already disabled' do 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) Jobs::DisableBootstrapMode.new.execute(user_id: admin.id)
end 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 it 'successfully turns off bootstrap mode' do
SiteSetting.bootstrap_mode_min_users = 5 SiteSetting.bootstrap_mode_min_users = 5
6.times do 6.times do

View file

@ -25,6 +25,12 @@ describe Jobs::EnableBootstrapMode do
Jobs::EnableBootstrapMode.new.execute(user_id: admin.id) Jobs::EnableBootstrapMode.new.execute(user_id: admin.id)
end 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 it 'successfully turns on bootstrap mode' do
StaffActionLogger.any_instance.expects(:log_site_setting_change).times(3) StaffActionLogger.any_instance.expects(:log_site_setting_change).times(3)
Jobs::EnableBootstrapMode.new.execute(user_id: admin.id) Jobs::EnableBootstrapMode.new.execute(user_id: admin.id)