diff --git a/app/jobs/regular/enable_bootstrap_mode.rb b/app/jobs/regular/enable_bootstrap_mode.rb index fcbd5b2921f..32431ea2afb 100644 --- a/app/jobs/regular/enable_bootstrap_mode.rb +++ b/app/jobs/regular/enable_bootstrap_mode.rb @@ -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 diff --git a/app/jobs/scheduled/disable_bootstrap_mode.rb b/app/jobs/scheduled/disable_bootstrap_mode.rb index ae1707c37f2..16028bac875 100644 --- a/app/jobs/scheduled/disable_bootstrap_mode.rb +++ b/app/jobs/scheduled/disable_bootstrap_mode.rb @@ -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 diff --git a/spec/jobs/disable_bootstrap_mode_spec.rb b/spec/jobs/disable_bootstrap_mode_spec.rb index 96f11ceac3f..b8be00bf4d2 100644 --- a/spec/jobs/disable_bootstrap_mode_spec.rb +++ b/spec/jobs/disable_bootstrap_mode_spec.rb @@ -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 diff --git a/spec/jobs/enable_bootstrap_mode_spec.rb b/spec/jobs/enable_bootstrap_mode_spec.rb index c0441bc5fc4..8cf653b46fd 100644 --- a/spec/jobs/enable_bootstrap_mode_spec.rb +++ b/spec/jobs/enable_bootstrap_mode_spec.rb @@ -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)