From dc961fecb9c28be5e8f161a82616148be6a9facc Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Mon, 25 Feb 2019 16:06:33 +0100 Subject: [PATCH] FIX: Outgoing emails were not disabled after restoring backup --- app/controllers/admin/backups_controller.rb | 1 - lib/backup_restore/restorer.rb | 4 ++++ spec/requests/admin/backups_controller_spec.rb | 2 -- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/backups_controller.rb b/app/controllers/admin/backups_controller.rb index 9071b068e66..3fe1141ed87 100644 --- a/app/controllers/admin/backups_controller.rb +++ b/app/controllers/admin/backups_controller.rb @@ -114,7 +114,6 @@ class Admin::BackupsController < Admin::AdminController client_id: params.fetch(:client_id), publish_to_message_bus: true, } - SiteSetting.set_and_log(:disable_emails, 'yes', current_user) BackupRestore.restore!(current_user.id, opts) rescue BackupRestore::OperationRunningError render_error("backup.operation_already_running") diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb index 5dcc3770d93..5d39e5efa99 100644 --- a/lib/backup_restore/restorer.rb +++ b/lib/backup_restore/restorer.rb @@ -401,6 +401,10 @@ module BackupRestore def reload_site_settings log "Reloading site settings..." SiteSetting.refresh! + + log "Disabling outgoing emails for non-stuff users..." + user = User.find_by_email(@user_info[:email]) || Discourse.system_user + SiteSetting.set_and_log(:disable_emails, 'non-staff', user) end def clear_emoji_cache diff --git a/spec/requests/admin/backups_controller_spec.rb b/spec/requests/admin/backups_controller_spec.rb index 6a6b60ce9da..96a7b63c490 100644 --- a/spec/requests/admin/backups_controller_spec.rb +++ b/spec/requests/admin/backups_controller_spec.rb @@ -162,12 +162,10 @@ RSpec.describe Admin::BackupsController do describe '#restore' do it "starts a restore" do - expect(SiteSetting.disable_emails).to eq("no") BackupRestore.expects(:restore!).with(admin.id, filename: backup_filename, publish_to_message_bus: true, client_id: "foo") post "/admin/backups/#{backup_filename}/restore.json", params: { client_id: "foo" } - expect(SiteSetting.disable_emails).to eq("yes") expect(response.status).to eq(200) end end